News:

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

Main Menu

Recent posts

#1
Windows API / Re: I don't know where to star...
Last post by Honzik2005 - Today at 08:40:56 AM
Thanks so much! I'm going to see if I can get this to work
#2
Windows API / Re: I don't know where to star...
Last post by fearless - Today at 08:20:36 AM
You can override the handling of the painting in the main window or a window you create yourself. For the main window, something like the following:

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

Then in your MyPaint function you can setup doublebuffering and draw stuff to the window, for example:

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


#3
The Campus / Re: invoking an offset procedu...
Last post by LordAdef - Today at 07:57:32 AM
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?:


lea eax, FuncInit
mov Foo.Init, eax

Panel STRUCT 4
    hdc     dd  ?
    init    proc_Ptr  ?  <------- here
Panel ends


I use offset:
mov panel1.init, offset test_proc

calling:
invoke panel1.init, 10

#4
The Campus / Re: invoking an offset procedu...
Last post by fearless - Today at 07:46:16 AM
Nice! 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?:


lea eax, FuncInit
mov Foo.Init, eax
#5
The Campus / Re: invoking an offset procedu...
Last post by LordAdef - Today at 07:34:36 AM
Hi Fearless,

It worked beautifully!!!

Thank you so much. Saved the day!

Thanks everyone for chiming in too!
#6
Windows API / I don't know where to start wi...
Last post by Honzik2005 - Today at 06:50:14 AM
I'm new to MASM as well as the Windows API, and I want to find out how to make some very simple 2D graphics in order to make a very simple game. I'm getting the hang of assembly on its own, but I'm having a hard time doing anything related to the Windows API.

Really, all I need to do is open a window, have some way of writing individual pixels (or maybe simple shapes) to certain locations on a back buffer, and then move that back buffer to the front buffer so that the graphics are displayed. That's it - I want to handle everything else. I could be wrong, but from what I can tell, Windows GDI is the simplest way of accomplishing this.

I've been looking for half a week, but I haven't really found anything helpful online. I've found a couple of Windows GDI examples in C, but I don't actually have any experience with C, so I have no idea how to reverse engineer them and translate them to MASM code. It also doesn't help that the examples aren't as simple as they could possibly be, so it's hard for me to figure out what part of the code does what and why.

I tried looking through the Windows GDI documentation, but that hasn't really cleared anything up. Maybe there's some prerequisite knowledge that I'm missing.

I really don't know where to start.
#7
The Campus / Re: invoking an offset procedu...
Last post by fearless - Today at 06:36:47 AM
Declare your struct with defined pointers, which point to prototypes, like so:

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

Then

Invoke Foo.Init, 1, 2, 3
or

lea ebx, Foo
Invoke [ebx].Foo.Init, 1, 2, 3

Also, remember to update the Foo struct with address of Init at run time,  before calling it, or you can try setting it to an offset at compile time (not tried that myself)
#8
The Campus / Re: invoking an offset procedu...
Last post by Vortex - Today at 06:04:15 AM
Hi LordAdef,

You can try this one :

.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

edx holds the pointer to MessageBoxA, you can specify the prX macro to call a function through a register.

Reading \masm32\include\windows.inc :

    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)

If you want to call a function taking three parameters :

invoke  pr3 PTR ecx,param1,param2,param3
#9
The Campus / Re: invoking an offset procedu...
Last post by Villuy - Today at 05:45:12 AM
invoke must have name of proc to check params. No way.
#10
Miscellaneous Projects / Re: ScratchPad
Last post by jimg - Today at 04:20:15 AM
Yes, thanks.