Question

I'm trying to write an ASM version of a Java app I developed recently, as a project in Win32 ASM, but as the title states, I'm having problems with GdiGradientFill; I'd prefer, for the moment, to use FASM, and avoid higher level ASM constructs, such as INVOKE and the use of the WIN32 includes.

What I have, atm:

PUSH    [hWnd]                                                  
CALL    [User32.GetWindowDC]                                
MOV     [hDC], EAX                          
PUSH    rectClient                              
PUSH    [hWnd]                          
CALL    [User32.GetClientRect]  

PUSH    [rectClient.left]
POP     [colorOne.xPos]
PUSH    [rectClient.top]
POP     [colorOne.yPos] 
MOV     [colorOne.red],     0xC000
MOV     [colorOne.green],   0xC000
MOV     [colorOne.blue],    0xC000
MOV     [colorOne.alpha],   0x0000

PUSH    [rectClient.right]
POP     [colorTwo.xPos]
PUSH    [rectClient.bottom]
POP     [colorTwo.yPos] 
MOV     [colorTwo.red],     0x0000
MOV     [colorTwo.green],   0x2800
MOV     [colorTwo.blue],    0x7700
MOV     [colorTwo.alpha],   0x0C00

MOV     [gRect.UpperLeft],  0
MOV     [gRect.LowerRight], 1

PUSH    GRADIENT_FILL_RECT_H                            
PUSH    1                               
PUSH    gRect                               
PUSH    2                           
PUSH    colorOne                            
PUSH    [hDC]                               
CALL    [GDI32.GdiGradientFill]

However, the code returns only a FALSE, and after going through both MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/dd373585(v=vs.85).aspx)

and some other examples (http://www.asmcommunity.net/board/index.php?topic=4100.0), I still can't see what I am doing wrong, can anyone see the flaw here?

An additional problem has been with my attempts to use Msimg32's GradientFill, as this always leads to a crash, however, I have seen some reports that Win2K+ OS's simply pass the parameters from Msimg32 to GDI32; is this accurate, or has anyone else experienced problems with this form?

Pastebin link for whole code: http://pastebin.com/GEHDw6Qe

Thanks for any help, SS

EDIT: Code is now working, honestly, I have no idea what has changed, I can't see anything different between the previous and now working data, other than changing the PUSH / POP sequence to MOV EAX, [rectClient.left], ect (The PUSH / POP method works, also) - Many thanks to those who offered assistance!

Was it helpful?

Solution

You're passing what looks like a RECT as the 4th parameter to GdiGradientFill. The function expects a GRADIENT_TRIANGLE.

Also, PUSH/POP is a very weird way to copy from one memory location to another. You're doing 4 memory accesses instead of two. Copy via a register; this is not Java.

Are you sure GetWindowDC is what you need? That one returns the DC for the whole window, title and border and all. For just the client area, people normally use GetDC(). When done, call ReleaseDC().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top