Hi guys I'm playing around with ownder drawn buttons, and i have no idea why they aren't showing up on my window, could someone take a look at it and tell me what's wrong?


Posted on 2001-12-30 05:08:55 by Asm_Freak
Oh... duh,

I figured it out, the class name of each button should have been "button" instead of my own name

Posted on 2001-12-30 05:20:38 by Asm_Freak
Hi Freak, just some advice and stylistic issues I'd like to take you up on.

invoke PostQuitMessage,NULL

PostQuitMessage() requires that you pass an int type,
so use 0 instead of NULL (S/390 :))

invoke CreateWindowEx, 0, addr Button1, addr Button1, WS_CHILD+WS_VISIBLE+1,
100, 100, 75, 45, hWnd, 2, hInstance, NULL

invoke CreateWindowEx, 0, addr Button2, addr Button2, WS_CHILD+WS_VISIBLE+1,
100, 200, 75, 45, hWnd, 3, hInstance, NULL

If you include sensible error handling in your code you can catch and diagnose
errors immediately (see the attachment). I would usually do something like:

invoke CreateWindowEx, ....

.if eax == NULL
invoke PrintErrorMsg


; Function : PrintErrorMsg()
; Conditions: None.
; Returns : None, just hope that it works. :)
; Protoype is PrintErrorMsg PROTO and requires some
; macros in the masm32 package
PrintErrorMsg proc
LOCAL error_id:DWORD

invoke GetLastError
mov error_id, eax

(SUBLANG_DEFAULT shl 10) or LANG_NEUTRAL, addr lpMsgBuf, 0, NULL

.if eax == 0
; you could do another GetLastError() + wsprintf to display the actual
; error id returned from FormatMessage()
invoke MessageBox, NULL, SADD ("Unable to format error message."), \
invoke MessageBox, NULL, lpMsgBuf, SADD ("GetLastError"), MB_ICONERROR or MB_OK
invoke LocalFree, lpMsgBuf

PrintErrorMsg endp

The code in PrintErrorMsg() is adapted from Microsoft, see the Win32 API
documentation for FormatMessage() to see the original example in C. There is
also the DBERROR library in the masm32 package under \masm32\DBERROR, you
can't sell or use it in commerical packages though.


Better to use or just in case you ever get two macros
that expand to the same value: 1 + 1 != 1 or 1

btw What is the "+1" for?

INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg

GetMessage() returns -1 if there was an error encountered. Your test doesn't
catch this error. So you might want to change your logic to something like:

invoke GetMessage,ADDR msg,NULL,0,0

.if eax == 0
je ExitLoop
.elseif eax == -1
; is the error fatal?
; let the user know and deal with it
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop

The Win32 API documentation for GetMessage() goes into more detail about this

Posted on 2001-12-30 23:18:33 by Boggy
I appreciate the help, it wasn't a serious program, the purpose of it was to demonstrate creation of buttons on the fly. I was studying a "reverse me" program, which obviously had no source and it used this method to create buttons, I wasn't quite sure how it worked, so i modified icz's tut 10-1 program accordinly to make these on the fly buttons work. +1 in the style means that it's a button, change it to 2,3,4... etc and you'll see that it changes from edit to radio.. and etc.

The program took about 5 mins to put together, that's all, i appreciate the help though.
Posted on 2001-12-31 03:05:49 by Asm_Freak
Hehe ok. But next time you create a button use one of the predefined BS_* styles instead of hardcoding numbers in your code--it helps readability.

Happy New Year.
Posted on 2001-12-31 06:25:36 by Boggy