News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

CALLBACK function

Started by BugCatcher, August 26, 2020, 04:38:55 AM

Previous topic - Next topic

BugCatcher

I know I've seen an example of a call back function some where in the forum a while ago, but I can't find it. Any help?

Vortex

Hello,

A classical example is the API function enumerating all the top-level windows :

BOOL EnumWindows(
  WNDENUMPROC lpEnumFunc,
  LPARAM      lParam
);


lpEnumFunc

Type: WNDENUMPROC

A pointer to an application-defined callback function. For more information, see EnumWindowsProc.


https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumwindows

A quick example :
.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     \masm32\include\masm32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\masm32.lib


EnumWndProc PROTO :DWORD,:DWORD


.data

f1          db 'Window handle = %X , window title = %s',13,10,0

.data?

buffer      db 64 dup(?)
buffer2     db 512 dup(?)

.code

start:

    invoke  EnumWindows,ADDR EnumWndProc,0

    invoke  ExitProcess,0
   

EnumWndProc PROC hwnd:DWORD,lParam:DWORD

    invoke  GetWindowText,hwnd,ADDR buffer,64

    invoke  wsprintf,ADDR buffer2,ADDR f1,\
            hwnd,ADDR buffer
           
    invoke  StdOut,ADDR buffer2

    mov     eax,1

    ret

EnumWndProc ENDP


END start

BugCatcher


hutch--

If the type of callback is a subclass of a control, the MASM32 SDK has a tool for that task called surprisingly enough, "subclass.exe".

BugCatcher


TouEnMasm

There is three kind of Callback functions.
    * a simple proc  called  by a function (richedit streamread,streamwrite..)
    * an event loop installed by a subclass procedure (common controls)
    * an implemented interface (openfile...)

For each,you need to know what is the need of the function,msdn give you the needed information.
Fa is a musical note to play with CL

daydreamer

Quote from: hutch-- on August 26, 2020, 10:22:26 AM
If the type of callback is a subclass of a control, the MASM32 SDK has a tool for that task called surprisingly enough, "subclass.exe".
thanks I try that,need reorganize big wndproc,to several smaller parts
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

hutch--

magnus,

You need to know the correct form for different callback types. A WndProc() is a procedure that you never call directly, it calling address is done in the WNDCLASSEX structure that is used by a call to CreateWindowEx. A "subclass" is a specialised access to the message handling procedure of a control like a button or any of the others. It get access to the message data BEFORE the control does which allows you to modify the actions of the control.

This is not a creative area where you experiment, it is built into the structure of the operating system and you need to do them correctly to get them to work. WIN32.HLP is your friend here, the basic architecture has not changed since the first versions of NT.

TimoVJL

Are you after Small Window - DednDave, 4-2011


WndProc PROC    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
    mov     eax,uMsg
    .if eax==WM_CREATE
INVOKE  WMCreate, hWnd
    .elseif eax==WM_CLOSE
        INVOKE  WMClose, hWnd
jnz     @F
    .elseif eax==WM_DESTROY
        INVOKE  WMDestroy 
    .else
@@:     INVOKE  DefWindowProc,hWnd,uMsg,wParam,lParam
    .endif
    ret
WndProc ENDP

WMCreate PROC hWnd:HWND
    mov     eax,hWnd
    mov     hwndMain,eax
    xor     eax,eax
    ret
WMCreate ENDP

WMDestroy PROC
    INVOKE  PostQuitMessage,NULL
    xor     eax,eax
    ret
WMDestroy ENDP

WMClose PROC hWnd:HWND
    INVOKE  DestroyWindow,hWnd
    xor     eax,eax
    ret
WMClose ENDP
May the source be with you

Adamanteus

#9
  :eusa_boohoo: Good styled interface controls skeleton module, sure in my minimalistic style by luxury moderui button :

daydreamer

Quote from: hutch-- on August 28, 2020, 09:50:28 AM
magnus,

You need to know the correct form for different callback types. A WndProc() is a procedure that you never call directly, it calling address is done in the WNDCLASSEX structure that is used by a call to CreateWindowEx. A "subclass" is a specialised access to the message handling procedure of a control like a button or any of the others. It get access to the message data BEFORE the control does which allows you to modify the actions of the control.

This is not a creative area where you experiment, it is built into the structure of the operating system and you need to do them correctly to get them to work. WIN32.HLP is your friend here, the basic architecture has not changed since the first versions of NT.
I guess magnus.asm you made earlier with button subclassing is good example
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding