Leaked source code of windows server 2003
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.

145 lines
3.9 KiB

  1. /*****************************************************************************
  2. *
  3. * window.cpp
  4. *
  5. *****************************************************************************/
  6. #include "sdview.h"
  7. LRESULT CALLBACK FrameWindow::WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  8. {
  9. FrameWindow *self;
  10. if (uiMsg == WM_NCCREATE) {
  11. LPCREATESTRUCT lpcs = RECAST(LPCREATESTRUCT, lParam);
  12. self = RECAST(FrameWindow *, lpcs->lpCreateParams);
  13. self->_hwnd = hwnd;
  14. SetWindowLongPtr(self->_hwnd, GWLP_USERDATA, RECAST(LPARAM, self));
  15. } else {
  16. self = RECAST(FrameWindow *, GetWindowLongPtr(hwnd, GWLP_USERDATA));
  17. }
  18. if (self) {
  19. return self->HandleMessage(uiMsg, wParam, lParam);
  20. } else {
  21. return DefWindowProc(hwnd, uiMsg, wParam, lParam);
  22. }
  23. }
  24. //
  25. // Default message handler. Messages land here after passing through
  26. // all the derived classes.
  27. //
  28. LRESULT FrameWindow::HandleMessage(UINT uiMsg, WPARAM wParam, LPARAM lParam)
  29. {
  30. switch (uiMsg) {
  31. case WM_NCDESTROY:
  32. _hwnd = NULL;
  33. PostQuitMessage(0);
  34. break;
  35. case WM_SIZE:
  36. if (_hwndChild) {
  37. SetWindowPos(_hwndChild, NULL, 0, 0,
  38. GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
  39. SWP_NOZORDER | SWP_NOACTIVATE);
  40. }
  41. return 0;
  42. case WM_SETFOCUS:
  43. if (_hwndChild) {
  44. SetFocus(_hwndChild);
  45. }
  46. return 0;
  47. case WM_CLOSE:
  48. if (GetKeyState(VK_SHIFT) < 0) {
  49. g_lThreads = 1; // force app to exit
  50. }
  51. break;
  52. case WM_COMMAND:
  53. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  54. case IDM_EXIT:
  55. DestroyWindow(_hwnd);
  56. break;
  57. case IDM_EXITALL:
  58. g_lThreads = 1; // force app to exit
  59. DestroyWindow(_hwnd);
  60. break;
  61. }
  62. break;
  63. case WM_HELP:
  64. Help(_hwnd, NULL);
  65. break;
  66. }
  67. return DefWindowProc(_hwnd, uiMsg, wParam, lParam);
  68. }
  69. #define CLASSNAME TEXT("SD View")
  70. HWND FrameWindow::CreateFrameWindow()
  71. {
  72. WNDCLASS wc;
  73. if (!GetClassInfo(g_hinst, CLASSNAME, &wc)) {
  74. wc.style = 0;
  75. wc.lpfnWndProc = WndProc;
  76. wc.cbClsExtra = 0;
  77. wc.cbWndExtra = 0;
  78. wc.hInstance = g_hinst;
  79. wc.hIcon = LoadIcon(g_hinst, MAKEINTRESOURCE(IDI_SDV));
  80. wc.hCursor = g_hcurArrow;
  81. wc.hbrBackground = RECAST(HBRUSH, COLOR_WINDOW + 1);
  82. wc.lpszMenuName = NULL;
  83. wc.lpszClassName = CLASSNAME;
  84. if (!RegisterClass(&wc)) {
  85. return NULL;
  86. }
  87. }
  88. _hwnd = CreateWindow(
  89. CLASSNAME, /* Class Name */
  90. NULL, /* Title */
  91. WS_CLIPCHILDREN | WS_VISIBLE |
  92. WS_OVERLAPPEDWINDOW, /* Style */
  93. CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
  94. CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
  95. NULL, /* Parent */
  96. NULL, /* No menu */
  97. g_hinst, /* Instance */
  98. this); /* Special parameters */
  99. return _hwnd;
  100. }
  101. DWORD FrameWindow::RunThread(FrameWindow *self, LPVOID lpParameter)
  102. {
  103. if (self) {
  104. self->_pszQuery = RECAST(LPTSTR, lpParameter);
  105. if (self->CreateFrameWindow()) {
  106. MSG msg;
  107. while (GetMessage(&msg, NULL, 0, 0)) {
  108. if (self->_haccel && TranslateAccelerator(self->_hwnd, self->_haccel, &msg)) {
  109. } else {
  110. TranslateMessage(&msg);
  111. DispatchMessage(&msg);
  112. }
  113. }
  114. }
  115. delete self;
  116. }
  117. if (lpParameter) {
  118. LocalFree(lpParameter);
  119. }
  120. return EndThreadTask(0);
  121. }