📄 dlgdemo.cpp
字号:
of.lStructSize = sizeof (of);
of.hwndOwner = hWnd;
of.lpstrFile = szFileName;
of.nMaxFile = dim(szFileName);
of.lpstrFilter = pszOpenFilter;
of.Flags = 0;
rc = GetOpenFileName (&of);
RptMessage (-1, TEXT ("GetOpenFileName returned: %x, filename: %s"),
rc, szFileName);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandSave - Process File Save command.
//
LPARAM DoMainCommandSave (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
OPENFILENAME of;
TCHAR szFileName [MAX_PATH] = {0};
const LPTSTR pszOpenFilter = TEXT ("All Documents (*.*)\0*.*\0\0");
INT rc;
szFileName[0] = '\0'; // Initialize filename.
memset (&of, 0, sizeof (of)); // Initialize File Open structure.
of.lStructSize = sizeof (of);
of.hwndOwner = hWnd;
of.lpstrFile = szFileName;
of.nMaxFile = dim(szFileName);
of.lpstrFilter = pszOpenFilter;
of.Flags = 0;
rc = GetSaveFileName (&of);
RptMessage (-1, TEXT ("GetSaveFileName returned: %x, filename: %s"),
rc, szFileName);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandColor - Process File Color command.
//
LPARAM DoMainCommandColor (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
CHOOSECOLOR cc;
static COLORREF cr[16];
INT rc;
// Initialize color structure.
memset (&cc, 0, sizeof (cc));
memset (&cr, 0, sizeof (cr));
cc.lStructSize = sizeof (cc);
cc.hwndOwner = hWnd;
cc.hInstance = hInst;
cc.rgbResult = RGB (0, 0, 0);
cc.lpCustColors = cr;
cc.Flags = CC_ANYCOLOR;
rc = (lpfnChooseColor) (&cc);
RptMessage (-1, TEXT ("Choose Color returned: %x, color: %x"),
rc, cc.rgbResult);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandFont - Process File Font command.
//
LPARAM DoMainCommandFont (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
#ifndef WINMOBILE
CHOOSEFONT cfd;
int rc;
if (lpfnChooseFontDlg == 0)
RptMessage (-1, TEXT ("ChooseFontDlg Not available"));
// Initialize print structure.
memset (&cfd, 0, sizeof (cfd));
cfd.lStructSize = sizeof (cfd);
cfd.hwndOwner = hWnd;
cfd.Flags = CF_SCREENFONTS;
rc = (lpfnChooseFontDlg) (&cfd);
RptMessage (-1, TEXT ("Choose Font returned: %x"), rc);
#endif
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandPrint - Process File Print command.
//
LPARAM DoMainCommandPrint (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
INT rc;
#ifndef WINMOBILE
PAGESETUPDLG psd;
// Initialize print structure.
memset (&psd, 0, sizeof (psd));
psd.lStructSize = sizeof (psd);
psd.hwndOwner = hWnd;
rc = (lpfnPrintDlg) (&psd);
#else
PRINTDLG pd;
// Initialize print structure.
memset (&pd, 0, sizeof (pd));
pd.cbStruct = sizeof (pd);
pd.hwndOwner = hWnd;
pd.dwFlags = PD_SELECTALLPAGES;
rc = (lpfnPrintDlg) (&pd);
#endif // ifndef WIN32_PLATFORM_PSPC
RptMessage (-1, TEXT ("PrintDlg returned: %x, : %x"),
rc, GetLastError());
return 0;
}
//----------------------------------------------------------------------
// PropSheetProc - Function called when Property sheet created
//
int CALLBACK PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam) {
HWND hwndTabs;
DWORD dwStyle;
RptMessage (-1, TEXT("PropSheetCallback h:%08x %4d %08x"),
hwndDlg, uMsg, lParam);
switch (uMsg)
{
case PSCB_INITIALIZED:
// Get tab control.
hwndTabs = GetDlgItem (hwndDlg, 0x3020);
dwStyle = GetWindowLong (hwndTabs, GWL_STYLE);
SetWindowLong (hwndTabs, GWL_STYLE, dwStyle | TCS_BOTTOM);
return 0;
case PSCB_GETTITLE:
StringCbCopy((LPTSTR)lParam, 256, TEXT ("Property Sheet"));
return 1;
case PSCB_GETVERSION:
return COMCTL32_VERSION;
// Add a hyperlink line below the tabs.
case PSCB_GETLINKTEXT:
StringCbCopy((LPTSTR)lParam, 256, TEXT ("Launch the calculator by ")
TEXT("tapping <file:\\windows\\calc.exe{here}>."));
return 0;
}
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandShowProp - Process show property sheet command.
//
LPARAM DoMainCommandShowProp(HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
PROPSHEETPAGE psp[2];
PROPSHEETHEADER psh;
INT i;
// Zero all the property page structures.
memset (&psp, 0, sizeof (psp));
// Fill in default values in property page structures.
for (i = 0; i < dim(psp); i++) {
psp[i].dwSize = sizeof (PROPSHEETPAGE);
psp[i].dwFlags = PSP_DEFAULT;
psp[i].hInstance = hInst;
psp[i].lParam = (LPARAM)hWnd;
}
// Set the dialog box templates for each page.
psp[0].pszTemplate = MAKEINTRESOURCE (ID_PAGE1);
psp[1].pszTemplate = MAKEINTRESOURCE (ID_PAGE2);
// Set the dialog box procedures for each page.
psp[0].pfnDlgProc = Page1DlgProc;
psp[1].pfnDlgProc = Page2DlgProc;
// Initialize property sheet structure.
psh.dwSize = sizeof (PROPSHEETHEADER);
psh.dwFlags = PSH_PROPSHEETPAGE;
psh.hwndParent = hWnd;
psh.hInstance = hInst;
psh.pszCaption = TEXT ("Property Sheet Demo");
psh.nPages = dim(psp);
psh.nStartPage = 0;
psh.ppsp = psp;
psh.pfnCallback = PropSheetProc;
// On Windows Mobile, make property sheets full screen.
#if WINMOBILE
psh.dwFlags |= PSH_USECALLBACK | PSH_MAXIMIZE;
#else
psh.dwFlags |= PSH_USECALLBACK;
#endif
// Create and display property sheet.
PropertySheet (&psh);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandModelessDlg - Process the File Modeless menu command.
//
LPARAM DoMainCommandModeless(HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
// Create dialog box only if not already created.
if (g_hwndMlDlg == 0)
// Use CreateDialog to create modeless dialog box.
g_hwndMlDlg = CreateDialog (hInst, TEXT ("Clearbox"), hWnd,
ModelessDlgProc);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandScrollable - Process the File Scrollable menu command.
//
LPARAM DoMainCommandScrollable(HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
// Create dialog box only if not already created.
DialogBox (hInst, TEXT ("ScrollDlg"), hWnd, ScrollableDlgProc);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandExit - Process Program Exit command.
//
LPARAM DoMainCommandExit (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
SendMessage (hWnd, WM_CLOSE, 0, 0);
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandAbout - Process the Help About menu command.
//
LPARAM DoMainCommandAbout(HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
// Use DialogBox to create modal dialog box.
DialogBox (hInst, TEXT ("aboutbox"), hWnd, AboutDlgProc);
return 0;
}
//======================================================================
// Modeless ClearList dialog box procedure
//
BOOL CALLBACK ModelessDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
switch (wMsg) {
case WM_COMMAND:
switch (LOWORD (wParam)) {
case IDD_CLEAR:
// Send message to list box to clear it.
SendDlgItemMessage (GetWindow (hWnd, GW_OWNER),
IDC_RPTLIST,
LB_RESETCONTENT, 0, 0);
return TRUE;
case IDOK:
case IDCANCEL:
// Modeless dialog boxes can't use EndDialog.
DestroyWindow (hWnd);
g_hwndMlDlg = 0; // 0 means dlg destroyed.
return TRUE;
}
break;
}
return FALSE;
}
//======================================================================
// About dialog box procedure
//
BOOL CALLBACK AboutDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
SHINITDLGINFO idi;
switch (wMsg) {
case WM_INITDIALOG:
idi.dwMask = SHIDIM_FLAGS;
idi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN |
SHIDIF_SIPDOWN;
idi.hDlg = hWnd;
SHInitDialog (&idi);
break;
case WM_COMMAND:
switch (LOWORD (wParam)) {
case IDOK:
case IDCANCEL:
EndDialog (hWnd, 0);
return TRUE;
}
break;
}
return FALSE;
}
//----------------------------------------------------------------------
// PrintCmdMessage - Prints command message data to report window
//
LRESULT PrintCmdMessage (WPARAM wParam, LPARAM lParam,
PNOTELABELS lpStruct, int nDim) {
int i;
for (i = 0; i < nDim; i++) {
if (HIWORD (wParam) == lpStruct[i].wNotification) {
RptMessage (LOWORD(wParam), TEXT("%s"),
lpStruct[i].pszLabel);
break;
}
}
if (i == nDim)
RptMessage (wParam, TEXT("WM_COMMAND notification: %x"),
HIWORD (wParam));
return 0;
}
//----------------------------------------------------------------------
// PrintNotMessage - Prints notification message data to report window
//
LRESULT PrintNotMessage (LPARAM lParam, PNOTELABELS lpStruct, int nDim) {
int i;
LPNMHDR phdr = (NMHDR *)lParam;
for (i = 0; i < nDim; i++) {
if (phdr->code == lpStruct[i].wNotification) {
RptMessage (phdr->idFrom, TEXT("%s"), lpStruct[i].pszLabel);
break;
}
}
if (i == nDim)
{
// If not in local list, check standard notifications
for (i = 0; i < sizeof (nlPropPage); i++) {
if (phdr->code == nlPropPage[i].wNotification) {
RptMessage (phdr->idFrom, TEXT("%s"),
nlPropPage[i].pszLabel);
break;
}
}
if (i == sizeof (nlPropPage))
RptMessage (phdr->idFrom, TEXT ("Notify code:%4d"),
phdr->code);
}
return 0;
}
//----------------------------------------------------------------------
// RptMessage - Add string to the report list box.
//
void RptMessage (DWORD id, LPTSTR lpszFormat, ...) {
TCHAR szBuffer[512];
va_list args;
va_start(args, lpszFormat);
StringCchVPrintf(szBuffer, dim (szBuffer),lpszFormat, args);
va_end(args);
SendMessage (hwndMain, MYMSG_ADDLINE, id,(LPARAM)szBuffer);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -