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.

103 lines
2.7 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  2. #include <stdafx.h>
  3. #include <windows.h>
  4. #include "msgwindow.h"
  5. extern CComModule _Module;
  6. // limit to this file
  7. //
  8. static const TCHAR szClassName[] = TEXT("CMSWEBDVDMsgWindowClass");
  9. static const TCHAR szDefaultWindowName[] = TEXT("CMSWEBDVDMsgWindowClassName");
  10. //
  11. // CMessageWindow class implementation
  12. // Generic goo to create a dummy window to handle events
  13. //
  14. static LRESULT CALLBACK StaticMsgWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  15. {
  16. CMsgWindow* win = (CMsgWindow*) GetWindowLongPtr( hWnd, GWLP_USERDATA );
  17. if( !win ) {
  18. if( uMsg == WM_CREATE) {
  19. // on WM_CREATE messages the last parameter to CreateWindow() is returned in the lparam
  20. CREATESTRUCT* pCreate = (CREATESTRUCT *)lParam;
  21. win = (CMsgWindow*) pCreate->lpCreateParams;
  22. SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)win);
  23. win->SetHandle(hWnd);
  24. } else {
  25. return DefWindowProc( hWnd, uMsg, wParam, lParam);
  26. }
  27. }
  28. return win->WndProc( uMsg, wParam, lParam );
  29. }
  30. CMsgWindow::CMsgWindow()
  31. : m_hWnd( NULL )
  32. {
  33. WNDCLASS wc; // class data
  34. if (!GetClassInfo(_Module.GetModuleInstance(), szClassName, &wc))
  35. {
  36. //
  37. // Register message window class
  38. //
  39. ZeroMemory(&wc, sizeof(wc)) ;
  40. wc.lpfnWndProc = StaticMsgWndProc ;
  41. wc.hInstance = _Module.GetModuleInstance() ;
  42. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) ;
  43. wc.lpszClassName = szClassName;
  44. wc.cbWndExtra = sizeof( LONG_PTR );
  45. if (0 == RegisterClass(&wc) ) // Oops, just leave; we'll catch later...
  46. {
  47. }
  48. }
  49. }
  50. bool CMsgWindow::Open( LPCTSTR pWindowName )
  51. {
  52. if( m_hWnd ) {
  53. DestroyWindow( m_hWnd );
  54. }
  55. if (NULL == pWindowName) {
  56. pWindowName = szDefaultWindowName;
  57. }
  58. //
  59. // m_hWnd is assigned during WM_CREATE message processing
  60. //
  61. HWND hwnd =
  62. CreateWindowEx(WS_EX_TOOLWINDOW, szClassName, pWindowName,
  63. WS_ICONIC, 0, 0, 1, 1, NULL, NULL,
  64. GetModuleHandle(NULL),
  65. this );
  66. return (NULL != hwnd);
  67. }
  68. bool CMsgWindow::Close(){
  69. if(m_hWnd){
  70. DestroyWindow(m_hWnd);
  71. //SetWindowLongPtr(m_hWnd, GWLP_USERDATA, (LONG_PTR)0);
  72. //PostMessage(m_hWnd, WM_CLOSE, 0, 0);
  73. //m_hWnd = NULL;
  74. }/* end of if statement */
  75. return(true);
  76. }/* end of function Close */
  77. CMsgWindow::~CMsgWindow()
  78. {
  79. SetWindowLongPtr(m_hWnd, GWLP_USERDATA, (LONG_PTR)0);
  80. PostMessage(m_hWnd, WM_CLOSE, 0, 0);
  81. }
  82. LRESULT CMsgWindow::WndProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
  83. {
  84. return DefWindowProc(m_hWnd, uMsg, wParam, lParam);
  85. }