/* 2010-07 johnpfeiffer
example of converting a win ce program to win32
simply show how many clicks have been made
*/
/* begin */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* end */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* #include "drawText.txt" */
#define IDC_ExitButton 40099
int clickCount = 0;
int pointHistory[128][2];
VOID drawText( HWND hwnd, char ansistring[ 128 ] , int x , int y )
{
HDC hdc;
wchar_t widestring[ 128 ] ;
wchar_t buffer[ 128 ] ;
int i =0;
memset( widestring , 0, sizeof( widestring ));
memset( buffer , 0, sizeof( buffer ));
i = mbstowcs( widestring , ansistring , strlen( ansistring ) );
wsprintf( buffer , "%d" , i);
hdc = GetDC( hwnd );
ExtTextOut( hdc , x , y-20 , (UINT)NULL , NULL ,
(LPCTSTR)buffer , wcslen( buffer ), NULL);
ExtTextOutW( hdc , x , y , (UINT)NULL , NULL ,
widestring , wcslen( widestring ), NULL);
ExtTextOut( hdc , x , y+20 , (UINT)NULL , NULL ,
widestring , 4 , NULL);
ReleaseDC(hwnd, hdc);
}/* end function drawText */
/*
THE PROBLEM IS THAT LPCSTR ISN'T WCHAR!
LPSTR = char*
LPCSTR = const char*
LPWSTR = wchar_t*
BOOL ExtTextOut(
HDC hdc,
int X,
int Y,
UINT fuOptions,
const RECT* lprc,
LPCTSTR lpString,
UINT cbCount,
const int* lpDx
);
int __cdecl wsprintf(
__out LPTSTR lpOut,
__in LPCTSTR lpFmt,
__in ...
);
answer is to use ExtTextOutW...
*/
LRESULT CALLBACK MenuWndProc( HWND hwnd,
UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
char buffer[64];
switch (message)
{
case WM_LBUTTONDOWN:
pointHistory[ clickCount ][0] = LOWORD( lParam );
pointHistory[ clickCount ][1] = HIWORD( lParam );
memset( buffer , 0, sizeof( buffer ));
sprintf( buffer , "%d", clickCount );
drawText( hwnd , buffer , LOWORD( lParam ) , HIWORD( lParam ) );
clickCount++;
break;
case WM_CHAR:
break;
case WM_KEYDOWN:
break;
case WM_MOUSEMOVE:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_ExitButton:
PostQuitMessage(0);
break;
default:
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
break;
case WM_CREATE:
UpdateWindow( hwnd );
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
} /* end MenuWndProc function */
int APIENTRY WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int ncmdshow )
{
HWND hwnd = NULL;
HWND ExitButton= NULL;
MSG msg;
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)MenuWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "WindowApp";
if(! RegisterClass (&wc))
{
MessageBox(NULL, TEXT("errors ") , "IMPORTANT", MB_OK);
return 0;
}
hwnd = CreateWindow ("WindowApp", "display mouse xy",
WS_VISIBLE, 0 , 30 , 300 , 200 ,
(HWND)NULL, NULL, hInstance, NULL);
/*
wc.hCursor = 0;
wc.lpszClassName = (LPTSTR) "Menu App";
hwnd = CreateWindow ("Menu App", "display mouse xy",
WS_VISIBLE, 0 ,30 , 300 , 200 ,
(HWND)NULL, NULL, hInstance, (LPSTR)NULL);
*/
/* -------- -------- -------- --------
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)MenuWndProc ;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "WindowsApp";
if( RegisterClass(&wc) ==0 ){ return -1; }
hwnd = CreateWindowEx( 1, "WindowApp", "Windows Clock",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL );
*/
ExitButton = CreateWindow(
"BUTTON", "quit", WS_CHILD |
WS_VISIBLE | BS_PUSHBUTTON,
0, 30 , 40 , 40 , hwnd, (HMENU)IDC_ExitButton,
hInstance, NULL);
ShowWindow(hwnd, ncmdshow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
} /* end WinMain */