一、PropertySheet 说明
1.PropertySheet是对话框而非控件,虽然微软将他放在控件文章中来说明。但实际上PropertySheet是一个对话框容器,而非控件的容器。原因是其内部的Page页面,都是标准的对话框。所以应该将它划分为通用对话框一边。
2. PropertySheet的两种典型的使用方式是:Wizard和Tab标签页。
一种方式是Wizard式的向导式对话框,另外一个方式是Tab控件式的列表。这两种对话框容器都起着很重要的作用,典型的就是在IDE环境中的项目向导,属性配置对话框。
二、通用代码部分
1.资源文件----h文件
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#define IDD_FIRST_PAGE 105
#define IDD_LAST_PAGE 106
#define IDD_PAGE1 107
#define IDD_PAGE2 108
#define IDD_PAGE3 109
2.资源文件-----rc文件
// Generated by ResEdit 1.6.2
// Copyright (C) 2006-2014
// http://www.resedit.net
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"
//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_FIRST_PAGE DIALOG 0, 0, 317, 193
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
LTEXT "这是欢迎页面", 0, 30, 45, 49, 8, SS_LEFT, WS_EX_LEFT
}
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_LAST_PAGE DIALOG 0, 0, 317, 193
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
LTEXT "这是结束页", 0, 123, 71, 41, 8, SS_LEFT, WS_EX_LEFT
}
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_PAGE1 DIALOG 0, 0, 317, 143
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
LTEXT "这是第一页", 0, 130, 53, 41, 8, SS_LEFT, WS_EX_LEFT
}
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_PAGE2 DIALOG 0, 0, 317, 143
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
LTEXT "这是第二页", 0, 119, 54, 41, 8, SS_LEFT, WS_EX_LEFT
}
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_PAGE3 DIALOG 0, 0, 317, 143
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
LTEXT "这是第三页", 0, 127, 55, 41, 8, SS_LEFT, WS_EX_LEFT
}
3.代码-----通用部分
#include <windows.h>
#include "./res/resource.h"
HINSTANCE g_hinst;
//PropertySheet回调函数,似乎可以不需要
int CALLBACK PropSheetProc(HWND hDlg,UINT uMsg,LPARAM lParam)
{
switch(uMsg)
{
case PSCB_PRECREATE:
break;
default:
return 0;
}
return 0;
}
//每一个页面的消息处理函数。作为例子这里简化为共用一个。
INT_PTR CALLBACK DialogProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
//TODO
break;
}
return 0;
}
VOID DoPropertySheet();
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
{
g_hinst=hInstance;
DoPropertySheet();
}
三、创建PropertySheet代码
方式一:HPROPSHEETPAGE数组
1.创建Wizard代码
VOID DoPropertySheet()
{
///创建页面//
PROPSHEETPAGE psp;
HPROPSHEETPAGE ahpsp[4];
PROPSHEETHEADER psh;
/*******通用部分*******/
psp.dwSize =sizeof(PROPSHEETPAGE);
psp.hInstance = g_hinst;
psp.pfnDlgProc = DialogProc;
/*********创建页面********/
psp.pszTemplate = MAKEINTRESOURCE(IDD_FIRST_PAGE);
ahpsp[0] = CreatePropertySheetPage(&psp);
psp.pszTemplate = MAKEINTRESOURCE(IDD_PAGE1);
ahpsp[1] = CreatePropertySheetPage(&psp);
psp.pszTemplate = MAKEINTRESOURCE(IDD_PAGE2);
ahpsp[2] = CreatePropertySheetPage(&psp);
psp.pszTemplate = MAKEINTRESOURCE(IDD_PAGE3);
ahpsp[3] = CreatePropertySheetPage(&psp);
psp.pszTemplate = MAKEINTRESOURCE(IDD_LAST_PAGE);
ahpsp[4] = CreatePropertySheetPage(&psp);
psh.dwSize =sizeof(PROPSHEETHEADER);
psh.hInstance = g_hinst;
psh.hwndParent = NULL;
psh.phpage = ahpsp;//指定HPROPSHEETPAGE数组
psh.dwFlags=PSH_WIZARD;
psh.nStartPage = 0;
psh.nPages = 5;
PropertySheet(&psh);
}
2.创建Tab代码
VOID DoPropertySheet()
{
///创建页面//
PROPSHEETPAGE psp;
HPROPSHEETPAGE ahpsp[4];
PROPSHEETHEADER psh;
/*******通用部分*******/
psp.dwSize =sizeof(PROPSHEETPAGE);
psp.hInstance = g_hinst;
psp.pfnDlgProc = DialogProc;//核心部分,不能省略
/*********创建页面********/
psp.pszTemplate = MAKEINTRESOURCE(IDD_FIRST_PAGE);
psp.dwFlags = PSP_USETITLE;
psp.pszTitle = TEXT("字体");
ahpsp[0] = CreatePropertySheetPage(&psp);//如果不适用TITLE,那么将使用资源中对话框的Caption名称。
psp.dwFlags = PSP_USETITLE;
psp.pszTitle = TEXT("颜色");
psp.pszTemplate = MAKEINTRESOURCE(IDD_PAGE1);
ahpsp[1] = CreatePropertySheetPage(&psp);
psp.dwFlags = PSP_USETITLE;
psp.pszTitle = TEXT("编辑器");
psp.pszTemplate = MAKEINTRESOURCE(IDD_PAGE2);
ahpsp[2] = CreatePropertySheetPage(&psp);
psp.dwFlags = PSP_USETITLE;
psp.pszTitle = TEXT("绘图");
psp.pszTemplate = MAKEINTRESOURCE(IDD_PAGE3);
ahpsp[3] = CreatePropertySheetPage(&psp);
psp.dwFlags = PSP_USETITLE;
psp.pszTitle = TEXT("格式");
psp.pszTemplate = MAKEINTRESOURCE(IDD_LAST_PAGE);
ahpsp[4] = CreatePropertySheetPage(&psp);
psh.dwSize =sizeof(PROPSHEETHEADER);
psh.hInstance = g_hinst;
psh.hwndParent = NULL;
psh.phpage = ahpsp;//指定HPROPSHEETPAGE数组
psh.dwFlags=PSH_PROPTITLE;
psh.nStartPage = 0;
psh.nPages = 5;
PropertySheet(&psh);
}
方式二:使用PROPSHEETPAGE数组
1.创建Wizard代码
VOID DoPropertySheet()
{
PROPSHEETPAGE psp[5];
PROPSHEETHEADER psh;
/
psp[0].dwSize = sizeof(PROPSHEETPAGE);
psp[0].dwFlags = PSP_USETITLE;
psp[0].pszTitle = NULL;
psp[0].hInstance = g_hinst;
psp[0].pfnDlgProc = DialogProc;//必须的
psp[0].pszTemplate = MAKEINTRESOURCE(IDD_FIRST_PAGE);
psp[1].dwSize = sizeof(PROPSHEETPAGE);
psp[1].dwFlags = PSP_USETITLE;
psp[1].pszTitle = NULL;
psp[1].hInstance = g_hinst;
psp[1].pfnDlgProc = DialogProc;//必须的
psp[1].pszTemplate =MAKEINTRESOURCE(IDD_PAGE1);
psp[2].dwSize = sizeof(PROPSHEETPAGE);
psp[2].dwFlags = PSP_USETITLE;
psp[2].pszTitle = NULL;
psp[2].hInstance = g_hinst;
psp[2].pfnDlgProc = DialogProc;//必须的
psp[2].pszTemplate = MAKEINTRESOURCE(IDD_PAGE2);
psp[3].dwSize = sizeof(PROPSHEETPAGE);
psp[3].dwFlags = PSP_USETITLE;
psp[3].pszTitle = NULL;
psp[3].hInstance = g_hinst;
psp[3].pfnDlgProc = DialogProc;//必须的
psp[3].pszTemplate =MAKEINTRESOURCE(IDD_PAGE3);
psp[4].dwSize = sizeof(PROPSHEETPAGE);
psp[4].dwFlags = PSP_USETITLE;
psp[4].pszTitle = NULL;
psp[4].hInstance = g_hinst;
psp[4].pfnDlgProc = DialogProc;//必须的
psp[4].pszTemplate =MAKEINTRESOURCE(IDD_LAST_PAGE);
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_WIZARD|PSH_PROPSHEETPAGE;
psh.hwndParent = NULL;//必须的不能少
psh.hInstance = g_hinst;
psh.nPages = sizeof(psp)/sizeof(PROPSHEETPAGE);
psh.nStartPage = 0;
psh.ppsp = (LPCPROPSHEETPAGE) &psp;//这个选项需要PSH_PROPSHEETPAGE
PropertySheet(&psh);
}
2.创建Tab代码
VOID DoPropertySheet()
{
PROPSHEETPAGE psp[5];
PROPSHEETHEADER psh;
/
psp[0].dwSize = sizeof(PROPSHEETPAGE);
psp[0].dwFlags = PSP_USETITLE;
psp[0].pszTitle = TEXT("字体");
psp[0].hInstance = g_hinst;
psp[0].pfnDlgProc = DialogProc;//必须的
psp[0].pszTemplate = MAKEINTRESOURCE(IDD_FIRST_PAGE);
psp[1].dwSize = sizeof(PROPSHEETPAGE);
psp[1].dwFlags = PSP_USETITLE;
psp[1].pszTitle = TEXT("颜色");
psp[1].hInstance = g_hinst;
psp[1].pfnDlgProc = DialogProc;//必须的
psp[1].pszTemplate =MAKEINTRESOURCE(IDD_PAGE1);
psp[2].dwSize = sizeof(PROPSHEETPAGE);
psp[2].dwFlags = PSP_USETITLE;
psp[2].pszTitle = TEXT("编辑器");
psp[2].hInstance = g_hinst;
psp[2].pfnDlgProc = DialogProc;//必须的
psp[2].pszTemplate = MAKEINTRESOURCE(IDD_PAGE2);
psp[3].dwSize = sizeof(PROPSHEETPAGE);
psp[3].dwFlags = PSP_USETITLE;
psp[3].pszTitle = TEXT("绘图");
psp[3].hInstance = g_hinst;
psp[3].pfnDlgProc = DialogProc;//必须的
psp[3].pszTemplate =MAKEINTRESOURCE(IDD_PAGE3);
psp[4].dwSize = sizeof(PROPSHEETPAGE);
psp[4].dwFlags = PSP_USETITLE;
psp[4].pszTitle = TEXT("格式");
psp[4].hInstance = g_hinst;
psp[4].pfnDlgProc = DialogProc;//必须的
psp[4].pszTemplate =MAKEINTRESOURCE(IDD_LAST_PAGE);
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_PROPTITLE|PSH_PROPSHEETPAGE;
psh.hwndParent = NULL;//必须的不能少
psh.hInstance = g_hinst;
psh.nPages = sizeof(psp)/sizeof(PROPSHEETPAGE);
psh.nStartPage = 0;
psh.ppsp = (LPCPROPSHEETPAGE) &psp;//这个选项需要PSH_PROPSHEETPAGE
PropertySheet(&psh);
}
使用PROPSHEETPAGE数组,最终要的一点,就是要在psh.dwFlags中加入PSH_PROPSHEETPAGE标志,这样才会启用psh.ppsp成员。同时每个页面必须设置dwFlags,为上述格式(其他未实验)。
三、未完待续............