Thread: WinApi - Property Sheets

  1. #1
    Unregistered
    Guest

    WinApi - Property Sheets

    Note: Property Sheets(say ps)

    I have seen examples in CodeGuru(Propert Sheet in Dialog article) with MFC. Those examples can create Property Sheets in a dialog or formview as child controls. Surely, somebody(s) here was(were) tried that himself/herself too. Whatsoever, I tried to do this in WinApi. Unfortunatly couldn't yet. In fact, not sure, is it possible via APIs. Is anybody tried? Or at least, may say that is possible(and not too hard). Or (many or...), can I designate Property Sheet(ps) window properties, such WS_CHILD etc. Since, ::Create method has ability to give such properties to ps etc.
    In fact, I created a form and a child frame, as run time. Then designate the ps as modeless and set the frame as parent to ps. At last, I have a ps in that frame(place holder) like child control(or picture). But, I failed to;

    1. tabbing through ps and also other controls outside the ps(on main form controls).
    2. slip out the ps header and borders.

    Is this possible? Or anybody seen an example anywhere?

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    Here is an example I downloaded a while ago. I never got around to learning how it works exactly, but I have attached the zip for you to see.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Unregistered
    Guest
    Big Thanks,

    I'll look in. Hope what I learn.

    Regards

  4. #4
    Unregistered
    Guest
    Unfortunatly that source codes, doesn't fit my needs. Now I can hide (modeless)propsheet's header bar. But I already couldn't tab-stop propsheet to main form. This is hardest part. Because, propsheet is already not a control(child), just seems so. Does anybody know a trick(or tweak), can be tab-stop through (modeless)propsheet to main form, than back etc.

  5. #5
    Unregistered
    Guest
    In this code, many of the portions are belongs to BCX(Basic to C) programs sample. I changed, added and removed
    some of the parts. This code successfully compiles via LCC-win32 compiler. If somebody interests and solves
    some problems, please inform me. ([email protected])
    problems:
    The propsheet is seems like a child control but not really a child. If compile, you can see that
    if propsheet has focused, tab-stops can not back to main form controls. Both propseet and main form must has
    the same message queue etc. Clearly, my goal was designing the propsheet like a TabControl on the form(or dialog).
    Right now only seems so but not really.

    (btw, I know how to create and use tabcontrol, this is a different goal)

    Have a nice day.

    Code:
    #include <windows.h>    
    #include <windowsx.h>   
    #include <commctrl.h>   
    #include <stdio.h>
    #include <string.h>
    
    #define PS_PAGES 3
    #define ID_BUTTON1 111
    #define IDD_PEOPLE 1001
    #define IDD_ANIMAL 1002
    #define IDD_BUILDING 1003
    #define IDM_EXIT 104
    #define IDM_ABOUT 300
    
    static  HWND   Form1;
    static  HWND   Button1;
    static  char   AppName[20];
    static  HWND   hInstance;
    static  PROPSHEETPAGE  psp[PS_PAGES];
    static  PROPSHEETHEADER  psh;
    static  HWND   hWndPropCtrl;
    static  HWND   hWndPicture;
    static  RECT   btmrect;
    static  DWORD  width;
    static  DWORD  height;
    
    
    int     WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    void    FormLoad (HWND);
    int     FindFirstInstance (char *);
    HWND    CreatePropSheet (HWND);
    LRESULT CALLBACK PropSheetProc (HWND, UINT, WPARAM, LPARAM);
    
    
    int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int CmdShow)
    {
    	static  MSG  Msg;
    	memset(&Msg,0,sizeof(Msg));
    	static  WNDCLASS  wc;
    	memset(&wc,0,sizeof(wc));
    	hInstance=hInst;
    	strcpy(AppName,"PropSheetDemo");
    	if(FindFirstInstance(AppName))
    	{
    		return 0;
    	}
    	wc.style=0;
    	wc.lpfnWndProc=WndProc;
    	wc.cbClsExtra=0;
    	wc.cbWndExtra=0;
    	wc.hInstance=hInst;
    	wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
    	wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    	wc.hbrBackground=GetSysColorBrush(COLOR_BTNFACE);
    	wc.lpszClassName=AppName;
    	RegisterClass(&wc);
    	FormLoad(hInst);
    	while(GetMessage(&Msg,NULL,0,0))
    	{
    		if(!IsDialogMessage(Form1,&Msg))
    		{
    			if(!PropSheet_IsDialogMessage(hWndPropCtrl,&Msg))
    			{
    				TranslateMessage(&Msg);
    				DispatchMessage(&Msg);
    			}
    		}
    	}
    	return Msg.wParam;
    }
    
    
    LRESULT CALLBACK WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(Msg)
    	{
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{
    				case ID_BUTTON1:
    					break;
    				case IDM_EXIT:
    					PostQuitMessage(0);
    					break;
    			}
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			return 0;
    	}
    	return DefWindowProc(hWnd,Msg,wParam,lParam);
    }
    
    
    void FormLoad (HWND hInst)
    {
    	Form1=CreateWindow(AppName,"Main Window",WS_OVERLAPPEDWINDOW,100,100,500,400,NULL,(HMENU)NULL,hInst,NULL);
    	Button1=CreateWindowEx(0,"button","Button1",WS_CHILD|WS_TABSTOP|BS_PUSHBUTTON|WS_VISIBLE,399,1,70,30,Form1,(HMENU)ID_BUTTON1,hInst,NULL);
    	hWndPicture=CreateWindowEx(0,"static","",WS_CHILD|WS_TABSTOP|WS_VISIBLE,5,5,360,310,Form1,NULL,hInst,NULL);
    	
    	GetWindowRect(hWndPicture,&btmrect);	
    	width=btmrect.right - btmrect.left;
    	height=btmrect.bottom - btmrect.top;
    
    	SendMessage(Button1,(UINT)WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),(LPARAM)MAKELPARAM(FALSE,0));
    	UpdateWindow(Form1);
    	ShowWindow(Form1,SW_SHOWNORMAL);
    	hWndPropCtrl=CreatePropSheet(Form1);
    
    	SetParent(hWndPropCtrl,hWndPicture);
    	SetWindowPos(hWndPropCtrl,NULL,-5,-25,width+15,height+40,SWP_NOZORDER|SWP_NOACTIVATE);
    //	SetWindowLong(hWndPropCtrl, GWL_STYLE,GetWindowLong(hWndPropCtrl,GWL_STYLE)|WS_CHILD);
    //	SetWindowLong(hWndPicture, GWL_EXSTYLE,GetWindowLong(hWndPicture,GWL_EXSTYLE)|WS_EX_CONTROLPARENT);
    }
    
    int FindFirstInstance (char *ApplName)
    {
    	static  HWND  hWnd;
    	memset(&hWnd,0,sizeof(hWnd));
    	hWnd=FindWindow(ApplName,NULL);
    	if(hWnd)
    	{
    		return TRUE;
    	}
    	return FALSE;
    }
    
    HWND CreatePropSheet (HWND hWndParent)
    {
    	psp[0].dwSize=sizeof(PROPSHEETPAGE);
    	psp[0].dwFlags=0;
    	psp[0].hInstance=hInstance;
    	psp[0].pszTemplate=MAKEINTRESOURCE(IDD_PEOPLE);
    	psp[0].pfnDlgProc=(DLGPROC)PropSheetProc;
    	psp[0].pszTitle="?????";
    	psp[0].lParam=0;
    	psp[0].pfnCallback=NULL;
    
    	psp[1].dwSize=sizeof(PROPSHEETPAGE);
    	psp[1].dwFlags=PSP_USETITLE;
    	psp[1].hInstance=hInstance;
    	psp[1].pszTemplate=MAKEINTRESOURCE(IDD_ANIMAL);
    	psp[1].pfnDlgProc=(DLGPROC)PropSheetProc;
    	psp[1].pszTitle="Animals";
    	psp[1].lParam=0;
    	psp[1].pfnCallback=NULL;
    
    	psp[2].dwSize=sizeof(PROPSHEETPAGE);
    	psp[2].dwFlags=PSP_USETITLE;
    	psp[2].hInstance=hInstance;
    	psp[2].pszTemplate=MAKEINTRESOURCE(IDD_BUILDING);
    	psp[2].pfnDlgProc=(DLGPROC)PropSheetProc;
    	psp[2].pszTitle="Buildings";
    	psp[2].lParam=0;
    	psp[2].pfnCallback=NULL;
    
    	psh.dwSize=sizeof(PROPSHEETHEADER);
    	psh.dwFlags=PSH_PROPSHEETPAGE|PSH_NOAPPLYNOW|PSH_MODELESS;
    	psh.hwndParent=Form1;
    	psh.hInstance=hInstance;
    	psh.pszIcon=NULL;
    	psh.pszCaption=NULL;
    	psh.nPages=sizeof(psp)/sizeof(PROPSHEETPAGE);
    	psh.nStartPage=0;
    	psh.ppsp=(LPCPROPSHEETPAGE)&psp;
    	psh.pfnCallback=NULL;
    
    
    	return (HWND)PropertySheet(&psh);
    }
    
    LRESULT CALLBACK PropSheetProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {	
    
    	switch(Msg)
    	{
    		case WM_INITDIALOG:
    
    			ShowWindow(GetDlgItem(GetParent(hWnd),IDOK),SW_HIDE);
    			ShowWindow(GetDlgItem(GetParent(hWnd),IDCANCEL),SW_HIDE);
    //			SetWindowLong(GetParent(hWnd), GWL_STYLE,GetWindowLong(GetParent(hWnd),GWL_STYLE)|WS_CHILD);
    //			SetWindowLong(GetParent(hWnd), GWL_STYLE,WS_DLGFRAME);
    		
    			return 1;
    		case WM_NOTIFY:
    			switch(((LPNMHDR)lParam)->code)
    			{
    				case PSN_SETACTIVE:
    					break;
    				case PSN_RESET:
    					break;
    				case PSN_QUERYCANCEL:
    					break;
    				case PSN_KILLACTIVE:
    					break;
    			}
    			break;
    		case WM_COMMAND:
    			break;
    	}
    	return DefWindowProc(hWnd,Msg,wParam,lParam);
    }
    -------------------------------Propsht.Rc-------------------------------------------
    #include <windows.h>
    
    1001 DIALOG 0, 0, 80, 134
    STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
    CAPTION "PEOPLE"
    FONT 8, "MS Sans Serif"
    BEGIN
        AUTOCHECKBOX    "male",     201, 10, 10, 80, 10
        AUTOCHECKBOX    "female",   202, 10, 20, 80, 10
        AUTOCHECKBOX    "children", 203, 10, 30, 80, 10
        LTEXT           "Note: this page has no HELP button", 204, 10, 60, 200, 12
    END
    
    1002 DIALOG 0, 0, 80, 134
    STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
    CAPTION "ANIMALS"
    FONT 8, "MS Sans Serif"
    BEGIN
        AUTOCHECKBOX    "cat"  , 211, 50, 50, 80, 10
        AUTOCHECKBOX    "dog"  , 212, 50, 60, 80, 10
        AUTOCHECKBOX    "horse", 213, 50, 70, 80, 10
        LTEXT           "Note: on this page HELP works", 213, 50, 100, 200, 12
    END
    
    1003 DIALOG 0, 0, 80, 134
    STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
    CAPTION "BUILDINGS"
    FONT 8, "MS Sans Serif"
    BEGIN
        AUTOCHECKBOX    "house"    , 221, 50, 100, 80, 10
        AUTOCHECKBOX    "garage"   , 222, 50, 110, 80, 10
        AUTOCHECKBOX    "dog house", 223, 50, 120, 80, 10
    END
    ---------------------------------build.bat-----------------------------------------------------
    @echo off
    lrc propsht
    bc  propsht
    lw  propsht propsht.res

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Closing Property Sheets - PSM_GETCURRENTPAGEHWND Test
    By Tonto in forum Windows Programming
    Replies: 1
    Last Post: 05-07-2007, 07:22 AM
  2. Property Sheets
    By rEtard in forum Windows Programming
    Replies: 8
    Last Post: 07-22-2005, 09:34 AM
  3. tabs VS property sheets
    By axr0284 in forum Windows Programming
    Replies: 7
    Last Post: 01-11-2005, 01:49 AM
  4. add menu to property sheets
    By ZeroG in forum Windows Programming
    Replies: 1
    Last Post: 09-25-2004, 08:50 PM
  5. Property Sheets :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 05-09-2002, 03:04 PM