API | MFC | C++ | C |

Programming Windows API

Windows Property Sheets Example

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 228, 97
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,237,24,50,14
PUSHBUTTON "Cancel",IDCANCEL,237,24,50,14
END
PAGE1 DIALOG DISCARDABLE 0, 0, 100, 47
STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Tab 1"
FONT 10, "MS Sans Serif"
BEGIN
CONTROL "Radio1",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON,4,13,58,8
CONTROL "Radio2",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,4,27,60,8
GROUPBOX "Page 1",IDC_STATIC,1,3,71,36
END
PAGE2 DIALOG DISCARDABLE 0, 0, 100, 24
STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Tab 2"
FONT 16, "MS Sans Serif"
BEGIN
LTEXT "Page 2",-1,0,1,100,10
END
/////////////////////////////////////////////////////////////////////////////
//
//property sheet example
#pragma comment( lib, "user32.lib" )
#pragma comment( lib, "comctl32.lib" )
#include <windows.h>
#include <commctrl.h>
#define IDC_RADIO1 1
#define IDC_RADIO2 2
//the first property sheet page function
BOOL CALLBACK PageProc1(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp)

{
LPNMHDR lpnmhdr;
switch (msg)
{
case WM_COMMAND:
switch (LOWORD(wp))
//respond to button click
{
case IDC_RADIO1:
MessageBox(hwnd,TEXT("Radio 1 Clicked"),TEXT("Tab1"),MB_OK);
break;
case IDC_RADIO2:
MessageBox(hwnd,TEXT("Radio 2 Clicked"),TEXT("Tab1"),MB_OK);
break;
}
break;

case WM_NOTIFY:
lpnmhdr = (NMHDR FAR *)lp;
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://Notifies a page that it is about to be activated.
PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_NEXT);
break;
default:
break;
}
break;
default:
break;
}
return FALSE;
}
//the second property sheet page function
BOOL CALLBACK PageProc2(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) {
return FALSE;
}

LRESULT CALLBACK WndProc(HWND hWnd , UINT msg , WPARAM wp , LPARAM lp) {
PROPSHEETPAGE psp;//stores information about each property page
PROPSHEETHEADER psh;//stores information about the propety sheet
HPROPSHEETPAGE hPsp[2];//used to individual create page for property sheet

switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_CREATE:
InitCommonControls();
return 0;
//responds to right mouse button click by creating and displaying the property sheet
case WM_RBUTTONUP:
psp.dwSize = sizeof (PROPSHEETPAGE);
psp.dwFlags = PSP_DEFAULT | PSP_USEICONID;
psp.pszIcon = TEXT("PAGEICON");
psp.hInstance = (HINSTANCE)GetWindowLong(hWnd , GWL_HINSTANCE);

psp.pszTemplate = TEXT("Page1");
psp.pfnDlgProc = (DLGPROC)PageProc1;
hPsp[0] = CreatePropertySheetPage(&psp);

psp.pszTemplate = TEXT("Page2");
psp.pfnDlgProc = (DLGPROC)PageProc2;
hPsp[1] = CreatePropertySheetPage(&psp);

psh.dwSize = sizeof (PROPSHEETHEADER);
psh.dwFlags = PSH_DEFAULT | PSH_USEHICON;
psh.hwndParent = hWnd;
psh.hIcon = LoadIcon(NULL , IDI_ASTERISK);
psh.pszCaption =TEXT( "property Sheet");
psh.nPages = 2;
psh.phpage = hPsp;
PropertySheet(&psh);
return 0;
}
return DefWindowProc(hWnd , msg , wp , lp);
}

int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance ,PSTR lpCmdLine , int nCmdShow )
{
HWND hWnd;
MSG msg;
WNDCLASS winc;

winc.style = CS_HREDRAW | CS_VREDRAW;
winc.lpfnWndProc = WndProc;
winc.cbClsExtra = winc.cbWndExtra = 0;
winc.hInstance = hInstance;
winc.hIcon = LoadIcon(NULL , IDI_APPLICATION);
winc.hCursor = LoadCursor(NULL , IDC_ARROW);
winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
winc.lpszMenuName = NULL;
winc.lpszClassName = TEXT("WndProc");

if (!RegisterClass(&winc)) return -1;

hWnd = CreateWindow(
TEXT("WndProc") , TEXT("Property Sheet Demo") ,
WS_OVERLAPPEDWINDOW | WS_VISIBLE ,
CW_USEDEFAULT , CW_USEDEFAULT ,
CW_USEDEFAULT , CW_USEDEFAULT ,
NULL , NULL , hInstance , NULL
);
if (hWnd == NULL) return -1;

while(GetMessage(&msg , NULL , 0 , 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

Creating a Simple Window | Common Elements | Data Types and Character Sets | The Device Context | Graphics Device Interface | Displaying Text | Displaying Graphics | Mapping Modes | Keyboard Input | Working with the Mouse | Menus | Child Windows | ScrollBar Control | The Dialog Box | Windows Message Box | Common Dialog Box | Bitmaps | Common Controls | Creating a Toolbar | Multiple Document Interface | Timers | DLL’s | Creating Custom Controls | Owner Drawn Controls | API Hooking and DLL Injection | File Management Functions | String Manipulation | System Information Functions |