Maybe you need a special Edit to limit the input of floating point, but existing Edit can't complete this work - because it can only limit case or pure numbers. When you ask for help on the forum, a netizen tells you: "Usage." You may have a series of questions while seeing the front line of dawn: What is the child? What is the principle of subclass? How to achieve subclass? Let me start from a simple C program, step down on your doubt. First of all, I list the following C programs: #include
This process is roughly as follows: WndProc OldProc; OldProc = (WndProc) Setwindowslong (hwnd, gwl_wndproc, (long) newProc); of course, the new window process newProc is pre-implemented in advance. After the above code is executed, the system will first enter the newProc callback process you implemented, and then after processing the message you interested, go back to the original. Complete the remaining work during the callback process. The above is the principle analysis of the window subclass. Here I actually explain how to subclassify the window through an example. The interface of this example is as follows:
The edit box above the interface is used to limit floating point input, and below is a normal hyperlink. Ok, let me start to complete the subclass of these two windows by step: First step, save the original window process when the main window dialog is initialized, and set the new window process. Code is as follows: case WM_INITDIALOG: EditProc = (WNDPROC) SetWindowLong (GetDlgItem (hDlg, IDC_EDIT), GWL_WNDPROC, (LONG) ProcFloat); StaticProc = (WNDPROC) SetWindowLong (GetDlgItem (hDlg, IDC_ST_HOMEPAGE), GWL_WNDPROC, (LONG) ProcLink); Break; Step 2, Floating Point Editing Floating Window Process: LRESULT CALLBACK Procfloat (HWND HWND, UINT MSG, WPARAM WPARAM, LPARAM LPARAM) {IF (MSG == WM_CHAR && WPARAM! = '.' && (WPARAM <= '0' || WPARAM> = '9') && WParam! = VK_BACK) {MessageBeep (MB_OK); Return 0;} else Return CallWindowProc (EditProc, HWND, MSG, WPARAM, LPARAM);} What to explain here is, Due to the requirements of the control itself, just intercept a message, it is the WM_CHAR that receives characters. When the character entered by the user is not a decimal point, 0 ~ 9, and the backup key (notice not to have a retracted key, otherwise you will find that your edit box cannot delete the incorrect number), send a sound to prompt input error. As for other messages, the original callback function is called. A third step of the process of implementing the window hyperlink: LRESULT CALLBACK ProcLink (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {switch (Msg) {case WM_SETCURSOR: SetCursor (LoadCursor (NULL, IDC_HAND)); break; case WM_LBUTTONDOWN : Shellexecute (NULL, "Open", "http://home.ncust.edu.cn/ ~titilima", null, null, sw_shownormal; break; default: Return CallWindowProc (staticproc, hwnd, msg, wparam, lparam) This code is easy to understand: It has completed two things, one is to set the cursor pointer as a hand shape (note: For the earlier Windows system, there is no predefined IDC_HAND pointer, this time you You need to draw a hand pointer yourself in the exe, such as the hand pointer in Delphi is drawn by yourself). Second, when you click the left mouse button, open the web link you want to open.
In fact, for the hyperlink, it is more important to implement in subclass - it is its font color (note this code is implemented during the callback process of the main window dialog): Case WM_CTLCOLORSTATIC: IF GetDlgItem (hDlg, IDC_ST_HOMEPAGE) == (HWND) lParam) {SetTextColor ((HDC) wParam, 0xff0000); SetBkMode ((HDC) wParam, TRANSPARENT); return (LRESULT) CreateSolidBrush (GetSysColor (COLOR_BTNFACE));} break; further There are a few points to explain: 1. Your static hyperlink must have a unique resource ID, such as my Idc_st_homepage, so you can use getDlgitem to get its handle to complete subclasses; 2, you must It sets the SS_NOTIFY style to ensure that it can inform the parent window dialog when clicking it; Realize this. About Win32 window subcatenation is introduced here, you can click here to download the supporting source code of this article, in detail in the code.