Win32 assembly tutorial seven controls subclassification

zhaozj2021-02-08  272

-------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------- It is presented in C, but this concept is still applicable in Win32ASM, because the idea is like this: first assume a different attribute, when a new object is present, what is said Objects are somewhat different, while other properties are exactly the same, then in addition to handling this attribute, others can use the code of the previous object. In a specific application, I will give an example. For example, we define a "edit" control, then this control is confirmed by Windows, because its window process is inside the Windows system, but if we want to make a "Edit" control for syntax checking, in addition to the code of the grammatical check, have to write a lot of code to realize the old "Edit" control? The answer is of course negative. In fact, we can intercept the WM_CHAR message of a standard "edit" control, check the key to the key and proceed, the other messages can be passed to the original window process. Drawing as follows: Before childification: Windows => Edit control After subclass: Windows => Our process code => Edit control window Process There is a function in Windows API can be used to implement this Function, that is, SETWINDOWLONG PROTO HWND, NINDEX, DWNEWLONG, parameter means hwnd is the window handle you want to change, NINDEX is what properties we have to change the window, its value can be gwl_exstyle: change window style, GWL_WndProc: Settings Window The new process, this is exactly what we are interested, there is GWL_USERDATA this is a 32-bit data of the window custom. Dwnewlong is a new value, and an API is used to call the original window process, called CallWindWoproc Proto LpprevwndFunc, HWND, MSG, WPARAM, LPARAM. We have the following procedure when using: Set the address of our own code with setwindowlong, hwnd, gwl_wndproc, addr _newprocaddress, the API returns the original process address with setWindowlong, HWND, GWL_USERDATA, EAX to save the original process address in custom data in. In this way, all messages will be sent first to our process, then in our own process: the message to be processed, if the original process is not desired, then returns. For your own messages, call the original window procedure and return the return value.

The method is to remove the original process address saved in the custom data with Invoke GetWindowlong, HWnd, GWL_USERDATA, EAX, HWND, UMSG, WPARAM, LPARM, and LPARAM call the original process uint ustructsize} This section provides a source program, it is Implement the URL connection process of the text in the dialog, we see the text in some programs is blue, there is an underline, then the mouse moves to the above, just like the super knots in the browser, and press Go to the website, think about it, we don't have a standard control or API to implement such a feature, because this is first a text, so we can submit this text, handle its WM_LButtonup message To implement the function of the automatic connection to the website; process the WM_SETCURSOR message to make the mouse to change the cursor above, the specific source program is as follows: source program - resource file; >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>; ******************************************************* * # incrude; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> ICON 1000 begins; >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # define IDI_MAIN 1000 # DEFINE IDC_HANDLE 2000; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> Dialog box 3000; >>>>>>>>>>>>>>>>>>>>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>> # Define DLG_ABOUT 3000 # define id_email 3001 # define id_homepage 3002; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Folder; >>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>> Idi_main icon "main.ico" IDC_Handle Cursor "Handle.cur"; >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DLG_ABout Dialog Discardable 50, 50, 160, 30Style DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENUCAPTION "URL Joint Text Demo - BY Luo Yunbin" Font 9, "Song" BeGinltext "My Home:", -1, 5, 5, 54, 9lText "http: // Asm.yeah.Net ", ID_Homepage, 55, 5, 80, 9LText" My E-mail: ", -1, 5, 17, 54, 9ltext" Bigluo@telekbird.com.cn ", ID_EMAIL, 55, 17 , 95, 9nd source program - assembly source file; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>

>>>>>>>>>>>>>>>>>>>>>>> Folding code; >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Folder Luo Yunbin's programming park); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>> Folding information; window subcatenification demonstration VER 1.0; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>. 386.Model Flat, StdCallOption Casemap: None; Case Sensitive; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Folder >>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>> include windows.incinclude user32.incinclude kernel32.incinclude comctl32.incinclude comdlg32.incinclude shell32.incinclude gdi32.incincludelib user32.libincludelib kernel32.libincludelib comctl32.libincludelib comdlg32.libincludelib shell32.libincludelib gdi32.lib; >> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Folder Dialog - Aboutid_Email EQU 3001ID_HomePage EQU 3002; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

