14win32_14_button按钮

Posted 养老保险年审

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了14win32_14_button按钮相关的知识,希望对你有一定的参考价值。

14win32_14_button按钮

  1. #include <windows.h>
  2. #include <iostream>
  3. CHAR szText[256] = { 0 };
  4. #define PrintLog(x) WriteConsole(g_hStdout, x, strlen(x), NULL, NULL)
  5. HINSTANCE g_hInst = NULL; //窗口句柄
  6. HANDLE g_hStdout = NULL; //控制台句柄
  7. //OnCreate
  8. void OnCreate(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
  9. {
  10. //下压式Button
  11. CreateWindow("BUTTON", "PUSH_BUTTON", WS_CHILD | WS_VISIBLE, 100, 100, 200, 40, hWnd, (HMENU)1001, g_hInst, NULL);
  12. //三态按键
  13. CreateWindow("BUTTON", "我是三态按键", WS_CHILD | WS_VISIBLE | BS_AUTO3STATE|BS_PUSHLIKE/*若不加这个风格,则像CheckBox*/, 400, 100, 200, 40, hWnd, (HMENU)2001, g_hInst, NULL);
  14. //分组按钮
  15. CreateWindow("BUTTON", "分组一", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 100, 200, 300, 300,
  16. hWnd, (HMENU)3001, g_hInst, NULL);
  17. //多选按钮,CheckBox
  18. CreateWindow("BUTTON", "checkbox", WS_CHILD | WS_VISIBLE | BS_CHECKBOX, 120, 220, 200, 30,
  19. hWnd, (HMENU)4001, g_hInst, NULL);
  20. CreateWindow("BUTTON", "Auto_check_box", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, 120, 250, 200, 30,
  21. hWnd, (HMENU)4002, g_hInst, NULL);
  22. //单选按钮
  23. CreateWindow("BUTTON", "A", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON|WS_GROUP/*分组,把AB分成一组*/,
  24. 120, 300, 100, 30, hWnd, (HMENU)5001, g_hInst,NULL);
  25. CreateWindow("BUTTON", "B", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
  26. 120, 330, 100, 30, hWnd, (HMENU)5002, g_hInst,NULL);
  27. CreateWindow("BUTTON", "C", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON|WS_GROUP/*分组,把CD分成一组*/,
  28. 120, 360, 100, 30, hWnd, (HMENU)5003, g_hInst,NULL);
  29. CreateWindow("BUTTON", "D", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
  30. 120, 390, 100, 30, hWnd, (HMENU)5004, g_hInst,NULL);
  31. }
  32. //响应按钮
  33. void OnCommand(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
  34. {
  35. int nNotifyCode = HIWORD(wParam);
  36. int nEventID = LOWORD(wParam);
  37. switch (nEventID)
  38. {
  39. case 1001:
  40. switch (nNotifyCode)
  41. {
  42. //push_button消息的响应,一般只处理点击消息,其它消息很少处理
  43. case BN_CLICKED:
  44. MessageBox(NULL, "Hello push_button!", "button", MB_OK);
  45. break;
  46. }
  47. break;
  48. case 4002:
  49. {
  50. HWND hCtrl = GetDlgItem(hWnd, 4002);
  51. LRESULT nCheck = 0;
  52. switch (nNotifyCode)
  53. {
  54. //push_button消息的响应,一般只处理点击消息,其它消息很少处理
  55. case BN_CLICKED:
  56. {
  57. //获取当前CheckBox的状态
  58. nCheck = SendMessage(hCtrl, BM_GETCHECK, 0, 0);
  59. //判断当前状态是否被选择
  60. if (nCheck & BST_CHECKED)
  61. {
  62. //设置成不选择状态
  63. SendMessage(hCtrl, BM_SETCHECK, BST_UNCHECKED, 0);
  64. }
  65. else
  66. {
  67. //设置成选择状态
  68. SendMessage(hCtrl, BM_SETCHECK, BST_CHECKED, 0);
  69. }
  70. break;
  71. }
  72. }
  73. break;
  74. }
  75. }
  76. }
  77. LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
  78. {
  79. switch (nMsg)
  80. {
  81. case WM_CREATE:
  82. OnCreate(hWnd, nMsg, wParam, lParam);
  83. break;
  84. case WM_COMMAND:
  85. OnCommand(hWnd, nMsg, wParam, lParam);
  86. break;
  87. case WM_DESTROY:
  88. PostQuitMessage(0);
  89. break;
  90. }
  91. return DefWindowProc(hWnd, nMsg, wParam, lParam);
  92. }
  93. BOOL RegisterWnd(LPSTR pszClassName)
  94. {
  95. WNDCLASSEX wce = { 0 };
  96. wce.cbSize = sizeof(wce);
  97. wce.cbClsExtra = 0;
  98. wce.cbWndExtra = 0;
  99. wce.hbrBackground = HBRUSH(COLOR_BTNFACE + 1);
  100. wce.hCursor = NULL;
  101. wce.hIcon = NULL;
  102. wce.hIconSm = NULL;
  103. wce.hInstance = g_hInst;
  104. wce.lpfnWndProc = WndProc;
  105. wce.lpszClassName = pszClassName;
  106. wce.lpszMenuName = NULL;
  107. wce.style = CS_HREDRAW | CS_VREDRAW;
  108. ATOM atom = RegisterClassEx(&wce);
  109. if (atom == NULL)
  110. {
  111. return FALSE;
  112. }
  113. else
  114. {
  115. return TRUE;
  116. }
  117. }
  118. HWND CreateWnd(LPSTR pszClassName)
  119. {
  120. HWND hWnd = CreateWindowEx(0, pszClassName, "灭天", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  121. CW_USEDEFAULT, NULL, NULL, g_hInst, 0);
  122. return hWnd;
  123. }
  124. void ShowWnd(HWND hWnd)
  125. {
  126. ShowWindow(hWnd, SW_SHOW);
  127. UpdateWindow(hWnd);
  128. }
  129. void Msg()
  130. {
  131. MSG msg = { 0 };
  132. while (GetMessage(&msg, NULL, 0, 0))
  133. {
  134. TranslateMessage(&msg);
  135. DispatchMessage(&msg);
  136. }
  137. }
  138. void ConsoleWnd()
  139. {
  140. AllocConsole();
  141. g_hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  142. CHAR szText[] = "Debug start:\n";
  143. WriteConsole(g_hStdout, szText, strlen(szText), NULL, NULL);
  144. }
  145. int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
  146. {
  147. g_hInst = hInstance;
  148. //ConsoleWnd();
  149. RegisterWnd("oooo");
  150. HWND hWnd = CreateWnd("oooo");
  151. ShowWnd(hWnd);
  152. Msg();
  153. return 0;
  154. }





以上是关于14win32_14_button按钮的主要内容,如果未能解决你的问题,请参考以下文章

BricsCAD.Platinum.v14.2.12.34721.Win32_64 2CD

2016-10-10 14:23:33 scrapy crawl projectName (cannot import name '_win32stdio')

xilinx ISE_14.7 for win 8/10

Windows 添加按钮

带有 If Else 语句的 Python Tkinter 按钮

Actix.Analyzer.v5.5.338.385.Win32_64 2CD+Magus Pro 5.2