My notepad (IMITATING windows Notepad program) program source code

Source: Internet
Author: User
Tags comparison table


 

A small part of the code in the source program:File Name: mynotepad. cpp

 

// MyNotepad.cpp: Defines the entry point for the application. <br />
// <br />
#include "stdafx.h" </ p>
<p> #include "resource.h" <br />
#include "MyNotepad.h" <br />
#include "PopFile.h" <br />
#include "PopFont.h" <br />
#include "PopFind.h" <br />
#include "ErrorMessage.h" <br />
#include "GetDllVersion.h" </ p>
<p> LONG <br />
OnLineWrap (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); </ p>
<p> // Message mapping and processing function comparison table. <br />
struct MSGMAP_ENTRY _messageEntries [] = <br />
{<br />
WM_CREATE, OnCreate, <br />
WM_DESTROY, OnDestroy, <br />
WM_SIZE, OnSize, <br />
WM_SETFOCUS, OnSetFocus, <br />
WM_CLOSE, OnClose, <br />
WM_COMMAND, OnCommand <br />
}; <br />
// COMMAND-ID processing comparison table. <br />
struct MSGMAP_ENTRY _commandEntries [] = <br />
{IDM_ABOUT, OnAbout, </ p>
<p> IDM_FILE_NEW, OnFileNew, <br />
IDM_FILE_OPEN, OnFileOpen, <br />
IDM_FILE_SAVE, OnFileSave, <br />
IDM_FILE_SAVE_AS, OnFileSaveAs, <br />
IDM_EDIT_FIND, OnEditFind, <br />
IDM_EDIT_FIND_NEXT, OnEditFindNext, <br />
IDM_EDIT_FIND_REPLACE, OnEditFindReplace, <br />
IDM_DATATIME, OnDataTime, <br />
IDM_APP_EXIT, OnAppExit, <br />
IDM_FORMAT_FONT, OnFormatFont, <br />
IDM_EDIT_UNDO, OnEditUndo, <br />
IDM_EDIT_CUT, OnEditCut, <br />
IDM_EDIT_COPY, OnEditCopy, <br />
IDM_EDIT_PASTE, OnEditPaste, <br />
IDM_EDIT_CLEAR, OnEditClear, <br />
IDM_EDIT_SELECT_ALL, OnEditSelectAll, <br />
IDM_STATIC, OnStatic, <br />
IDM_LINE_WRAP, OnLineWrap <br />
}; </ p>
<p> void SetStatusText (HWND hWndEdit, HWND hWndStatus); <br />
// Edit control window subclass. <br />
LRESULT <br />
CALLBACK <br />
EditSubWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); </ p>
<p> // Global Variables: <br />
HINSTANCE _hInst; // current instance <br />
TCHAR _szAppName [MAX_LOADSTRING]; // Program name. <br />
TCHAR _szFileName [MAX_PATH]; // File name. <br />
TCHAR _szTitleName [MAX_PATH]; // Program title. <br />
HWND _hDlgModeless; // Find dialog handle. <br />
HWND _hWndEdit; // Edit window handle. <br />
HWND _hWndStatus; // The handle of the status bar window. <br />
UINT _messageFindReplace; // Find dialog ID. <br />
BOOL _bNeedSave; // The file needs to be saved. <br />
WNDPROC _wpOrigEditProc; // The original EDIT control window procedure function address. </ p>
<p> int <br />
APIENTRY <br />
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) <br />
{<br />
 MSG msg; <br />
HWND hWnd; <br />
HACCEL hAccel; <br />
INITCOMMONCONTROLSEX cc; // General control class information structure. </ P>
<p> cc.dwSize = sizeof (INITCOMMONCONTROLSEX); <br />
cc.dwICC = ICC_BAR_CLASSES; // The status bar class. </ p>
<p> if (GetDllVersion (TEXT ("comctl32.dll")) <PACKVERSION (4,71)) <br />
{<br />
MessageBox (NULL, TEXT ("comctl32.dll Version <4.71"), NULL, MB_OK); <br />
return FALSE; <br />
} </ p>
<p> if (! InitCommonControlsEx (& cc)) <br />
{<br />
MessageBox (NULL, TEXT ("InitCommonControlsEx ()"), NULL, MB_OK); <br />
return FALSE; <br />
} </ p>
<p> MyRegisterClass (hInstance); <br />
hWnd = InitInstance (hInstance, nCmdShow); <br />
if (! hWnd) return FALSE; </ p>
<p> hAccel = LoadAccelerators (hInstance, MAKEINTRESOURCE (IDR_ACCELERATOR1)); <br />
// Main message loop: <br />
while (GetMessage (& msg, NULL, 0, 0)) <br />
{<br />
if (_hDlgModeless == NULL ||! IsDialogMessage (_hDlgModeless, & msg)) <br />
{<br />
if (! TranslateAccelerator (hWnd, hAccel, & msg)) <br />
{<br />
TranslateMessage (& msg); <br />
DispatchMessage (& msg); <br />
} <br />
} <br />
} </ p>
<p> return msg.wParam; <br />
} </ p>
<p> ATOM <br />
MyRegisterClass (HINSTANCE hInstance) <br />
{<br />
// Load the text string of the application title bar. <br />
LoadString (hInstance, IDS_APP_TITLE, _szAppName, MAX_LOADSTRING); </ p>
<p> WNDCLASSEX wcex; </ p>
<p> wcex.cbSize = sizeof (WNDCLASSEX); <br />
wcex.style = CS_HREDRAW | CS_VREDRAW; <br />
wcex.lpfnWndProc = (WNDPROC) WndProc; <br />
wcex.cbClsExtra = 0; <br />
wcex.cbWndExtra = 0; <br />
wcex.hInstance = hInstance; <br />
wcex.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_ICON1)); <br />
wcex.hCursor = LoadCursor (NULL, IDC_ARROW); <br />
wcex.hbrBackground = (HBRUSH) COLOR_WINDOW + 1; <br />
wcex.lpszMenuName = NULL; <br />
wcex.lpszClassName = _szAppName; <br />
wcex.hIconSm = NULL; </ p>
<p> return RegisterClassEx (& wcex); <br />
} </ p>
<p> HWND <br />
InitInstance (HINSTANCE hInstance, int nCmdShow) <br />
{<br />
HWND hWnd; <br />
_hInst = hInstance; </ p>
<p> hWnd = CreateWindow (<br />
_szAppName, // windows class name <br />
_szAppName, // windows title. <br />
WS_OVERLAPPEDWINDOW, <br />
CW_USEDEFAULT, <br />
CW_USEDEFAULT, <br />
CW_USEDEFAULT, <br />
CW_USEDEFAULT, <br />
NULL, <br />
LoadMenu (hInstance, MAKEINTRESOURCE (IDR_MENU1)), <br />
hInstance, NULL); </ p>
<p> if (! hWnd) return NULL; </ p>
<p> ShowWindow (hWnd, nCmdShow); <br />
   UpdateWindow (hWnd); </ p>
<p> return hWnd; <br />
} </ p>
<p> LRESULT <br />
CALLBACK <br />
WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
int i; </ p>
<p> for (i = 0; i <dim (_messageEntries); i ++) <br />
{<br />
if (message == _messageEntries [i] .nMessage) <br />
return ((* _messageEntries [i] .pfn) (hWnd, message, wParam, lParam)); <br />
} </ p>
<p> // Process the find and replace dialog message. <br />
if (message == _messageFindReplace) <br
/>
{<br />
PopFindReplaceText (_hWndEdit, (LPFINDREPLACE) lParam); <br />
SetForegroundWindow (hWnd); // Set the foreground window. <br />
} </ p>
<p> return (DefWindowProc (hWnd, message, wParam, lParam)); <br />
} </ p>
<p> LONG <br />
OnCommand (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
int i; </ p>
<p> for (i = 0; i <dim (_commandEntries); i ++) <br />
{<br />
if (LOWORD (wParam) == _commandEntries [i] .nMessage) <br />
return ((* _commandEntries [i] .pfn) (hWnd, message, wParam, lParam)); <br />
} </ p>
<p> // Process edit control commands. <br />
if (lParam && LOWORD (wParam) == ID_EDIT) <br />
{<br />
MessageOperationEdit (_hWndEdit, wParam, & _bNeedSave); <br />
} </ p>
<p> return (DefWindowProc (hWnd, message, wParam, lParam)); <br />
} </ p>
<p> // Process window messages. <br />
LONG <br />
OnCreate (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
if (! CreateEditText (hWnd, wParam, lParam)) return 0; <br />
if (! InitStatus (hWnd)) return 0; </ p>
<p> _wpOrigEditProc = (WNDPROC) SetWindowLong (_hWndEdit, GWL_WNDPROC, (LONG) EditSubWndProc); </ p>
<p> // Set the maximum number of characters (hard limit) that the edit control can enter. <br />
SendMessage (_hWndEdit, EM_LIMITTEXT, MAX_CHAR_COUNT, 0L); <br />
PopFileInitialize (hWnd); <br />
PopFontInitialize (_hWndEdit); <br />
// Register a custom message (for find and replace dialogs). <br />
_messageFindReplace = RegisterWindowMessage (FINDMSGSTRING); <br />
DoCaption (hWnd, _szTitleName); </ p>
<p> return 1; <br />
} </ p>
<p> LRESULT <br />
CALLBACK <br />
EditSubWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
switch (message) <br />
{<br />
case WM_LBUTTONUP: // Left mouse button release. <br />
SetStatusText (_hWndEdit, _hWndStatus); <br />
break; <br />
/ * case EM_LINEFROMCHAR: <br />
{<br />
TCHAR szBuffer [MAX_PATH]; <br />
wsprintf (szBuffer, TEXT ("% d"), wParam); <br />
MessageBox (NULL, szBuffer, NULL, MB_OK); <br />
} <br />
break; <br />
* / <br />
} <br />
return CallWindowProc (_wpOrigEditProc, hWnd, message, wParam, lParam); <br />
/ * <br />
int ich = -1; <br />
int iv; </ p>
<p> iv = SendMessage (_hWndEdit, EM_LINEFROMCHAR, wParam, 0); <br />
wsprintf (szBuffer, TEXT ("% d"), iv); <br />
MessageBox (NULL, szBuffer, NULL, MB_OK); </ p>
<p> return 1; * / <br />
} </ p>
<p> LONG <br />
OnSize (HWND hWnd, UINT wMsg, UINT wParam, LONG lParam) <br />
{<br />
RECT rect; <br />
LONG cy; </ p>
<p> GetClientRect (_hWndStatus, & rect); // Get the rectangular size of the status bar window. <br />
cy = rect.bottom-rect.top; // Calculate the rectangular width of the status bar window. </ p>
<p> MoveWindow (_hWndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam)-cy, TRUE); <br />
SendMessage (_hWndStatus, WM_SIZE, wParam, lParam); <br />
return 1; <br />
} </ p>
<p> LONG <br />
OnSetFocus (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
SetFocus (_hWndEdit); <br />
return 1; <br />
} </ p>
<p> LONG <br />
OnClose (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
if (_bNeedSave && IDCANCEL == AskAboutSave (hWnd, _szTitleName)) return 0; <br />
return DestroyWindow (hWnd); <br />
} </ p>
<p> LONG <br />
OnDestroy (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
PopFontDeinitialize (); // Delete the font. <br />
PostQuitMessage (0); <br />
return 1; <br />
} </ p>
<p> // Process Command message. <br />
LONG <br />
OnAbout (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
DialogBox (_hInst, TEXT ("AboutBox"), hWnd, AboutDlgProc); <br />
return 1; <br />
} </ p>
<p> LONG <br />
OnLineWrap (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
SendMessage (_hWndEdit, EM_LINEFROMCHAR, (WPARAM) 1, 0); </ p>
<p> return 1; <br />
} </ p>
<p> LONG <br />
OnFileNew (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
if (_bNeedSave && IDCANCEL == AskAboutSave (hWnd, _szTitleName)) <br />
return 0; </ p>
<p> SetWindowText (_hWndEdit, TEXT ("/ 0")); // Clear the title bar text. <br />
_szFileName [0] = TEXT ('/ 0'); // Simple empty string. <br />
_szTitleName [0] = TEXT ('/ 0'); <br />
DoCaption (hWnd, _szTitleName); <br />
_bNeedSave = FALSE; </ p>
<p> return 1; <br />
} </ p>
<p> LONG <br />
OnFileOpen (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
if (_bNeedSave && IDCANCEL == AskAboutSave (hWnd, _szTitleName)) <br />
return 0; </ p>
<p> if (PopFileOpenDlg (hWnd, _szFileName, _szTitleName)) <br />
{<br />
if (! PopFileRead (_hWndEdit, _szFileName)) <br />
{<br />
OkMessage (hWnd, TEXT ("Cannot open file% s!"), _SzTitleName); <br />
_szFileName [0] = TEXT ('/ 0'); <br />
_szTitleName [0] = TEXT ('/ 0'); <br />
} <br />
} <br />
DoCaption (hWnd, _szTitleName); <br />
_bNeedSave = FALSE; </ p>
<p> return 1; <br />
} </ p>
<p> LONG <br />
OnFileSave (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
if (_szFileName [0]) <br />
{<br />
if (PopFileWrite (_hWndEdit, _szFileName)) <br />
{<br />
_bNeedSave = FALSE; <br />
return 1; <br />
} <br />
else <br />
{<br />
OkMessage (hWnd, TEXT ("Cannot save% s"), _szTitleName); <br />
} <br />
} <br />
return OnFileSaveAs (hWnd, message, wParam, lParam); <br />
} </ p>
<p> LONG <br />
OnFileSaveAs (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
if (PopFileSaveDlg (hWnd, _szFileName, _szTitleName)) <br />
{<br />
DoCaption (hWnd, _szTitleName); <br />
if (PopFileWrite (_hWndEdit, _szFileName)) <br />
{<br />
_bNeedSave = FALSE; <br />
return 1; <br />
} <br />
else <br />
{<br />
OkMessage (hWnd, TEXT ("Cannot save% s"), _szTitleName); <br />
} <br />
} <br />
return 0; <br />
} </ p>
<p> LONG <br />
OnEditFind (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
_hDlgModeless = PopFindDlg (hWnd); <br />
return 1; <br />
} </ p>
<p> LONG <br />
OnEditFindNext (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
if (_hDlgModeless! = NULL) <br />
{<br />
return PopFindNextText (_hWndEdit); <br />
} <br />
return 0; <br />
} </ p>
<p> LONG <br />
OnEditFindReplace (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
_hDlgModeless = PopReplaceDlg (hWnd); <br />
return 1; <br />
} </ p>
<p> LONG <br />
OnDataTime (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
TCHAR szBuffer [MAX_PATH]; <br />
SYSTEMTIME systemtime; </ p>
<p> GetLocalTime (& systemtime); <br />
wsprintf (szBuffer, TEXT ("% d:% d% d-% d-% d"), systemtime.wHour, <br />
systemtime.wMinute, systemtime.wYear, <br />
systemtime.wMonth, systemtime.wDay); </ p>
<p> return SendMessage (_hWndEdit, EM_REPLACESEL, TRUE, (LPARAM) szBuffer); <br />
} </ p>
<p> LONG <br />
OnAppExit (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
return SendMessage (hWnd, WM_CLOSE, wParam, lParam); <br />
} </ p>
<p> LONG <br />
OnFormatFont (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
if (PopFontChooseFont (hWnd)) <br />
PopFontSetFont (_hWndEdit); <br />
return 1; <br />
} </ p>
<p> LONG <br />
OnEditUndo (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
return SendMessage (_hWndEdit, WM_UNDO, 0, 0); <br />
} </ p>
<p> LONG <br />
OnEditCut (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
return SendMessage (_hWndEdit, WM_CUT, 0, 0); <br />
} </ p>
<p> LONG <br />
OnEditCopy (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
return SendMessage (_hWndEdit, WM_COPY, 0, 0); <br />
} </ p>
<p> LONG <br />
OnEditPaste (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
return SendMessage (_hWndEdit, WM_PASTE, 0, 0); <br />
} </ p>
<p> LONG <br />
OnEditClear (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
return SendMessage (_hWndEdit, WM_CLEAR, 0, 0); <br />
} </ p>
<p> LONG <br />
OnEditSelectAll (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
return SendMessage (_hWndEdit, EM_SETSEL, 0, -1); <br />
} </ p>
<p> LONG <br />
OnStatic (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
return 1; <br />
} </ p>
<p> void <br />
DoCaption (HWND hWnd, TCHAR * szTitleName) <br />
{<br />
// Set the form title bar. <br />
TCHAR szCaption [64 + MAX_PATH]; <br />
wsprintf (szCaption, TEXT ("% s-% s"), szTitleName [0]? szTitleName: UNTITLED, _szAppName); <br />
SetWindowText (hWnd, szCaption); <br />
} </ p>
<p> short <br />
AskAboutSave (HWND hWnd, TCHAR * szTitleName) <br />
{<br />
// About the save dialog. <br />
TCHAR szBuffer [64 + MAX_PATH]; <br />
int iRetum = 0; </ p>
<p> if (szTitleName [0] == TEXT ('/ 0')) <br />
{<br />
wsprintf (szBuffer, TEXT ("The text of the file% s has changed./nWant to save the file?"), UNTITLED); <br />
iRetum = MessageBox (hWnd, szBuffer, _szAppName, MB_YESNOCANCEL | MB_ICONQUESTION); <br />
if (iRetum == IDYES) <br />
{<br />
if (! SendMessage (hWnd, WM_COMMAND, IDM_FILE_SAVE_AS, 0)) <br />
iRetum = IDCANCEL; <br />
} <br />
} <br />
else <br />
{<br />
wsprintf (szBuffer, TEXT ("The text of the file% s has changed./nWant to save the file?"), szTitleName); <br />
iRetum = MessageBox (hWnd, szBuffer, _szAppName, MB_YESNOCANCEL | MB_ICONQUESTION); <br />
if (iRetum == IDYES) <br />
{<br />
if (! SendMessage (hWnd, WM_COMMAND, IDM_FILE_SAVE, 0)) <br />
iRetum = IDCANCEL; <br />
} <br />
} <br />
return iRetum; <br />
} </ p>
<p> void <br />
OkMessage (HWND hWnd, TCHAR * szMessage, TCHAR * szTitleName) <br />
{<br />
TCHAR szBuffer [64 + MAX_PATH]; <br />
wsprintf (szBuffer, szMessage, szTitleName [0]? szTitleName: UNTITLED); <br />
MessageBox (hWnd, szBuffer, _szAppName, MB_OK | MB_ICONEXCLAMATION); <br />
} </ p>
<p> BOOL <br />
CALLBACK <br />
AboutDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
switch (message) <br />
{<br />
case WM_INITDIALOG: <br />
return TRUE; <br />
case WM_CLOSE: <br />
EndDialog (hDlg, 0); <br />
return TRUE; <br />
} <br />
/ * case WM_COMMAND: <br />
switch (LOWORD (wParam)) <br />
{<br />
case IDOK: <br />
// case IDCANCEL: <br />
EndDialog (hDlg, 0); <br />
return TRUE; <br />
} <br />
break; * / <br />
return FALSE; <br />
} </ p>
<p> BOOL <br />
CreateEditText (HWND hWnd, WPARAM wParam, LPARAM lParam) <br />
{<br />
// Create edit control. <br />
_hWndEdit = CreateWindow (<br />
TEXT ("edit"), <br />
NULL, <br />
WS_CHILD | // Sub-form. <br />
WS_VISIBLE | // Display the window. <br />
WS_VSCROLL | // Vertical scroll bar. <br />
WS_HSCROLL | // The horizontal scroll bar. <br />
ES_LEFT | // Text is left aligned. <br />
ES_AUTOHSCROLL | // Automatic Scroll text horizontally. <br />
ES_AUTOVSCROLL | // Automatically scroll text vertically. <br />
ES_MULTILINE | // Multiline editing. <br />
ES_NOHIDESEL, // Do not hide the selected text when losing focus. <br />
0, 0, 0, 0, <br />
hWnd, <br />
(HMENU) ID_EDIT, <br />
((LPCREATESTRUCT) lParam)-> hInstance, NULL); </ p>
<p> if (! _ hWndEdit) return FALSE; </ p>
<p> return TRUE; <br />
} </ p>
<p> BOOL <br />
InitStatus (HWND hWnd) <br />
{<br />
RECT rect; <br />
int i, parts [NUMPARTS]; </ p>
<p> GetClientRect (hWnd, & rect); </ p>
<p> for (i = 1; i <= NUMPARTS; i ++) <br />
parts [i-1] = rect.right / NUMPARTS * i; </ p>
<p> _hWndStatus = CreateStatusWindow (WS_CHILD | WS_VISIBLE, NULL, hWnd, NULL); <br />
if (! _hWndStatus) return FALSE; </ p>
<p> return SendMessage (_hWndStatus, SB_SETPARTS, (WPARAM) NUMPARTS, (LPARAM) parts); <br />
} </ p>
<p> void <br />
SetStatusText (HWND hWndEdit, HWND hWndStatus) <br />
{<br />
// POINT point; <br />
long iLineCount; <br />
// long iLength; <br />
long iOffset; <br />
TCHAR szBuffer [MAX_LOADSTRING]; <br />
int iRow; </ p>
<p> // GetCaretPos (& point); <br />
// Get the current cursor position in the string. <br />
// iOffset = SendMessage (hWndEdit, EM_CHARFROMPOS, 0, MAKELPARAM (point.x, point.y)); </ p>
<p> // iLength = GetWindowTextLength (hWndEdit); // Get the length of the form text (excluding / 0 characters). </ p>
<p> SendMessage (hWndEdit, EM_SETSEL, (WPARAM) 0, (LPARAM) -1); // All the text is selected. </ p>
<p> iOffset = SendMessage (hWndEdit, EM_GETSEL, (WPARAM) 0, (WPARAM) 0); </ p>
<p> iLineCount = SendMessage (hWndEdit, EM_LINEFROMCHAR, (WPARAM) iOffset, (WPARAM) NULL); </ p>
<p> iRow = SendMessage (hWndEdit, EM_LINELENGTH, iLineCount, 0); <br />
/ * <br />
Note: Here you need to get the number of characters in the line where the caret is. There is no processing here. <br />
* / <br />
wsprintf (szBuffer, TEXT ("Ln:% d Col:% d,% d"), iLineCount, iOffset, iRow); </ p>
<p> SendMessage (hWndStatus, SB_SETTEXT, 1, (LPARAM) szBuffer); <br />
} </ p>
<p> void <br />
MessageOperationEdit (HWND hWndEdit, WPARAM wParam, BOOL * bNeedSave) <br />
{<br />
/ * <br />
Process Edit control message function. <br />
BOOL * bNeedSave text needs to save the mark. <br />
* / <br />
switch (HIWORD (wParam)) <br />
{<br />
case EN_UPDATE: // The content of edit control has been changed. <br />
* bNeedSave = TRUE; <br />
break; <br />
case EN_ERRSPACE: // Edit control operation has exceeded the middle. <br />
case EN_MAXTEXT: // Edit control runs beyond the middle when inserted. <br />
MessageBox (hWndEdit, TEXT ("Edit input has exceeded the space!"), <br />
_szAppName, MB_OK | MB_ICONSTOP); <br />
break; <br />
} <br />
}

 

Download the complete source code:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.