📄 cmndlg32.c
字号:
break;
case IDM_CHOOSEFONT:
if (NewFont = ChooseNewFont( hWnd ))
InvalidateRect( hWnd, NULL, TRUE );
break;
case IDM_FINDTEXT:
CallFindText( hWnd );
break;
case IDM_REPLACETEXT:
CallReplaceText( hWnd );
break;
case IDM_STANDARD:
// uncheck previous selection
CheckMenuItem( GetMenu( hWnd ), wMode, MF_UNCHECKED | MF_BYCOMMAND);
//reset mode
wMode = LOWORD(wParam);
//check new selection
CheckMenuItem( GetMenu( hWnd ), wMode, MF_CHECKED | MF_BYCOMMAND);
DrawMenuBar( hWnd);
break;
case IDM_HOOK:
case IDM_CUSTOM:
// uncheck previous selection
CheckMenuItem( GetMenu( hWnd ), wMode, MF_UNCHECKED | MF_BYCOMMAND);
//reset mode
wMode = LOWORD(wParam);
//check new selection
CheckMenuItem( GetMenu( hWnd ), wMode, MF_CHECKED | MF_BYCOMMAND);
DrawMenuBar( hWnd);
break;
case IDM_ENTERNEW:
if (DialogBox(hInst,
"EnterNewBox",
hWnd,
(DLGPROC)EnterNew) == TRUE)
InvalidateRect( hWnd, NULL, TRUE );
break;
case IDM_ABOUT:
DialogBox(hInst,
"AboutBox",
hWnd,
(DLGPROC)About);
break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
break;
case WM_DESTROY: /* message: window being destroyed */
PostQuitMessage(0);
break;
default:
// Handle the special findreplace message (FindReplaceMsg) which
// was registered at initialization time.
if ( message == FindReplaceMsg )
{
if ( lpFR = (LPFINDREPLACE) lParam )
{
if (lpFR->Flags & FR_DIALOGTERM ) // terminating dialog
return (0);
SearchFile( lpFR );
InvalidateRect( hWnd, NULL, TRUE );
}
return (0);
}
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (0);
}
/****************************************************************************
*
* FUNCTION: EnterNew(HWND, UINT, UINT, LONG)
*
* PURPOSE: Processes messages for "EnterNew" dialog box
*
* COMMENTS:
*
* This function allows the user to enter new text in the current
* window. This text is stored in the global current buffer.
*
****************************************************************************/
BOOL APIENTRY EnterNew(
HWND hDlg, /* window handle of the dialog box */
UINT message, /* type of message */
UINT wParam, /* message-specific information */
LONG lParam)
{
TCHAR Buf[FILE_LEN-1];
switch (message)
{
case WM_INITDIALOG: /* message: initialize dialog box */
return (TRUE);
case WM_COMMAND: /* message: received a command */
if (LOWORD(wParam) == IDOK)
{
GetDlgItemText( hDlg, IDEDIT, Buf, FILE_LEN-1);
dwFileSize = strlen(Buf);
strncpy( FileBuf, Buf, FILE_LEN-1);
lpBufPtr = FileBuf;
EndDialog( hDlg, TRUE );
return (TRUE);
}
else if (LOWORD(wParam) == IDCANCEL)
{ /* System menu close command? */
EndDialog(hDlg, FALSE); /* Exits the dialog box */
return (TRUE);
}
break;
}
return (FALSE); /* Didn't process a message */
// avoid compiler warnings at W3
lParam;
}
/****************************************************************************
*
* FUNCTION: About(HWND, UINT, UINT, LONG)
*
* PURPOSE: Processes messages for "About" dialog box
*
* COMMENTS:
*
* No initialization is needed for this particular dialog box, but TRUE
* must be returned to Windows.
*
* Wait for user to click on "Ok" button, then close the dialog box.
*
****************************************************************************/
BOOL APIENTRY About(
HWND hDlg, /* window handle of the dialog box */
UINT message, /* type of message */
UINT wParam, /* message-specific information */
LONG lParam)
{
switch (message)
{
case WM_INITDIALOG: /* message: initialize dialog box */
return (TRUE);
case WM_COMMAND: /* message: received a command */
if (LOWORD(wParam) == IDOK /* "OK" box selected? */
|| LOWORD(wParam) == IDCANCEL) { /* System menu close command? */
EndDialog(hDlg, TRUE); /* Exits the dialog box */
return (TRUE);
}
break;
}
return (FALSE); /* Didn't process a message */
// avoid compiler warnings at W3
lParam;
}
/****************************************************************************
*
* FUNCTION: FileOpenNotify( HWND hDlg, LPOFNOTIFY pofn)
*
* PURPOSE: This function processes the WM_NOTIFY message that is sent
* to the hook dialog procedure for the File Open common dialog.
*
* COMMENTS:
*
*
****************************************************************************/
BOOL NEAR PASCAL FileOpenNotify(HWND hDlg, LPOFNOTIFY pofn)
{
static char lpszNotification[FILE_LEN];
switch (pofn->hdr.code)
{
// The selection has changed.
case CDN_SELCHANGE:
{
char szFile[MAX_PATH];
// Get the file specification from the common dialog.
CommDlg_OpenSave_GetSpec(GetParent(hDlg),
szFile, sizeof(szFile));
wsprintf(lpszNotification, "File Open Notification: %s. File: %s",
"CDN_SELCHANGE", szFile);
}
break;
// A new folder has been opened.
case CDN_FOLDERCHANGE:
{
char szFile[MAX_PATH];
if (CommDlg_OpenSave_GetFolderPath(GetParent(hDlg),
szFile, sizeof(szFile)) <= sizeof(szFile))
{
wsprintf(lpszNotification, "File Open Notification: %s. File: %s",
"CDN_FOLDERCHANGE", szFile);
}
}
break;
// The "Help" pushbutton has been pressed.
case CDN_HELP:
wsprintf(lpszNotification, "File Open Notification: %s.",
"CDN_HELP");
break;
// The 'OK' pushbutton has been pressed.
case CDN_FILEOK:
SetWindowLong(hDlg, DWL_MSGRESULT, 1L);
wsprintf(lpszNotification, "File Open Notification: %s. File: %s",
"CDN_FILEOK", pofn->lpOFN->lpstrFile);
break;
// Received a sharing violation.
case CDN_SHAREVIOLATION:
wsprintf(lpszNotification, "File Open Notification: %s.",
"CDN_SHAREVIOLATION");
break;
case CDN_INITDONE:
wsprintf(lpszNotification, "File Open Notification: %s.",
"CDN_INITDONE");
break;
case CDN_TYPECHANGE:
wsprintf(lpszNotification, "File Open Notification: %s.",
"CDN_TYPECHANGE");
break;
}
// write the notification out the the status window.
SendMessage(hWndStatus, SB_SETTEXT, 0, (LPARAM)lpszNotification);
return(TRUE);
}
/****************************************************************************
*
* FUNCTION: FileOpenHookProc(HWND, UINT, UINT, LONG)
*
* PURPOSE: Processes messages for GetFileNameOpen() common dialog box
*
* COMMENTS:
*
* This function will prompt the user if they are sure they want
* to open the file if the OFN_ENABLEHOOK flag is set.
*
* If the current option mode is CUSTOM, the user is allowed to check
* a box in the dialog prompting them whether or not they would like
* the file created. If they check this box, the file is created and
* the string 'Empty' is written to it.
*
* RETURN VALUES:
* TRUE - User chose 'Yes' from the "Are you sure message box".
* FALSE - User chose 'No'; return to the dialog box.
*
****************************************************************************/
BOOL APIENTRY FileOpenHookProc(
HWND hDlg, /* window handle of the dialog box */
UINT message, /* type of message */
UINT wParam, /* message-specific information */
LONG lParam)
{
HANDLE hFile;
TCHAR szTempText[256];
TCHAR szString[256];
DWORD dwBytesWritten;
switch (message)
{
case WM_NOTIFY:
FileOpenNotify(hDlg, (LPOFNOTIFY)lParam);
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
GetDlgItemText( hDlg, edt1, szTempText,
sizeof( szTempText ) - 1);
if ( OpenFileName.Flags & OFN_PATHMUSTEXIST )
{
sprintf( szString, "Are you sure you want to open %s?",
szTempText);
if ( MessageBox( hDlg, szString, "Information",
MB_YESNO ) == IDYES )
break;
return (TRUE);
}
// check to see if the Create File box has been checked
if ( (BOOL)(SendMessage( GetDlgItem(hDlg, chx2),
BM_GETCHECK, 0, 0L )) == TRUE )
{
// if so, create the file
if ((hFile = CreateFile( szTempText,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
(HANDLE)NULL)) == (HANDLE)-1)
{
MessageBox( hDlg,
"Directory could not be created.",
NULL,
MB_OK );
return (FALSE);
}
if (WriteFile( hFile, (LPTSTR)FileBuf, dwFileSize,
&dwBytesWritten, NULL) == FALSE)
MessageBox( hDlg, "Error writing file.", NULL, MB_OK );
// close the file
CloseHandle(hFile);
}
}
break;
}
return (FALSE);
// avoid compiler warnings at W3
lParam;
}
/****************************************************************************
*
* FUNCTION: OpenNewFile(HWND)
*
* PURPOSE: Invokes common dialog function to open a file and opens it.
*
* COMMENTS:
*
* This function initializes the OPENFILENAME structure and calls
* the GetOpenFileName() common dialog function. This function will
* work regardless of the mode: standard, using a hook or using a
* customized template.
*
* RETURN VALUES:
* TRUE - The file was opened successfully and read into the buffer.
* FALSE - No files were opened.
*
****************************************************************************/
BOOL OpenNewFile( HWND hWnd )
{
HANDLE hFile;
DWORD dwBytesRead;
strcpy( szFile, "");
strcpy( szFileTitle, "");
OpenFileName.lStructSize = sizeof(OPENFILENAME);
OpenFileName.hwndOwner = hWnd;
OpenFileName.hInstance = (HANDLE) hInst;
OpenFileName.lpstrFilter = szFilter;
OpenFileName.lpstrCustomFilter = (LPTSTR) NULL;
OpenFileName.nMaxCustFilter = 0L;
OpenFileName.nFilterIndex = 1L;
OpenFileName.lpstrFile = szFile;
OpenFileName.nMaxFile = sizeof(szFile);
OpenFileName.lpstrFileTitle = szFileTitle;
OpenFileName.nMaxFileTitle = sizeof(szFileTitle);
OpenFileName.lpstrInitialDir = NULL;
OpenFileName.lpstrTitle = "Open a File";
OpenFileName.nFileOffset = 0;
OpenFileName.nFileExtension = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -