Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.9 KiB

  1. #ifndef _MAINAPPWINDOW
  2. #define _MAINAPPWINDOW
  3. #include "stdafx.h"
  4. #include "CWindow.h"
  5. class CMainWnd {
  6. private:
  7. HWND m_hWnd;
  8. INT m_IconResourceID;
  9. public:
  10. CMainWnd( HWND hWnd )
  11. : m_hWnd(hWnd)
  12. {
  13. }
  14. ~CMainWnd(void)
  15. {
  16. }
  17. static BOOL RegisterClass( HINSTANCE hInstance, LPCTSTR pszClassName )
  18. {
  19. WNDCLASSEX wcex;
  20. ZeroMemory(&wcex,sizeof(wcex));
  21. wcex.cbSize = sizeof(wcex);
  22. if (!GetClassInfoEx( hInstance, pszClassName, &wcex )) {
  23. ZeroMemory(&wcex,sizeof(wcex));
  24. wcex.cbSize = sizeof(wcex);
  25. wcex.style = 0;
  26. wcex.lpfnWndProc = (WNDPROC)WndProc;
  27. wcex.cbClsExtra = 0;
  28. wcex.cbWndExtra = 0;
  29. wcex.hInstance = hInstance;
  30. wcex.hIcon = ::LoadIcon(hInstance, MAKEINTRESOURCE(107/*IDI_PROPVIEW*/));
  31. wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
  32. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  33. wcex.lpszMenuName = NULL;
  34. wcex.lpszClassName = pszClassName;
  35. wcex.hIconSm = 0;
  36. if (!::RegisterClassEx(&wcex)) {
  37. return FALSE;
  38. }
  39. return TRUE;
  40. }
  41. return TRUE;
  42. }
  43. static HWND Create( LPCTSTR lpWindowName,
  44. LPCTSTR lpWindowClassName,
  45. DWORD dwStyle,
  46. DWORD dwExStyle,
  47. int x,
  48. int y,
  49. int nWidth,
  50. int nHeight,
  51. HWND hWndParent,
  52. HMENU hMenu,
  53. HINSTANCE hInstance )
  54. {
  55. //
  56. // register the window class
  57. //
  58. if (RegisterClass( hInstance, lpWindowClassName )) {
  59. HWND hWnd = CreateWindowEx(dwExStyle,
  60. lpWindowClassName,
  61. lpWindowName,
  62. dwStyle,
  63. x,
  64. y,
  65. nWidth,
  66. nHeight,
  67. hWndParent,
  68. hMenu,
  69. hInstance,
  70. NULL );
  71. SetWindowLongPtr(hWnd,GWLP_USERDATA,NULL);
  72. return hWnd;
  73. } else {
  74. Trace(TEXT("RegisterClass failed, GetLastError() reported %d"),GetLastError());
  75. return NULL;
  76. }
  77. }
  78. //
  79. // public helpers
  80. //
  81. VOID PostMessageToAllChildren(MSG msg);
  82. //
  83. // windows message handlers
  84. //
  85. LRESULT OnPaint ( WPARAM wParam, LPARAM lParam );
  86. LRESULT OnDestroy ( WPARAM wParam, LPARAM lParam );
  87. LRESULT OnCreate ( WPARAM wParam, LPARAM lParam );
  88. LPARAM OnSize ( WPARAM wParam, LPARAM lParam );
  89. LPARAM OnSetFocus( WPARAM wParam, LPARAM lParam );
  90. LRESULT OnCommand ( WPARAM wParam, LPARAM lParam );
  91. //
  92. // menu handlers
  93. //
  94. VOID OnFileExit( WPARAM wParam, LPARAM lParam );
  95. VOID OnSelectDevice( WPARAM wParam, LPARAM lParam );
  96. static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  97. {
  98. //Trace(TEXT("Messages to MainWnd\nhWnd = %p, uMsg = %d, wParam = %x, lParam = %x"), hWnd, uMsg, wParam, lParam);
  99. SC_BEGIN_MESSAGE_HANDLERS(CMainWnd)
  100. {
  101. SC_HANDLE_MESSAGE( WM_PAINT, OnPaint );
  102. SC_HANDLE_MESSAGE( WM_DESTROY, OnDestroy );
  103. SC_HANDLE_MESSAGE( WM_CREATE, OnCreate );
  104. SC_HANDLE_MESSAGE( WM_COMMAND, OnCommand );
  105. SC_HANDLE_MESSAGE( WM_SIZE, OnSize );
  106. SC_HANDLE_MESSAGE( WM_SETFOCUS, OnSetFocus );
  107. }
  108. SC_END_MESSAGE_HANDLERS();
  109. }
  110. };
  111. #endif