Hacking CPropertySheet
-
Hi CPians, In one of my projects, I need a property sheet but there must be a header control on top of the propety sheet. I solved the problem using the source code of CPropertSheet from MFC. Here is the main part of the code: CStepCreatorSheet is derived from CPropertySheet
BOOL CStepCreatorSheet::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();// move the window! CRect rectWnd; GetWindowRect (rectWnd); ScreenToClient(rectWnd); SetWindowPos (NULL, 0, 0, rectWnd.Width(), rectWnd.Height() + m\_nHeaderHeight, SWP\_NOMOVE | SWP\_NOZORDER | SWP\_NOACTIVATE); m\_HeaderCtrl.CreateEx (NULL, NULL, NULL, WS\_CHILD | WS\_VISIBLE | WS\_TABSTOP | WS\_BORDER, -1, -1, rectWnd.Width (), m\_nHeaderHeight - 5, m\_hWnd, 0, 0); // move the tab control HWND hWnd = (HWND)GetTabControl()->m\_hWnd; ASSERT(hWnd != NULL); CRect rectOld; ::GetWindowRect (hWnd, &rectOld); ScreenToClient (&rectOld); //::MoveWindow (hWnd, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height () - m\_nHeaderHeight, TRUE); ::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (), SWP\_NOZORDER | SWP\_NOACTIVATE); //move the property sheet hWnd = (HWND)m\_pMainPage1->m\_hWnd; ASSERT(hWnd != NULL); ::GetWindowRect (hWnd, &rectOld); ScreenToClient (&rectOld); ::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (), SWP\_NOZORDER | SWP\_NOACTIVATE); // move buttons by similar amount for (int i = 0; i < sizeof(\_PropSheetButtons) / sizeof (int); i++) { hWnd = ::GetDlgItem(m\_hWnd, \_PropSheetButtons\[i\]); if (hWnd != NULL) { ::GetWindowRect (hWnd, &rectOld); ScreenToClient (&rectOld); ::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (), SWP\_NOZORDER | SWP\_NOACTIVATE); } } CenterWindow (); return bResult;
}
BOOL CStepCreatorSheet::OnCommand(WPARAM wParam, LPARAM lParam)
{
// allow message map override
if (CWnd::OnCommand(wParam, lParam))
return TRUE;// crack message parameters UINT nID = LOWORD(wParam); HWND hWndCtrl = (HWND)lParam; int nCode = HIWORD(wParam); // set m\_nModalResult to ID of button, whenever button is clicked if (hWndCtrl != NULL && nCode == BN\_CLICKED) { if (::SendMessage(hWndCtrl, WM\_GETDLGCODE, 0, 0) & (DLGC\_BUTTON|DLGC\_DEFPUSHBUTTON)) { LONG lStyle = ::GetWindowLong(hWndCtrl, GW
-
Hi CPians, In one of my projects, I need a property sheet but there must be a header control on top of the propety sheet. I solved the problem using the source code of CPropertSheet from MFC. Here is the main part of the code: CStepCreatorSheet is derived from CPropertySheet
BOOL CStepCreatorSheet::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();// move the window! CRect rectWnd; GetWindowRect (rectWnd); ScreenToClient(rectWnd); SetWindowPos (NULL, 0, 0, rectWnd.Width(), rectWnd.Height() + m\_nHeaderHeight, SWP\_NOMOVE | SWP\_NOZORDER | SWP\_NOACTIVATE); m\_HeaderCtrl.CreateEx (NULL, NULL, NULL, WS\_CHILD | WS\_VISIBLE | WS\_TABSTOP | WS\_BORDER, -1, -1, rectWnd.Width (), m\_nHeaderHeight - 5, m\_hWnd, 0, 0); // move the tab control HWND hWnd = (HWND)GetTabControl()->m\_hWnd; ASSERT(hWnd != NULL); CRect rectOld; ::GetWindowRect (hWnd, &rectOld); ScreenToClient (&rectOld); //::MoveWindow (hWnd, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height () - m\_nHeaderHeight, TRUE); ::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (), SWP\_NOZORDER | SWP\_NOACTIVATE); //move the property sheet hWnd = (HWND)m\_pMainPage1->m\_hWnd; ASSERT(hWnd != NULL); ::GetWindowRect (hWnd, &rectOld); ScreenToClient (&rectOld); ::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (), SWP\_NOZORDER | SWP\_NOACTIVATE); // move buttons by similar amount for (int i = 0; i < sizeof(\_PropSheetButtons) / sizeof (int); i++) { hWnd = ::GetDlgItem(m\_hWnd, \_PropSheetButtons\[i\]); if (hWnd != NULL) { ::GetWindowRect (hWnd, &rectOld); ScreenToClient (&rectOld); ::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (), SWP\_NOZORDER | SWP\_NOACTIVATE); } } CenterWindow (); return bResult;
}
BOOL CStepCreatorSheet::OnCommand(WPARAM wParam, LPARAM lParam)
{
// allow message map override
if (CWnd::OnCommand(wParam, lParam))
return TRUE;// crack message parameters UINT nID = LOWORD(wParam); HWND hWndCtrl = (HWND)lParam; int nCode = HIWORD(wParam); // set m\_nModalResult to ID of button, whenever button is clicked if (hWndCtrl != NULL && nCode == BN\_CLICKED) { if (::SendMessage(hWndCtrl, WM\_GETDLGCODE, 0, 0) & (DLGC\_BUTTON|DLGC\_DEFPUSHBUTTON)) { LONG lStyle = ::GetWindowLong(hWndCtrl, GW
If it works like a charm I wouldn't wotry more about it. Now seriously, your code seems fine to me. In fact you might consider doing a bunch with it and posting an article here at CP. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
If it works like a charm I wouldn't wotry more about it. Now seriously, your code seems fine to me. In fact you might consider doing a bunch with it and posting an article here at CP. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Hi Joaquín, Thanks for your reply. I asked this question, because I am not a GUI guru :(( . In fact, I have never needed such a thing and because of this I am just curious if I am in the right path or not. If I get confirmations from the professionals, I will surely post an article about this issue ;) . There are no articles about this, as far as i know. Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix
-
Hi Joaquín, Thanks for your reply. I asked this question, because I am not a GUI guru :(( . In fact, I have never needed such a thing and because of this I am just curious if I am in the right path or not. If I get confirmations from the professionals, I will surely post an article about this issue ;) . There are no articles about this, as far as i know. Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix
I agree, the code looks fine. This is a lot like the case where you have to hack out the OK/CANCEL buttons from a property sheet when you need the property sheet as just a simple control. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?