Advertisement
Guest User

drag n drop

a guest
Jul 19th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. #include <Windows.h>
  2.  
  3. HWND editBox1;
  4. HWND editBox2;
  5.  
  6. MSG evnt;
  7.  
  8. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  9.  
  10. void init(HINSTANCE hInstance, LPSTR className);
  11.  
  12. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  13. {
  14. // Creating window class
  15. LPSTR className = "Window Class";
  16. init(hInstance, className);
  17.  
  18. // Creating main window
  19. HWND hwnd;
  20. hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, className, "Drag n Drop", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, NULL, NULL, hInstance, NULL);
  21.  
  22. // Error checking
  23. if (hwnd == NULL)
  24. {
  25. MessageBox(NULL, "Could not create window", "", MB_ICONEXCLAMATION);
  26. return 1;
  27. }
  28.  
  29. ShowWindow(hwnd, nCmdShow); // Pokaż okienko...
  30. UpdateWindow(hwnd);
  31.  
  32. editBox1 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE, 150, 80, 200, 50, hwnd, (HMENU)1, hInstance, NULL);
  33. editBox2 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE, 150, 150, 200, 50, hwnd, (HMENU)2, hInstance, NULL);
  34.  
  35. while (GetMessage(&evnt, NULL, 0, 0))
  36. {
  37. TranslateMessage(&evnt);
  38. DispatchMessage(&evnt);
  39. }
  40. return evnt.wParam;
  41. }
  42.  
  43. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  44. {
  45. switch (msg)
  46. {
  47. case WM_COMMAND:
  48. switch (wParam)
  49. {
  50. case 1:
  51. // Button 1
  52. break;
  53. }
  54. break;
  55.  
  56. case WM_CLOSE:
  57. DestroyWindow(hwnd);
  58. break;
  59.  
  60. case WM_DESTROY:
  61. PostQuitMessage(0);
  62. break;
  63.  
  64. default:
  65. return DefWindowProc(hwnd, msg, wParam, lParam);
  66. }
  67. return 0;
  68. }
  69.  
  70. void init(HINSTANCE hInstance, LPSTR className)
  71. {
  72. WNDCLASSEX wc;
  73.  
  74. wc.cbSize = sizeof(WNDCLASSEX);
  75. wc.style = 0;
  76. wc.lpfnWndProc = WndProc;
  77. wc.cbClsExtra = 0;
  78. wc.cbWndExtra = 0;
  79. wc.hInstance = hInstance;
  80. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  81. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  82. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  83. wc.lpszMenuName = NULL;
  84. wc.lpszClassName = className;
  85. wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  86.  
  87. // Registering window class
  88. if (!RegisterClassEx(&wc))
  89. {
  90. MessageBox(NULL, "Could not register window!", "", MB_ICONEXCLAMATION | MB_OK);
  91. return;
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement