- 1 year ago
Can I make a property sheet without resource script?
Yes, it is possible to create a property sheet without using a resource script in Windows. Instead, you can dynamically create the property sheet controls and handle their events programmatically. Here's an example using the Win32 API:
cpp#include <Windows.h>
#include <CommCtrl.h>
// Property sheet window procedure
INT_PTR CALLBACK PropertySheetProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
// Create controls dynamically
HWND hButton = CreateWindow(
WC_BUTTON, // Window class name
L"Click Me", // Window caption
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // Window style
10, 10, 100, 30, // Position and size
hwndDlg, // Parent window handle
NULL, // Menu handle
GetModuleHandle(NULL), // Instance handle
NULL // Window creation data
);
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hwndDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Initialize common controls
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&icex);
// Create the property sheet
PROPSHEETPAGE psp;
psp.dwSize = sizeof(PROPSHEETPAGE);
psp.dwFlags = PSP_DEFAULT | PSP_USETITLE;
psp.hInstance = hInstance;
psp.pszTemplate = NULL; // No resource template
psp.pfnDlgProc = PropertySheetProc;
psp.pszTitle = L"Property Sheet Title";
PROPSHEETHEADER psh;
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID;
psh.hwndParent = NULL; // Parent window handle
psh.hInstance = hInstance;
psh.pszIcon = NULL; // No icon
psh.pszCaption = L"Property Sheet Caption";
psh.nPages = 1;
psh.nStartPage = 0;
psh.ppsp = &psp;
PropertySheet(&psh);
return 0;
}
In this example, the PropertySheetProc
function serves as the window procedure for the property sheet dialog. In the WM_INITDIALOG
message handler, you can dynamically create controls using the CreateWindow
function. The WM_COMMAND
message handler handles button click events.
In the WinMain
function, the common controls are initialized using InitCommonControlsEx
. The property sheet is created using PROPSHEETPAGE
and PROPSHEETHEADER
structures. The pszTemplate
member of PROPSHEETPAGE
is set to NULL
to indicate that no resource template is used.
Compile and run the code, and you should see a property sheet with a button control. You can modify the PropertySheetProc
function to create additional controls and handle their events as needed.