.DATA? HINSTANCE DD? HICON DD? SZBUFFER DB 256 DUP (?); >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | hpLinkProc Proto: DWORD,: DWORD,: DWORD,: DWORD;> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Subject = =! I like your program! ", 0.codeif debuginclude debug.asmendif; ************************************ *********************** [About the window program in the dialog box; *********************************************************** ****************** _ HYPERLINKPROC PROC HWND: DWORD, UMSG: DWORD, WPARAM: DWORD, LPARM: DWORDMOV EAX, UMSG.IF EAX == WM_LButtonUpinvoke getdlgctrlid, hwnd.if eax == ID_HOMEPAGEinvoke ShellExecute, 0,0, offset szHomePage, 0,0,0.elseif eax == ID_EMAILinvoke ShellExecute, 0,0, offset szEmail, 0,0,0.endif.elseif eax == WM_NCHITTEST; WM_NCHITTEST will return TRUE You can receive the mouse action, implement the function! MOV EAX, TrueRet.elseif EAX == WM_SETCURSORINVOKE SETCURSOR, HCURSORHANDLE.ELSEINVOKE GETWINDOWLONG, HWND, GWL _USERDATAINVOKE CALLWINDOWPROC, EAX, HWND, UMSG, WPARAM, LPARAMRET.ENDIFXOR EAX, EAXRET_HYPERLINKPROC ENDP; ********************************************* ************************************; dialog window main program;

*********************************************************** ***************** AboutDialogproc Proc Uses EBX EDI ESI, / HWND: DWORD, UMSG: DWORD, WPARAM: DWORD, LPARAM: DWORDLOCAL @stwindow: RectLocal @dwwidth: DWORD, @dwHeight: DWORDlocal @hWinTemp: DWORDlocal @stFont: LOGFONT, @ hFontOutput: DWORDmov eax, uMsg.if eax == WM_CLOSEinvoke EndDialog, hWnd, NULL.elseif eax == WM_INITDIALOGinvoke GetModuleHandle, NULLinvoke LoadCursor, eax, IDC_HANDLEmov hCursorHandle, eaxinvoke GetDlgItem, hWnd, ID_HOMEPAGEmov @ hWinTemp, eaxinvoke SetWindowLong, @ hWinTemp, GWL_WNDPROC, addr _HyperLinkProcinvoke SetWindowLong, @ hWinTemp, GWL_USERDATA, eaxinvoke GetDlgItem, hWnd, ID_EMAILmov @ hWinTemp, eaxinvoke SetWindowLong, @ hWinTemp, GWL_WNDPROC, addr _HyperLinkProcinvoke SetWindowLong, @ hWinTemp, GWL_USERDATA, eax .elseif eax == WM_CTLCOLORSTATICinvoke GetDlgCtrlID, lParam.if eax == ID_HOMEPAGE || eax == ID_EMAILinvoke SendMessage, lParam, WM_GETFONT, 0,0mov @ hFontOutput, eaxinvoke GetObject, @ hFontOutput, sizeof LOGFONT, addr @stFontmov @ stFont.lfUnderline, Truein voke CreateFontIndirect, addr @stFontmov @ hFontOutput, eaxinvoke SelectObject, wParam, eaxinvoke SetTextColor, wParam, Blueinvoke GetSysColor, COLOR_MENUinvoke SetBkColor, wParam, eaxinvoke DeleteObject, @ hFontOutput; ***************** *********************************************************** *; Note Always return the return value of the stockOject, otherwise the color cannot be displayed; ***************************** ************************************ Invoke getStockObject, hollow_brush.elsemov eax, falseret.endifret.else *********************************************************** *************; Note: After the message processing of the dialog box, return true, a message that is not processed; return false;

*********************************************************** ****************** MOV EAX, FALSERET.ENDIFMOV ENX, TRUERETABOUTDIALOGPROC ENDP; >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> start: invoke InitCommonControlsinvoke GetModuleHandle, NULLmov hInstance, eaxinvoke DialogBoxParam, hInstance, DLG_ABOUT, / NULL, offset AboutDialogProc, DLG_ABOUTinvoke ExitProcess, NULL; **** *********************************************************** ************* * End Start program analysis and points in the resource, we define two text boxes, ID_HomePage and ID_Email, in the initdialog message in the process of the main dialog, respectively we use GetDlgItem take their hWnd, then subclass, we have a new process is provided to _HyperLinkProc the invoke GetDlgItem, hWnd, ID_HOMEPAGEmov @ hWinTemp, eaxinvoke SetWindowLong, @ hWinTemp, GWL_WNDPROC, addr _HyperLinkProcinvoke SetWindowLong, @ hWinTemp, GWL_USERDATA, eaxinvoke GetDlgItem, hWnd, ID_EMAILmov @ hWinTemp, eaxinvoke SetWindowLong, @ hWinTemp, GWL_WNDPROC, addr _HyperLinkProcinvoke SetWindowLong, @ hWinTemp, GWL_USERDATA, eax then the new process, the detected W M_lbuttonup message (left mouse button release) Use the shellexecute API to connect to the website, detect WM_NCHITTEST to make the text control message message, detect the WM_SETCURSOR message set the cursor to hand shape, for these messages, there are no processes, Then use CallWindowProc to call the original process for processing.

转载请注明原文地址:https://www.9cbs.com/read-1450.html

New Post(0)