Discussion:
Help positioning a property sheet
(too old to reply)
Ron Hall
2004-08-23 10:42:16 UTC
Permalink
I'm stuck on what I would assume is a really easy thing to do. I have
created a modal property sheet to take advantage of the tabs and multiple
dialogs in a single window. However I want to position the dialog box at
the same place on the screen that the user placed it from before and I don't
seam to be able to do this without going to some ridiculous lengths. I have
tried using SetWindowPos from within the property sheet callback function
but with no luck. I have modified the template setting the x and y position
from within the callback function. It seams that I might have to put code
into each of the dialogs and use the window words so I can position it and
make it visible, this just seams way toooo hard for such a simple thing so I
believe I must be missing something, I've already spent way tooo much time
on time. Can someone help?

TIA
Ron
Christian ASTOR
2004-08-23 11:04:44 UTC
Permalink
Post by Ron Hall
I'm stuck on what I would assume is a really easy thing to do. I have
created a modal property sheet to take advantage of the tabs and multiple
dialogs in a single window. However I want to position the dialog box at
the same place on the screen that the user placed it from before
eg, PSCB_INITIALIZED, subclassing, PostMessage(), SetWindowPos()
Jussi Jumppanen
2004-08-31 15:07:32 UTC
Permalink
Post by Ron Hall
I'm stuck on what I would assume is a really easy thing to do.
I did not find it easy :(
Post by Ron Hall
I have created a modal property sheet to take advantage of
the tabs and multiple dialogs in a single window. However I
want to position the dialog box at the same place on the
screen that the user placed it from before and I don't seam
to be able to do this without going to some ridiculous lengths. I
In order to get my modal property sheets to behave I had to
use a message hook. See the code snippets with comments at the
end of this e-mail.

Jussi Jumppanen
Author of: Zeus for Windows (New version 3.93 out now)
"The C/C++, Cobol, Java, HTML, Python, PHP, Perl programmer's editor"
Home Page: http://www.zeusedit.com

////////////////
//Step (1)
//I needed a static "home grown" window class

//-- Just a little hack needed for my c++ frame work
static xPropertySheet *g_mSheet;

////////////////
//Step (2)
//I set a windows message hook to trap the creation of the
//property sheet

//-- needed to center property sheet
hhookCBTProc = SetWindowsHookEx(WH_CBT, xCBTMsgHook, 0,
GetCurrentThreadId());

//-- create the property sheet
int sResult = PropertySheet(&psh);

//-- release the hook after use
UnhookWindowsHookEx(hhookCBTProc);

//-- reset the callback technology
g_mSheet = 0;

////////////////
//Step (3)
//The callback hook traps the creation of the property sheet
LRESULT CALLBACK xCBTMsgHook(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HCBT_CREATEWND)
{
CREATESTRUCT *pcs = ((CBT_CREATEWND *)lParam)->lpcs;

if ((pcs->style & WS_DLGFRAME) || (pcs->style & WS_POPUP))
{
//-- look for a valid property sheet
if ((g_mSheet) && (g_mSheet->isValid() == 0))
{
HWND hwnd = (HWND)wParam;

//-- set the window handle
g_mSheet->hwndObj = hwnd;

//-- save the window pointer with in the window extra bits
SetWindowLong(hwnd, GWL_USERDATA, (LONG)g_mSheet);

/**** At this point you can subclass the window ****/

//-- subclass the window so that we can trap the WM_INITDIALOG
g_mSheet->subclass(xPropertySheetProc);
}
}
}

return (::CallNextHookEx(hhookCBTProc, nCode, wParam, lParam));
}

Loading...