Thread: property sheet kinda not working

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    416

    property sheet kinda not working

    I'm trying to create tabbed dialogs within the main window. Originally I just had dialogs be the window itself, but then it eliminated the minimize, maximize and close button in the corner. So I would like to transfer them all to a tabbed dialogs using property sheets. But the problem is when the program is compiled, the program doesn't run, even though it compiles with no errors. I don't know what is happening with the program since there's no errors, or no program for that matter. Here is the code containing the property sheets.

    Code:
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_CREATE:
                PROPSHEETPAGE std;
    
                std.dwSize = sizeof(PROPSHEETPAGE);
                std.dwFlags = PSP_DEFAULT;
                std.pszTemplate = MAKEINTRESOURCE(IDD_MAIN);
                std.pfnDlgProc = DlgProc;
    
                HPROPSHEETPAGE ahstd = CreatePropertySheetPage(&std);
    
                PROPSHEETHEADER hstd;
                hstd.dwSize = sizeof(PROPSHEETHEADER);
                hstd.dwFlags = PSP_DEFAULT|PSH_MODELESS;
                hstd.hwndParent = hwnd;
                hstd.pszCaption = "Standard";
                hstd.phpage = &ahstd;
    
                PropertySheet(&hstd);
                break;
    
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }

  2. #2
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    I've never properly implemented prop sheets before, but from what I can tell, there seems to be a few general errors in the above code. For starters, prop sheet cannot create the page from the IDD_MAIN template in your exe if it does not have a handle to it first (psp.hInstance). There may be other errors, along with the fact that property sheets can only be used in version 6 controls (i.e. 2000, XP and above). As well, naming a variable "hstd" that is not actually a handle will quickly get you into confusing situations when using winAPI's hungarian notation which uses the prefix "h" to denote "handle to".

    The reason why I've never fully implemented property sheets (aside from them being version 6 dependant) is that generally, I find using child windows to be equally as good, if not better. You may want to look into using them to contain each subset of controls you want to place on each "page", then simply show/hide them as the user switches tabs.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Ok so after messing with it some more I don't understand what's happening. I would like to use tabs/property sheets since it would look a little tidier than child windows. I added the hInstance with the instance of the main window, and it still is not working correctly. Am I overlooking something simple or is this just confusing?

    EDIT: it still compiles, but does not open the window when ran.

    Code:
    case WM_CREATE:
                PROPSHEETPAGE std;
                HINSTANCE hdlg;
    
                std.dwSize = sizeof(PROPSHEETPAGE);
                std.dwFlags = PSP_DEFAULT|PSH_MODELESS;
                std.pszTemplate = MAKEINTRESOURCE(ELECTRICAL);
                std.pfnDlgProc = DlgProc;
                std.hInstance = hInstance;
    
                HPROPSHEETPAGE ahstd[1];
                ahstd[0] = CreatePropertySheetPage(&std);
    
                PROPSHEETHEADER hstd;//, hohm;
                hstd.dwSize = sizeof(PROPSHEETHEADER);
                hstd.dwFlags = PSP_DEFAULT|PSH_MODELESS;
                hstd.hwndParent = hwnd;
                hstd.pszCaption = "Standard";
                hstd.phpage = ahstd;
                hstd.hInstance = hdlg;
                hstd.nStartPage = 0;
                hstd.nPages = 1;
    
                //ZeroMemory(NULL, hstd, sizeof(PROPSHEETHEADER)); (dont know if
                // this should be left here or not)
                PropertySheet(&hstd);
    
                break;
    Last edited by scwizzo; 10-08-2007 at 06:22 PM.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    hdlg isn't initialized. Try the following.

    Code:
    case WM_CREATE:
                HINSTANCE hdlg;
               //hstd.hInstance = hdlg
                hstd.hInstance = hInstance;
               
                break;
    ;

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    I think i jumped in to the deep end... again. It still doesn't work with both PROPSHEETPAGE and PROPSHEETHEADER hInstances as hInstance instead of hdlg. Earlier in the code under WinMain() I have

    Code:
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    {
        HWND hwnd;            /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        hInstance = hThisInstance;
    So that is where hInstance is coming from (it's a global variable).

    I don't get why the compiler returns no error and doesn't run the program. Or maybe it is running and something is wrong and closes before it even really opens? Anyone have an example I can go off of? I've searched MSDN, this board, and some others and it seems like no one has any examples.
    Last edited by scwizzo; 10-09-2007 at 10:29 AM.

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Anyone have an example I can go off of?
    Code:
    // Resource.h
    //{{NO_DEPENDENCIES}}
    // Microsoft Developer Studio generated include file.
    // Used by PROPERTY.RC
    //
    #define IDR_MAIN_MENU                   101
    #define IDD_BUTTONS                     102
    #define IDD_COMBOBOXES                  103
    #define IDC_BUTTON2                     1001
    #define IDC_RADIO1                      1002
    #define IDC_RADIO2                      1003
    #define IDC_RADIO3                      1004
    #define IDC_CHECK1                      1005
    #define IDC_CHECK2                      1006
    #define IDC_CHECK3                      1007
    #define IDC_COMBO1                      1008
    #define IDC_COMBO2                      1009
    #define IDC_COMBO3                      1010
    #define IDM_EXIT                        2001
    #define IDM_PROPERTYSHEET               2002
    #define IDC_STATIC                      -1
    
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NO_MFC                     1
    #define _APS_NEXT_RESOURCE_VALUE        107
    #define _APS_NEXT_COMMAND_VALUE         2006
    #define _APS_NEXT_CONTROL_VALUE         1015
    #define _APS_NEXT_SYMED_VALUE           101
    #endif
    #endif
    Code:
    #pragma comment( lib, "user32.lib" ) 
    #pragma comment( lib, "comctl32.lib" ) 
    
    #include <windows.h>
    #include "resource.h"
    
    BOOL           InitApplication(HINSTANCE);
    BOOL           InitInstance(HINSTANCE, int);
    LRESULT CALLBACK  MainWndProc(HWND, UINT, WPARAM, LPARAM);
    int            CreatePropertySheet(HWND);
    LRESULT CALLBACK  ButtonsDlgProc(HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK  ComboDlgProc(HWND, UINT, WPARAM, LPARAM);
    void CALLBACK  PropSheetCallback(HWND, UINT, LPARAM);
    
    HINSTANCE   g_hInst;
    HWND        g_hwndPropSheet,g_hwndMain;
    TCHAR       g_szClassName[] = TEXT("PropSheetClass");
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
    	MSG      msg;
    	g_hInst = hInstance;
    	if(!hPrevInstance)
    		if(!InitApplication(hInstance))
    			return FALSE;
    
    	if (!InitInstance(hInstance, nCmdShow))
    		return FALSE;
    
    	while(GetMessage(&msg, NULL, 0x00, 0x00))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    
    
    BOOL InitApplication(HINSTANCE hInstance)
    {
    
    	WNDCLASSEX  wcex;
    
    	ZeroMemory(&wcex, sizeof(wcex));
    
    	wcex.cbSize          = sizeof(wcex);
    	wcex.style           = CS_HREDRAW | CS_VREDRAW;
    	wcex.lpfnWndProc     = (WNDPROC)MainWndProc;
    	wcex.cbClsExtra      = 0;
    	wcex.cbWndExtra      = 0;
    	wcex.hInstance       = hInstance;
    	wcex.hIcon           = LoadIcon(NULL, IDI_APPLICATION);
    	wcex.hCursor         = LoadCursor(NULL, IDC_ARROW);
    	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    	wcex.lpszMenuName    = MAKEINTRESOURCE(IDR_MAIN_MENU);
    	wcex.lpszClassName   = g_szClassName;
    
    	return RegisterClassEx(&wcex);
    }
    
    
    BOOL InitInstance(   HINSTANCE hInstance,
    	int nCmdShow)
    {
    	g_hwndMain = CreateWindowEx(  0,
    		g_szClassName,
    		TEXT("Property Sheet"),
    		WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		NULL,
    		NULL,
    		hInstance,
    		NULL);
    
    	if (!g_hwndMain)
    	{
    		return FALSE;
    	}
    	ShowWindow(g_hwndMain, nCmdShow);
    	UpdateWindow(g_hwndMain);
    	return TRUE;
    }
    
    
    LRESULT CALLBACK MainWndProc( HWND hWnd,
    	UINT uMessage,
    	WPARAM wParam,
    	LPARAM lParam)
    {
    	switch (uMessage)
    	{
    		case WM_CREATE:
    			break;
    
    		case WM_CLOSE:
    			if(IsWindow(g_hwndPropSheet))
    				DestroyWindow(g_hwndPropSheet);
    
    			DestroyWindow(hWnd);
    			break;
    
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    
    		case WM_COMMAND:
    			switch(wParam)
    			{
    				case IDM_PROPERTYSHEET:
    					CreatePropertySheet(hWnd);
    					break;
    
    				case IDM_EXIT:
    					PostMessage(hWnd, WM_CLOSE, 0, 0);
    					break;
    
    			}
    			return TRUE;
    
    		default:
    			break;
    	}
    	return DefWindowProc(hWnd, uMessage, wParam, lParam);
    }
    
    
    int CreatePropertySheet(HWND hwndOwner)
    {
    	PROPSHEETPAGE psp[2];
    	PROPSHEETHEADER psh;
    
    	psp[0].dwSize        = sizeof(PROPSHEETPAGE);
    	psp[0].dwFlags       = PSP_USETITLE;
    	psp[0].hInstance     = g_hInst;
    	psp[0].pszTemplate   = MAKEINTRESOURCE(IDD_BUTTONS);
    	psp[0].pszIcon       = NULL;
    	psp[0].pfnDlgProc    = (DLGPROC)ButtonsDlgProc;
    	psp[0].pszTitle      = TEXT("Buttons");
    	psp[0].lParam        = 0;
    
    	psp[1].dwSize        = sizeof(PROPSHEETPAGE);
    	psp[1].dwFlags       = PSP_USETITLE;
    	psp[1].hInstance     = g_hInst;
    	psp[1].pszTemplate   = MAKEINTRESOURCE(IDD_COMBOBOXES);
    	psp[1].pszIcon       = NULL;
    	psp[1].pfnDlgProc    = (DLGPROC) ComboDlgProc;
    	psp[1].pszTitle      = TEXT("Combo Boxes");
    	psp[1].lParam        = 0;
    
    	psh.dwSize           = sizeof(PROPSHEETHEADER);
    	psh.dwFlags          = PSH_PROPSHEETPAGE |  PSH_USECALLBACK;
    	psh.hwndParent       = hwndOwner;
    	psh.hInstance        = g_hInst;
    
    	psh.pszCaption       = TEXT("My Property Sheet");
    	psh.nPages           = sizeof(psp) / sizeof(PROPSHEETPAGE);
    	psh.ppsp             = (LPCPROPSHEETPAGE) &psp;
    	psh.pfnCallback      = (PFNPROPSHEETCALLBACK)PropSheetCallback;
    
    	return PropertySheet(&psh);
    }
    
    
    LRESULT CALLBACK ButtonsDlgProc( HWND hdlg,
    	UINT uMessage,
    	WPARAM wParam,
    	LPARAM lParam)
    {
    	LPNMHDR     lpnmhdr;
    
    	switch (uMessage)
    	{
    		case WM_COMMAND:
    			PropSheet_Changed(GetParent(hdlg), hdlg);
    			break;
    
    		case WM_NOTIFY:
    			lpnmhdr = (NMHDR FAR *)lParam;
    
    			switch (lpnmhdr->code)
    			{
    				case PSN_APPLY:   //sent when OK or Apply button pressed
    					break;
    
    				case PSN_RESET:   //sent when Cancel button pressed
    					break;
    
    				case PSN_SETACTIVE:
    					//this will be ignored if the property sheet is not a wizard
    					PropSheet_SetWizButtons(GetParent(hdlg), PSWIZB_NEXT);
    					break;
    				default:
    					break;
    			}
    			break;
    		default:
    			break;
    	}
    	return FALSE;
    }
    
    
    LRESULT CALLBACK ComboDlgProc(   HWND hdlg,
    	UINT uMessage,
    	WPARAM wParam,
    	LPARAM lParam)
    {
    	LPNMHDR     lpnmhdr;
    
    	switch (uMessage)
    	{
    		case WM_COMMAND:
    			PropSheet_Changed(GetParent(hdlg), hdlg);
    			break;
    
    		case WM_NOTIFY:
    			lpnmhdr = (NMHDR FAR *)lParam;
    
    			switch (lpnmhdr->code)
    			{
    				case PSN_APPLY:   //sent when OK or Apply button pressed
    					break;
    
    				case PSN_RESET:   //sent when Cancel button pressed
    					break;
    
    				case PSN_SETACTIVE:
    					//this will be ignored if the property sheet is not a wizard
    					PropSheet_SetWizButtons(GetParent(hdlg), PSWIZB_BACK | PSWIZB_FINISH);
    					return FALSE;
    
    				default:
    					break;
    			}
    			break;
    
    		default:
    			break;
    	}
    
    	return FALSE;
    }
    
    
    void CALLBACK PropSheetCallback(HWND hwndPropSheet, UINT uMsg, LPARAM lParam)
    {
    	switch(uMsg)
    	{
    			//called before the dialog is created, hwndPropSheet = NULL, lParam points to dialog resource
    		case PSCB_PRECREATE:
    			{
    				LPDLGTEMPLATE  lpTemplate = (LPDLGTEMPLATE)lParam;
    
    				if(!(lpTemplate->style & WS_SYSMENU))
    				{
    					lpTemplate->style |= WS_SYSMENU;
    				}
    			}
    			break;
    			//called after the dialog is created
    		case PSCB_INITIALIZED:
    			break;
    
    	}
    }
    Code:
    //Microsoft Developer Studio generated resource script.
    //
    #include "resource.h"
    
    #define APSTUDIO_READONLY_SYMBOLS
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include <windows.h>
    /////////////////////////////////////////////////////////////////////////////
    #undef APSTUDIO_READONLY_SYMBOLS
    
    /////////////////////////////////////////////////////////////////////////////
    // English (U.S.) resources
    
    #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
    #ifdef _WIN32
    LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
    #pragma code_page(1252)
    #endif //_WIN32
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Dialog
    //
    
    IDD_BUTTONS DIALOG DISCARDABLE  0, 0, 206, 70
    STYLE WS_CHILD | WS_VISIBLE | WS_BORDER
    FONT 8, "MS Sans Serif"
    BEGIN
        GROUPBOX        "Pushbuttons",IDC_STATIC,5,5,60,60
        PUSHBUTTON      "Pushbutton",IDC_BUTTON2,10,20,49,14
        GROUPBOX        "Radio Buttons",IDC_STATIC,70,5,60,60
        CONTROL         "Radio1",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON | 
                        WS_GROUP,75,20,50,10
        CONTROL         "Radio2",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,75,36,50,
                        10
        CONTROL         "Radio3",IDC_RADIO3,"Button",BS_AUTORADIOBUTTON,75,50,50,
                        10
        GROUPBOX        "Check Boxes",IDC_STATIC,135,5,60,60
        CONTROL         "Check1",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | 
                        WS_TABSTOP,140,20,50,10
        CONTROL         "Check2",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | 
                        WS_TABSTOP,140,36,50,10
        CONTROL         "Check3",IDC_CHECK3,"Button",BS_AUTOCHECKBOX | 
                        WS_TABSTOP,140,50,50,10
    END
    
    IDD_COMBOBOXES DIALOG DISCARDABLE  0, 0, 230, 94
    STYLE WS_CHILD | WS_VISIBLE | WS_BORDER
    FONT 8, "MS Sans Serif"
    BEGIN
        COMBOBOX        IDC_COMBO1,10,15,60,70,CBS_SIMPLE | CBS_SORT | 
                        WS_VSCROLL | WS_TABSTOP
        GROUPBOX        "Simple",IDC_STATIC,5,0,70,90
        COMBOBOX        IDC_COMBO2,85,15,60,75,CBS_DROPDOWN | CBS_SORT | 
                        WS_VSCROLL | WS_TABSTOP
        GROUPBOX        "Drop Down",IDC_STATIC,80,0,70,90
        COMBOBOX        IDC_COMBO3,160,15,60,75,CBS_DROPDOWNLIST | CBS_SORT | 
                        WS_VSCROLL | WS_TABSTOP
        GROUPBOX        "Drop List",IDC_STATIC,155,0,70,90
    END
    
    
    #ifdef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // TEXTINCLUDE
    //
    
    1 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "resource.h\0"
    END
    
    2 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "#include <winuser.h>\0"
    END
    
    3 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "\r\n"
        "\0"
    END
    
    #endif    // APSTUDIO_INVOKED
    
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Menu
    //
    
    IDR_MAIN_MENU MENU DISCARDABLE 
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM SEPARATOR
            MENUITEM "E&xit",                       IDM_EXIT
        END
        POPUP "&Test Property Sheet"
        BEGIN
            MENUITEM "My Property Sheet",           IDM_PROPERTYSHEET
        END
    END
    
    #endif    // English (U.S.) resources
    /////////////////////////////////////////////////////////////////////////////
    
    
    
    #ifndef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 3 resource.
    //
    
    
    /////////////////////////////////////////////////////////////////////////////
    #endif    // not APSTUDIO_INVOKED

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    guess who feels dumb...

    i didn't link comctl32 with the project...

    That example did help though! Thank you BobS0327

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. static property
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-12-2008, 01:03 AM
  2. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  3. C++/CLI Property
    By psychopath in forum Windows Programming
    Replies: 5
    Last Post: 07-11-2006, 09:45 PM
  4. working out...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 04-10-2003, 10:20 AM
  5. Property Sheets :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 05-09-2002, 03:04 PM