Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <math.h>
- LRESULT CALLBACK HelloWorldWndProc( HWND, UINT, UINT, LONG );
- char text[30];
- int x,y;
- int count;
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpszCmdParam, int nCmdShow )
- {
- HWND hWnd;
- WNDCLASS WndClass;
- MSG Msg;
- char szClassName[] = "Hello World";
- WndClass.style = CS_HREDRAW | CS_VREDRAW;
- WndClass.lpfnWndProc = HelloWorldWndProc;
- WndClass.cbClsExtra = 0;
- WndClass.cbWndExtra = 0;
- WndClass.hInstance = hInstance;
- WndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
- WndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
- WndClass.hbrBackground = ( HBRUSH )GetStockObject( WHITE_BRUSH );
- WndClass.lpszMenuName = NULL;
- WndClass.lpszClassName = szClassName;
- if( !RegisterClass( &WndClass ) )
- {
- MessageBox( NULL, "Cannot register class", "Error", MB_OK );
- return 0;
- }
- hWnd = CreateWindow( szClassName,
- "Program No 1",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL );
- if( !hWnd )
- {
- MessageBox( NULL, "Cannot create window", "Error", MB_OK );
- return 0;
- }
- ShowWindow( hWnd, nCmdShow );
- UpdateWindow( hWnd );
- while( GetMessage( &Msg, NULL, 0, 0 ) )
- {
- TranslateMessage( &Msg );
- DispatchMessage( &Msg );
- }
- return Msg.wParam;
- }
- LRESULT CALLBACK HelloWorldWndProc( HWND hWnd, UINT Message,
- UINT wParam, LONG lParam )
- {
- HDC hDC;
- PAINTSTRUCT PaintStruct;
- RECT Rect;
- HPEN pen = CreatePen(PS_SOLID, 0, RGB(255,0,0));
- switch( Message )
- {
- case WM_PAINT :
- hDC = BeginPaint( hWnd, &PaintStruct );
- GetClientRect( hWnd, &Rect );
- SelectObject(hDC, pen);
- if(text[0] == 'Y'){
- TextOut(hDC, y, x, text, count);
- }
- EndPaint( hWnd, &PaintStruct );
- return 0;
- case WM_LBUTTONDOWN :
- count = wsprintf(text,"Y:%d, X:%d",LOWORD(lParam),HIWORD(lParam));
- y = LOWORD(lParam);
- x = HIWORD(lParam);
- InvalidateRect(hWnd, &Rect, true);
- return 0;
- case WM_DESTROY :
- PostQuitMessage( 0 );
- return 0;
- }
- return DefWindowProc( hWnd, Message, wParam, lParam );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement