CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2010
    Posts
    6

    PropertySheet Embedding Problem

    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!

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: PropertySheet Embedding Problem

    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.

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: PropertySheet Embedding Problem

    Quote Originally Posted by ludvig.peers View Post
    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: PropertySheet Embedding Problem

    @to hoxsiew:
    1. CPropertySheet isn't derived from CDialog but from CWnd.
    2. CPropertySheet wraps a Windows Property Sheet, let's say it "standard window". See: Property Sheet in MSDN.
    3. Can be child with no problem in any other parent window.
    Last edited by ovidiucucu; July 15th, 2010 at 08:19 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Jul 2010
    Posts
    6

    Re: PropertySheet Embedding Problem

    I am using the propertysheet sutructures in WIN API.
    About Property Sheets

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

    Code:
    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:

    Code:
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured