Click to See Complete Forum and Search --> : Tabs / Property sheets


links
October 14th, 2008, 10:40 AM
I'm trying to write a simple application with a dialog as main window containing one tab control with two tabs.

After struggling with the tab control I figured there must be an easier way and found Property sheets on MSDN. While they work great they don't seem to be all that flexible (e.g looks like you are stuck with the OK and Cancel buttons).

So I'm back to plain tabs. The property sheet concept did give me some ideas on how to handle multiple tabs, which is great since my previous approach was driving me insane. So I'm trying to mimick some property sheet functionality in my application.

1.PNG is what I now have and it is also what it should look like all the time. It consists of a modeless dialog box. The "Close"-button and the tab control are children of the dialog box. I have another dialog box (I used the PROPPAGE_LARGE for this) on which I put the static control and progress bar. I am however encountering some painting (that is what it looks like to me) issues. 2.PNG occurs sometimes when another window is opened which overlaps my dialog window. When I move my mouse around in the client area and over the controls the tabs and Close-button appear as in 3.PNG.

While trying to figure out whats wrong I noticed that when I call UpdateWindow(handle to PROPPAGE) after I created all my controls, the controls on the PROPPAGE dialog disappear as seen in 4 UpdateWnd.PNG.

Now I'm stuck. The only thing I can think of is that it is a paint issue or some window relationship thing which I have no idea how to resolve. Anyone have any ideas please?

kirants
October 14th, 2008, 12:56 PM
You aren't really stuck with OK and cancel. You could hide the OK button and rename the cancel to close. Just handle WM_INITDIALOG message in the page dialog procedures and do it one time. For example, if you refer to the example here:
http://www.codeguru.com/forum/showpost.php?p=1767394&postcount=12

and replace the DlgProc with something like this, you get what you want:

DLGPROC DlgProc( HWND hDlg,
UINT Msg,
WPARAM wParam,
LPARAM lParam
)
{
switch(Msg)
{
case WM_INITDIALOG:
{
HWND hWndSheet = GetParent(hDlg);
SetDlgItemText(hWndSheet,IDCANCEL,_T("Close"));
ShowWindow(GetDlgItem(hWndSheet,IDOK),SW_HIDE);
}
break;
default:
break;
}
return FALSE;
}


Note: You need to do this only one time.

links
October 14th, 2008, 02:54 PM
Thanks for the response. Looks like I need some more help with Property pages.

I've created one page and then I create the property sheet. I want the property sheet to be my main window.

1. In the PROPSHEETHEADER struct, what do I set the hwndParent to if the property sheet itself is supposed to be the parent?

2. Which window handle should I use in my message loop with IsDialogMessage()?

3. If I understand correctly, each page should have its own Dialog Procedure. What about the property sheet? How can I tie it to a Dialog Procedure?

In short my problem is that it looks to me as if the property sheet needs a parent window of some sort to handle messages?

kirants
October 14th, 2008, 03:07 PM
1. In the PROPSHEETHEADER struct, what do I set the hwndParent to if the property sheet itself is supposed to be the parent?
NULL
2. Which window handle should I use in my message loop with IsDialogMessage()?
Your best bet is to set a call back using PSH_USECALLBACK and in response to the PSCB_INITIALIZED message, subclass the hWnd passed in using SetWindowLong. Once done, you will start receiving messages to in this subclass proc. This is the part am unsure, i.e. if the subclass window procedure will receive a WM_INITDIALOG or not. But, if it does, you can set a global HWND variable to the hWNd passed into the subclass procedure in response to WM_INITDIALOG and pass this global HWND variable to IsDialogMessage. You would then handle WM_DESTROY and set the global HWND variable to NULL and not call IsDialogMessage anymore. ( If you do not get WM_INITDIALOG i..e it is too late, you can simply store the HWND passed into the callback function in PSCB_INITIALIZED case.
3. If I understand correctly, each page should have its own Dialog Procedure. What about the property sheet? How can I tie it to a Dialog Procedure?You don't need to tie the 2. See above to subclass the property sheet HWND.

links
October 15th, 2008, 07:51 AM
Thanks for your help. You've put me on the right path!