Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change
WndProc PROC hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
mov eax, uMsg
.IF eax == WM_INITDIALOG
.ELSEIF eax == WM_ERASEBKGND
mov eax, 1
ret
.ELSEIF eax == WM_PAINT
Invoke MyPaint, hWin
mov eax, 0
ret
; .
; .
; .
;
; Other windows messages as per normal
;
; .
; .
; .
.ELSE
Invoke DefWindowProc, hWin, uMsg, wParam, lParam
ret
.ENDIF
xor eax, eax
ret
WndProc ENDP
MyPaint PROC hWin:DWORD
LOCAL ps:PAINTSTRUCT
LOCAL rect:RECT
LOCAL framedrect:RECT
LOCAL hdc:HDC
LOCAL hdcMem:HDC
LOCAL hBufferBitmap:DWORD
LOCAL hBufferBitmapOld:DWORD
LOCAL hBrush:DWORD
LOCAL hBrushOld:DWORD
Invoke BeginPaint, hWin, Addr ps
mov hdc, eax ; get the dc for the painting
;----------------------------------------------------------
; Setup Double Buffering
;----------------------------------------------------------
Invoke GetClientRect, hWin, Addr rect ; Get dimensions of area to buffer
Invoke CreateCompatibleDC, hdc ; Create memory dc for our buffer
mov hdcMem, eax
Invoke CreateCompatibleBitmap, hdc, rect.right, rect.bottom ; Create bitmap of size that matches dimensions
mov hBufferBitmap, eax
Invoke SelectObject, hdcMem, hBufferBitmap ; Select our created buffer bitmap into our memory dc
mov hBufferBitmapOld, eax ; Save old buffer bitmap
;==========================================================
; Start of our painting here, all the stuff before is just
; the setup of the doublebuffer etc. The example shows
; painting the background a color, and framing a rectangle.
;==========================================================
;----------------------------------------------------------
; Paint background of window/control
;----------------------------------------------------------
Invoke GetStockObject, DC_BRUSH ; Get system DC Brush
mov hBrush, eax ; Save brush handle
Invoke SelectObject, hdcMem, hBrush ; Switch it into hdcMem
mov hBrushOld, eax ; Save old brush handle
Invoke SetDCBrushColor, hdcMem, 09EE0DBh ; RGB(219,224,158) ; Set color for FillRect
Invoke FillRect, hdcMem, Addr rect, hBrush ; Fill the rectangle
Invoke SelectObject, hdcMem, hBrushOld ; Switch back old brush handle
Invoke DeleteObject, hBrush ; Delete brush
;----------------------------------------------------------
; Paint a framed rectangle (outlined only)
;----------------------------------------------------------
Invoke CopyRect, Addr framedrect, Addr rect ; Make a copy of rect
add framedrect.left, 40 ; Adjust framedrect so
sub framedrect.right, 40 ; that it fits inside
add framedrect.top, 40 ; the main window rect
sub framedrect.bottom, 40
Invoke GetStockObject, DC_BRUSH ; Get system DC Brush
mov hBrush, eax ; Save brush handle
Invoke SelectObject, hdcMem, hBrush ; Switch it into hdcMem
mov hBrushOld, eax ; Save old brush handle
Invoke SetDCBrushColor, hdcMem, 04908B0h ; RGB(176,8,73) ; Set color for FrameRect
Invoke FrameRect, hdcMem, Addr framedrect, hBrush ; Frame the rectangle
Invoke SelectObject, hdcMem, hBrushOld ; Switch back old brush handle
Invoke DeleteObject, hBrush ; Delete brush
;==========================================================
; End of our painting, rest is just copying buffer back
; and tidying up.
;==========================================================
;----------------------------------------------------------
; Copy back to main hdc from hdcMem
;----------------------------------------------------------
Invoke BitBlt, hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY
;----------------------------------------------------------
; Finish Double Buffering & Cleanup
;----------------------------------------------------------
Invoke SelectObject, hdcMem, hBufferBitmapOld ; Switch back to old buffer bitmap before deleting
Invoke DeleteObject, hBufferBitmap ; Delete bitmap used for double buffering
Invoke DeleteDC, hdcMem ; Delete double buffer hdc
Invoke EndPaint, hWin, Addr ps
mov eax, 0
ret
MyPaint ENDP
Quote from: fearless on Today at 07:46:16 AMNice! did u use an offset at compile time to point to a function (offset to proc), or did u update the struct at runtime with the address of function?:Panel STRUCT 4lea eax, FuncInit
mov Foo.Init, eax
Foo_Init_Proto TYPEDEF PROTO dwParam1:DWORD, dwParam2:DWORD, dwParam3:DWORD
Foo_Init_Ptr TYPEDEF PTR Foo_Init_Proto
Foo STRUCT
Init Foo_Init_Ptr 0
Foo ENDS
Invoke Foo.Init, 1, 2, 3
lea ebx, Foo
Invoke [ebx].Foo.Init, 1, 2, 3
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
.data
user32 db 'user32.dll',0
function db 'MessageBoxA',0
caption db 'Hello!',0
message db 'MessageBoxA called via pointer',0
.data?
hLib dd ?
pMessageBox dd ?
.code
start:
invoke LoadLibrary,ADDR user32
mov hLib,eax
invoke GetProcAddress,eax,ADDR function
mov pMessageBox,eax
mov edx,pMessageBox
invoke pr4 PTR edx,0,ADDR message,\
ADDR caption,0
invoke FreeLibrary,hLib
invoke ExitProcess,0
END start
mov edx,pMessageBox
invoke pr4 PTR edx,0,ADDR message,\
ADDR caption,0
ArgCount MACRO number
LOCAL txt
txt equ <typedef PROTO :DWORD>
REPEAT number - 1
txt CATSTR txt,<,:DWORD>
ENDM
EXITM <txt>
ENDM
pr0 typedef PROTO
pr1 ArgCount(1)
pr2 ArgCount(2)
.
.
pr24 ArgCount(24)
pr25 ArgCount(25)
invoke pr3 PTR ecx,param1,param2,param3