Click to See Complete Forum and Search --> : PropertySheet Embedding Problem


ludvig.peers
July 15th, 2010, 07:23 AM
Hi all!

I am facing a problem when embedding a propertysheet in my main dialog box. I have use the CreateWindow() function to create my main dialog box and two PUSHBUTTONS, which work just fine but when I include the propertysheet as a child on top of the dialog box the buttons do not work.
I believe it has something to do with the handles but no luck yet. If there are any suggestions on what I should check, it would be greatly appreciated!

Ludvig

P.S. I have not included any code, but if anyone wants to check it, I will be more than happy to provide it!

hoxsiew
July 15th, 2010, 08:00 AM
What do you mean by propertysheet? This isn't a standard window. There is CPropertySheet in MFC but that is derived from CDialog and is a popup window and would be difficult at best to embed into another dialog as a child window. For a property-sheet like effect, use a tab control.

ovidiucucu
July 15th, 2010, 08:01 AM
P.S. I have not included any code, but if anyone wants to check it, I will be more than happy to provide it!
Should be useful. Otherwise we can only guess.

ovidiucucu
July 15th, 2010, 08:15 AM
@to hoxsiew:

CPropertySheet isn't derived from CDialog but from CWnd.
CPropertySheet wraps a Windows Property Sheet, let's say it "standard window". See: Property Sheet (http://msdn.microsoft.com/en-us/library/bb774540(v=VS.85).aspx) in MSDN.
Can be child with no problem in any other parent window.

ludvig.peers
July 15th, 2010, 08:19 AM
I am using the propertysheet sutructures in WIN API.
About Property Sheets (http://msdn.microsoft.com/en-us/library/bb774538(v=VS.85).aspx)

I have created the dialog box and the two buttons in InitInstance



BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
g_hInst = hInstance; // Store instance handle in our global variable

//Handle to main dialog box
g_hwndMain = CreateWindowEx(NULL, g_szWindowClass, g_szTitle, WS_OVERLAPPED | WS_SYSMENU,
GetSystemMetrics(SM_CXSCREEN)/2-253, GetSystemMetrics(SM_CYSCREEN)/2-205, 506, 410, NULL, NULL, hInstance, NULL); //change size

//Handle to Send Button
g_hwndSendButton = CreateWindow(
"BUTTON", /* this makes a "button" */
"SEND", /* this is the text which will appear in the button */
BS_PUSHBUTTON |WS_VISIBLE | WS_CHILD ,
409, /* these four lines are the position and dimensions of the button */
310,
85,
26,
g_hwndMain, /* this is the buttons parent window */
(HMENU)IDC_SEND, /* these next two lines tell windows what to do when the button is pressed */
g_hInst,
NULL);

//Handle to Read Button
g_hwndReadButton = CreateWindow(
"BUTTON",
"READ",
BS_PUSHBUTTON |WS_VISIBLE | WS_CHILD,
320,
310,
85,
26,
g_hwndMain,
(HMENU)IDC_READ,
g_hInst,
NULL);

if (!g_hwndMain)
{
return FALSE;
}

g_hwndPropSheet = CreatePropSheet();

if(-1 == (int)g_hwndPropSheet)
{
return -1;
}

SetWindowLongPtr(g_hwndPropSheet, GWL_STYLE, WS_CHILD);
SetParent(g_hwndPropSheet, g_hwndMain);
SetWindowLongPtr(g_hwndPropSheet, GWL_EXSTYLE, WS_EX_CONTROLPARENT);

InitPPSheetSize();

ShowWindow(g_hwndMain, nCmdShow);
UpdateWindow(g_hwndMain);

return TRUE;
}


This is a modification on a code that I found here in codeguru:
http://www.codeguru.com/forum/showthread.php?t=323943

The function InitPPSheetSize(); that I call in InitInstance contains:


void InitPPSheetSize()
{
RECT rectWnd;
RECT rectButton;

GetWindowRect(g_hwndPropSheet, &rectWnd);
HWND hWnd = ::GetDlgItem(g_hwndPropSheet, IDOK);

if(!hWnd)
{
DebugBreak();
}

GetWindowRect(hWnd, &rectButton); //::

SetWindowPos(g_hwndPropSheet, NULL,30,10,
rectWnd.right - rectWnd.left, rectButton.top - rectWnd.top,
SWP_SHOWWINDOW);

for (int i = 0; i < _ArrCount(PropSheetButtons); i++)
{
hWnd = ::GetDlgItem(g_hwndPropSheet, PropSheetButtons[i]);
if (hWnd != NULL)
{
ShowWindow(hWnd, SW_HIDE); //::
EnableWindow(hWnd, FALSE); //::
}
}
}


I wanted two general buttons 'send' and 'read' for the three tabs that I have in my propertysheet, so I thought I would include them as childs in my main dialog box. Should I just use the default buttons 'OK' and 'Cancel' that are provided by the propertysheet() function and just rename them accordingly? Any ideas would be more than welcome!

Ludvig

P.S. I apologize but I am a bit new to C++ and WIN API.