Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

dialog.cpp

Go to the documentation of this file.
00001 /****************************************************************************** 00002 00003 Source File: Dialog.CPP 00004 00005 Implements the CDialog class. See Dialog.H for class definitions and details 00006 00007 Copyright (c) 1996 by Microsoft Corporation 00008 00009 A Pretty Penny Enterprises Production 00010 00011 Change History: 00012 00013 11-01-96 [email protected] Created it 00014 12-11-96 [email protected] Implemented hook 00015 00016 ******************************************************************************/ 00017 00018 #include "ICMUI.H" 00019 00020 // CDialog member functions 00021 00022 // Class constructor- just save things, for now 00023 00024 CDialog::CDialog(HINSTANCE hiWhere, int id, HWND hwndParent) { 00025 m_idMain = id; 00026 m_hwndParent = hwndParent; 00027 m_hiWhere = hiWhere; 00028 m_bIsModal = FALSE; 00029 m_hwnd = NULL; 00030 m_dpHook = NULL; 00031 m_lpHook = 0; 00032 } 00033 00034 CDialog::CDialog(CDialog &cdOwner, int id) { 00035 m_idMain = id; 00036 m_hwndParent = cdOwner.m_hwnd; 00037 m_hiWhere = cdOwner.m_hiWhere; 00038 m_bIsModal = FALSE; 00039 m_hwnd = NULL; 00040 m_dpHook = NULL; 00041 m_lpHook = 0; 00042 } 00043 00044 // Class destructor- clean up the window, if it is modeless. 00045 00046 CDialog::~CDialog() { 00047 Destroy(); 00048 } 00049 00050 // Modal Dialog Box 00051 00052 LONG CDialog::DoModal() { 00053 m_bIsModal = TRUE; 00054 return (LONG)DialogBoxParam(m_hiWhere, MAKEINTRESOURCE(m_idMain), m_hwndParent, 00055 CDialog::DialogProc, (LPARAM) this); 00056 } 00057 00058 // Modeless dialog box creation 00059 00060 void CDialog::Create() { 00061 if (!m_bIsModal && m_hwnd) 00062 return; // We'va already got one! 00063 00064 m_bIsModal = FALSE; 00065 CreateDialogParam(m_hiWhere, MAKEINTRESOURCE(m_idMain), 00066 m_hwndParent, CDialog::DialogProc, (LPARAM) this); 00067 } 00068 00069 // Modeless dialog box destruction 00070 00071 void CDialog::Destroy() { 00072 if (!m_bIsModal && m_hwnd) { 00073 DestroyWindow(m_hwnd); 00074 m_hwnd = NULL; 00075 } 00076 } 00077 00078 // Dialog Procedure- this is a static private method. This means 00079 // that all instances of this class (including derived classes) share 00080 // this code (no pointers needed) and that only instances of this 00081 // class (not even derived classes) can find it. 00082 00083 INT_PTR CALLBACK CDialog::DialogProc(HWND hwndMe, UINT uMsg, WPARAM wp, 00084 LPARAM lp) { 00085 00086 CDialog *pcdMe = (CDialog *) GetWindowLongPtr(hwndMe, DWLP_USER); 00087 00088 // If there is a hook procedure, it can either ignore or filter a 00089 // message by returning FALSE, or it can handle itself by returning 00090 // TRUE. WM_INITDALOG hook processing occurs AFTER all of our other 00091 // calls are made, and we allow the base class to define the LPARAM 00092 // that is passed in to the hook. 00093 // Because we do not have a pointer to the base class, we will miss 00094 // messages sent before WM_INITDIALOG (specifically WM_SETFONT) 00095 00096 if (uMsg != WM_INITDIALOG && pcdMe && pcdMe -> m_dpHook && 00097 (*pcdMe -> m_dpHook)(hwndMe, uMsg, wp, lp)) 00098 return TRUE; 00099 00100 switch (uMsg) { 00101 00102 case WM_INITDIALOG: 00103 00104 // The lp is the this pointer for the caller 00105 00106 pcdMe = (CDialog *) lp; 00107 00108 SetWindowLongPtr(hwndMe, DWLP_USER, (LONG_PTR)pcdMe); 00109 pcdMe -> m_hwnd = hwndMe; 00110 00111 // Derived classes override OnInit to initialize the dialog 00112 00113 if (!pcdMe -> m_dpHook) 00114 return pcdMe -> OnInit(); 00115 else { 00116 // If there is a hook procedure, we will call that after the 00117 // override- if the override returned FALSE, so must we 00118 BOOL bReturn = pcdMe -> OnInit(); 00119 return (*pcdMe -> m_dpHook)(hwndMe, uMsg, wp, 00120 pcdMe -> m_lpHook) && bReturn; 00121 } 00122 00123 case WM_COMMAND: 00124 00125 return pcdMe -> OnCommand(HIWORD(wp), LOWORD(wp), (HWND) lp); 00126 00127 case WM_NOTIFY: 00128 00129 return pcdMe -> OnNotify((int) wp, (LPNMHDR) lp); 00130 00131 case WM_HELP: 00132 00133 return pcdMe -> OnHelp((LPHELPINFO) lp); 00134 00135 case WM_CONTEXTMENU: 00136 00137 return pcdMe -> OnContextMenu((HWND) wp); 00138 00139 } 00140 00141 return FALSE; 00142 } 00143 00144 // Moves the window into position (needed to get dialogs positioned proeprly 00145 // in tab control display area). 00146 00147 void CDialog::Adjust(RECT& rc) { 00148 SetWindowPos(m_hwnd, HWND_TOP, rc.left, rc.top, 0, 0, 00149 SWP_NOACTIVATE | SWP_NOSIZE | SWP_SHOWWINDOW); 00150 }

Generated on Sat May 15 19:39:44 2004 for test by doxygen 1.3.7