Windows编程基础程序

我不是女神ヾ 2022-08-10 08:38 215阅读 0赞

Windows编程基础程序

  1. /*-----------------------------------------------------------
  2. HELLLO.C--Display "Hello Windows 98" in client area
  3. (c) me in 2015 year
  4. ------------------------------------------------------------*/
  5. #include "stdafx.h"
  6. #include "HELLOWIN.h"
  7. #include <Windows.h>
  8. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  9. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  10. {
  11. static TCHAR szAppName[] = TEXT("HelloWin");
  12. HWND hwnd;
  13. MSG msg;
  14. WNDCLASS wndclass;
  15. //注册窗口
  16. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  17. wndclass.lpfnWndProc = WndProc;
  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 = szAppName;
  26. //如果注册失败弹出MessageBox
  27. if (!RegisterClass(&wndclass))
  28. {
  29. MessageBox(NULL, TEXT("THIS program requires Windows NT!"),
  30. szAppName, MB_ICONERROR);
  31. return 0;
  32. }
  33. //创建窗口
  34. hwnd = CreateWindow(szAppName,
  35. TEXT("The Hello Progarm"),
  36. WS_OVERLAPPEDWINDOW,
  37. CW_USEDEFAULT,
  38. CW_USEDEFAULT,
  39. CW_USEDEFAULT,
  40. CW_USEDEFAULT,
  41. NULL,
  42. NULL,
  43. hInstance,
  44. NULL);
  45. ShowWindow(hwnd, iCmdShow);
  46. UpdateWindow(hwnd);
  47. while (GetMessage (&msg,NULL,0,0)) //检索消息
  48. {
  49. TranslateMessage(&msg); //翻译消息
  50. DispatchMessage(&msg); //分发消息
  51. }
  52. return msg.wParam;
  53. }
  54. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  55. {
  56. HDC hdc;
  57. PAINTSTRUCT ps;
  58. RECT rect;
  59. switch (message)
  60. {
  61. case WM_CREATE:
  62. //PlaySound(TEXT("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC);
  63. return 0;
  64. case WM_PAINT:
  65. hdc = BeginPaint(hwnd, &ps);
  66. GetClientRect(hwnd, &rect);
  67. DrawText(hdc, TEXT("Hello Windwos 98!"), -1, &rect,
  68. DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  69. EndPaint(hwnd, &ps);
  70. return 0;
  71. case WM_DESTROY:
  72. PostQuitMessage(0);
  73. return 0;
  74. }
  75. return DefWindowProc(hwnd, message, wParam, lParam);
  76. }

对以上代码的详细讲解
这里写链接内容

发表评论

表情:
评论列表 (有 0 条评论,215人围观)

还没有评论,来说两句吧...

相关阅读