Code:
// *************************************************************
// Created with BCX -- The BASIC To C Translator (ver 2.85)
// BCX (c) 1999, 2000, 2001, 2002 by Kevin Diggins
// *************************************************************
#include <windows.h> // Win32 Header File
#include <windowsx.h> // Win32 Header File
#include <commctrl.h> // Win32 Header File
#include <mmsystem.h> // Win32 Header File
#include <stdio.h>
#include <string.h>
#include <prsht.h>
// *************************************************
// User Defined Constants
// *************************************************
#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
#define IC_PEOPLE 10001
#define IC_ANIMAL 10002
#define IC_BUILDING 10003
// *************************************************
// System Variables
// *************************************************
char BCX_STR [1024*1024];
// *************************************************
// User Global Variables
// *************************************************
static HWND Form1;
static HWND Button1;
static char AppName[2048];
static char Caption[2048];
static HINSTANCE hInstance;
static PROPSHEETPAGE psp[PS_PAGES];
static PROPSHEETHEADER psh;
static HWND hWndPropCtrl;
// *************************************************
// Standard Prototypes
// *************************************************
char* BCX_TmpStr(size_t);
char* str (double);
// *************************************************
// User's Prototypes
// *************************************************
int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
void FormLoad (HINSTANCE);
int FindFirstInstance (char *);
int CreatePropSheet (HWND);
LRESULT CALLBACK PropSheetProc (HWND, UINT, WPARAM, LPARAM);
// Demonstrates use of Property Sheet
// written by Jef Rozenski
// *************************************************
// Run Time Functions
// *************************************************
char *BCX_TmpStr (size_t Bites)
{
static int StrCnt;
static char *StrFunc [64];
StrCnt = (StrCnt + 1) & 63;
free (StrFunc[StrCnt]);
return StrFunc[StrCnt] = (char*)calloc(Bites + 256, 1);
}
char *str (double d)
{
char *strtmp;
strtmp = BCX_TmpStr(2048);
sprintf(strtmp,"% .16g",d);
return strtmp;
}
// *************************************************
// User Subs and Functions
// *************************************************
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int CmdShow)
{
static MSG Msg;
static WNDCLASS wc;
memset(&Msg,0,sizeof(Msg));
memset(&wc,0,sizeof(wc));
hInstance=hInst;
strcpy(AppName,"PropSheetDemo");
if(FindFirstInstance(AppName))
{
return 0;
}
// register main window class
// Fill in window class structure with parameters that describe main window
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.lpszMenuName="TreeViewMenu";
wc.lpszClassName=AppName;
RegisterClass(&wc);
FormLoad(hInstance);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
for( ;; )
{
if(Msg==WM_COMMAND)
{
for( ;; )
{
if(LOWORD(wParam)==ID_BUTTON1)
{
hWndPropCtrl=(HWND)CreatePropSheet(hWnd);
break;
}
if(LOWORD(wParam)==IDM_EXIT)
{
PostQuitMessage(0);
}
break;
}
break;
}
if(Msg==WM_DESTROY)
{
PostQuitMessage(0);
return 0;
}
break;
}
return DefWindowProc(hWnd,Msg,wParam,lParam);
}
void FormLoad (HINSTANCE hInst)
{
strcpy(Caption,"Property Sheet Sample");
Form1=CreateWindow(AppName,Caption,WS_OVERLAPPEDWINDOW,0,0,300,200,NULL,(HMENU)NULL,hInst,NULL);
Button1=CreateWindowEx(0,"button","Show Properties",WS_CHILD|WS_TABSTOP|BS_PUSHBUTTON|WS_VISIBLE,25,10,200,30,Form1,(HMENU)ID_BUTTON1,hInst,NULL);
SendMessage(Button1,(UINT)WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),(LPARAM)MAKELPARAM(FALSE,0));
UpdateWindow(Form1);
ShowWindow(Form1,SW_SHOWNORMAL);
}
int FindFirstInstance (char *ApplName)
{
static HWND hWnd;
memset(&hWnd,0,sizeof(hWnd));
hWnd=FindWindow(ApplName,NULL);
if(hWnd)
{
return TRUE;
}
return FALSE;
}
int CreatePropSheet (HWND hWndParent)
{
SendMessage(GetDlgItem(Form1,(UINT)ID_BUTTON1),(WPARAM)WM_SETTEXT,(LPARAM)0,(int)"Show Properties");
psp[0].dwSize=sizeof(PROPSHEETPAGE);
psp[0].dwFlags=0;
psp[0].hInstance=hInstance;
psp[0].pszTemplate=MAKEINTRESOURCE(IDD_PEOPLE);
//psp[0].pszIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IC_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_HASHELP|PSP_USEHICON;
// this page has help button active
// if none of the pages has PSP_HASHELP
// then there will be no HELP button at all
psp[1].hInstance=hInstance;
psp[1].pszTemplate=MAKEINTRESOURCE(IDD_ANIMAL);
//psp[1].pszIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IC_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_HASHELP|PSP_USEHICON;
// this page has also help button active
psp[2].hInstance=hInstance;
psp[2].pszTemplate=MAKEINTRESOURCE(IDD_BUILDING);
//psp[2].pszIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IC_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_PROPTITLE;
// PSH_PROPTITLE includes "Properties" in the title
psh.hwndParent=hWndParent;
psh.hInstance=hInstance;
psh.pszIcon=NULL;
psh.pszCaption=(LPSTR)"Family";
psh.nPages=sizeof(psp)/sizeof(PROPSHEETPAGE);
psh.nStartPage=1;
psh.ppsp=(LPCPROPSHEETPAGE)&psp;
psh.pfnCallback=NULL;
return (PropertySheet(&psh));
}
LRESULT CALLBACK PropSheetProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
static char msgtxt[2048];
static HWND hIcon;
memset(&msgtxt,0,sizeof(msgtxt));
memset(&hIcon,0,sizeof(hIcon));
for( ;; )
{
if(Msg==WM_NOTIFY)
{
for( ;; )
{
if(((LPNMHDR)lParam)->code==PSN_APPLY)
{
//
// when the apply button is pressed, the Property Sheet
// sends PSN_APPLY to all dialogs to make the next message
// visible, it is sent to the button instead of the form
//
SendMessage(GetDlgItem(Form1,(UINT)ID_BUTTON1),(WPARAM)WM_SETTEXT,(LPARAM)0,(int)"PSN_APPLY");
//
// check if all entries are OK (function not present in this demo)
//
// IF AllOK() THEN
SetWindowLong(hWnd,DWL_MSGRESULT,PSNRET_NOERROR);
// ELSE
// SetWindowLong(hWnd,DWL_MSGRESULT,PSNRET_INVALID_NOCHANGEPAGE)
// ENDIF
break;
}
if(((LPNMHDR)lParam)->code==PSN_SETACTIVE)
{
SendMessage(Form1,(UINT)WM_SETTEXT,(WPARAM)0,(LPARAM)(int)"PSN_SETACTIVE");
break;
}
if(((LPNMHDR)lParam)->code==PSN_HELP)
{
SendMessage(Form1,(UINT)WM_SETTEXT,(WPARAM)0,(LPARAM)(int)"PSN_HELP");
break;
}
if(((LPNMHDR)lParam)->code==PSN_RESET)
{
SendMessage(Form1,(UINT)WM_SETTEXT,(WPARAM)0,(LPARAM)(int)"PSN_RESET");
SetWindowLong(hWnd,DWL_MSGRESULT,FALSE);
//
// to distinguish from previous, this message
// is send to the button instead of the form
//
break;
}
if(((LPNMHDR)lParam)->code==PSN_QUERYCANCEL)
{
SendMessage(GetDlgItem(Form1,(UINT)ID_BUTTON1),(WPARAM)WM_SETTEXT,(LPARAM)0,(int)"PSN_QUERYCANCEL");
SetWindowLong(hWnd,DWL_MSGRESULT,FALSE);
break;
}
if(((LPNMHDR)lParam)->code==PSN_KILLACTIVE)
{
SendMessage(GetDlgItem(Form1,(UINT)ID_BUTTON1),(WPARAM)WM_SETTEXT,(LPARAM)0,(int)"PSN_KILLACTIVE");
SetWindowLong(hWnd,DWL_MSGRESULT,FALSE);;
}
break;
}
break;
}
if(Msg==WM_COMMAND)
{
for( ;; )
{
if(LOWORD(wParam)>200)
{
sprintf(BCX_STR,"%s%s","controlID: ",str(LOWORD(wParam)));
strcpy(msgtxt,BCX_STR);
SendMessage(Form1,(UINT)WM_SETTEXT,(WPARAM)0,(LPARAM)(int)msgtxt);
// send notification of change
// this activates the APPLY button
PropSheet_Changed(GetParent(hWnd),hWnd);
}
break;
}
}
break;
}
return DefWindowProc(hWnd,Msg,wParam,lParam);
}
//----------------------------------------------------------------
// Propsht.Rc
#include <windows.h>
10001 ICON "people.ico"
10002 ICON "animal.ico"
10003 ICON "building.ico"
1001 DIALOG 0, 0, 150, 200
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, 150, 200
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, 150, 200
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