Advertisement
Guest User

Untitled

a guest
Dec 28th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. // This is a Win32 program,it simply demonstrates how to draw lines in a window
  2. // Basicaly,you draw a line by clicking somehwere on the window and while the button
  3. // is pressed,you simply move the mouse to a new position and then release the button
  4. // @author: Gonzales Cenelia
  5. // homepage: www.ai-search.4t.com
  6. #include <windows.h>
  7. #include <windows.h>
  8.  
  9. LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  10.  
  11. int WINAPI WinMain( HINSTANCE hInstance,
  12. HINSTANCE hPrevInstance,
  13. LPSTR lpCmdLine,
  14. int nShowCmd) {
  15. HWND hWnd;
  16. MSG msg;
  17. WNDCLASSEX wc;
  18. wc.cbSize = sizeof(WNDCLASSEX);
  19. wc.cbClsExtra = 0;
  20. wc.cbWndExtra = 0;
  21. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  22. wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
  23. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  24. wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  25. wc.hInstance = hInstance;
  26. wc.lpfnWndProc = WndProc;
  27. wc.lpszClassName = "DrawingApp1";
  28. wc.lpszMenuName = NULL;
  29. wc.style = CS_HREDRAW | CS_VREDRAW;
  30.  
  31. // registering the class
  32. if(!RegisterClassEx(&wc)) {
  33. MessageBox(NULL, "Error while registering window", "OPenGL Tutorial", MB_OK );
  34. return 1;
  35. }
  36.  
  37. // creating the window
  38. hWnd = CreateWindowEx(
  39. WS_EX_OVERLAPPEDWINDOW,
  40. "DrawingApp1",
  41. "Win32 DrawingApp",
  42. WS_OVERLAPPEDWINDOW,
  43. 150,
  44. 100,
  45. 640,
  46. 480,
  47. NULL,
  48. NULL,
  49. hInstance,
  50. NULL );
  51.  
  52. if(!hWnd) {
  53. MessageBox(NULL, "Error while creating window", "OpenGL Tutorial", MB_OK );
  54. return 1;
  55. }
  56.  
  57. ShowWindow(hWnd, SW_SHOW);
  58. UpdateWindow(hWnd);
  59.  
  60. while( GetMessage( &msg, 0, 0, 0 ) > 0 ) {
  61. TranslateMessage(&msg);
  62. DispatchMessage(&msg);
  63. }
  64.  
  65. return msg.wParam;
  66. }
  67.  
  68. LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
  69. static BOOL bButtonClicked = 0;
  70. static int X = 0, Y = 0;
  71. HDC hDC = NULL;
  72.  
  73. switch(Msg) {
  74. case WM_LBUTTONDOWN:
  75. bButtonClicked = 1;
  76. X = LOWORD(lParam);
  77. Y = HIWORD(lParam);
  78. break;
  79. case WM_LBUTTONUP:
  80. if(bButtonClicked) {
  81. hDC = GetDC(hWnd);
  82. MoveToEx( hDC, X, Y, NULL );
  83. X = LOWORD(lParam);
  84. Y = HIWORD(lParam);
  85. LineTo( hDC, X, Y );
  86. bButtonClicked = 0;
  87. ReleaseDC( hWnd, hDC );
  88. }
  89. break;
  90. case WM_MOUSEMOVE:
  91. break;
  92. case WM_CLOSE:
  93. DestroyWindow(hWnd);
  94. break;
  95. case WM_DESTROY:
  96. PostQuitMessage(0);
  97. break;
  98. }
  99. return DefWindowProc(hWnd, Msg, wParam, lParam);
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement