Advertisement
Guest User

Untitled

a guest
May 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <math.h>
  3.  
  4. LRESULT CALLBACK HelloWorldWndProc( HWND, UINT, UINT, LONG );
  5. char text[30];
  6. int x,y;
  7. int count;
  8.  
  9. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  10. LPSTR lpszCmdParam, int nCmdShow )
  11. {
  12. HWND hWnd;
  13. WNDCLASS WndClass;
  14. MSG Msg;
  15. char szClassName[] = "Hello World";
  16. WndClass.style = CS_HREDRAW | CS_VREDRAW;
  17. WndClass.lpfnWndProc = HelloWorldWndProc;
  18. WndClass.cbClsExtra = 0;
  19. WndClass.cbWndExtra = 0;
  20. WndClass.hInstance = hInstance;
  21. WndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
  22. WndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
  23. WndClass.hbrBackground = ( HBRUSH )GetStockObject( WHITE_BRUSH );
  24. WndClass.lpszMenuName = NULL;
  25. WndClass.lpszClassName = szClassName;
  26.  
  27. if( !RegisterClass( &WndClass ) )
  28. {
  29. MessageBox( NULL, "Cannot register class", "Error", MB_OK );
  30. return 0;
  31. }
  32.  
  33. hWnd = CreateWindow( szClassName,
  34. "Program No 1",
  35. WS_OVERLAPPEDWINDOW,
  36. CW_USEDEFAULT,
  37. CW_USEDEFAULT,
  38. CW_USEDEFAULT,
  39. CW_USEDEFAULT,
  40. NULL,
  41. NULL,
  42. hInstance,
  43. NULL );
  44.  
  45. if( !hWnd )
  46. {
  47. MessageBox( NULL, "Cannot create window", "Error", MB_OK );
  48. return 0;
  49. }
  50.  
  51. ShowWindow( hWnd, nCmdShow );
  52. UpdateWindow( hWnd );
  53.  
  54. while( GetMessage( &Msg, NULL, 0, 0 ) )
  55. {
  56. TranslateMessage( &Msg );
  57. DispatchMessage( &Msg );
  58. }
  59. return Msg.wParam;
  60. }
  61.  
  62. LRESULT CALLBACK HelloWorldWndProc( HWND hWnd, UINT Message,
  63. UINT wParam, LONG lParam )
  64. {
  65. HDC hDC;
  66. PAINTSTRUCT PaintStruct;
  67. RECT Rect;
  68. HPEN pen = CreatePen(PS_SOLID, 0, RGB(255,0,0));
  69. switch( Message )
  70. {
  71. case WM_PAINT :
  72. hDC = BeginPaint( hWnd, &PaintStruct );
  73. GetClientRect( hWnd, &Rect );
  74. SelectObject(hDC, pen);
  75. if(text[0] == 'Y'){
  76. TextOut(hDC, y, x, text, count);
  77. }
  78. EndPaint( hWnd, &PaintStruct );
  79. return 0;
  80. case WM_LBUTTONDOWN :
  81. count = wsprintf(text,"Y:%d, X:%d",LOWORD(lParam),HIWORD(lParam));
  82. y = LOWORD(lParam);
  83. x = HIWORD(lParam);
  84. InvalidateRect(hWnd, &Rect, true);
  85. return 0;
  86. case WM_DESTROY :
  87. PostQuitMessage( 0 );
  88. return 0;
  89. }
  90.  
  91. return DefWindowProc( hWnd, Message, wParam, lParam );
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement