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?
Thanks
Jp
Thanks
Jp
Oh... duh,
I figured it out, the class name of each button should have been "button" instead of my own name
JP
I figured it out, the class name of each button should have been "button" instead of my own name
JP
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:
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.
WS_CHILD+WS_VISIBLE+1
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?
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW
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:
The Win32 API documentation for GetMessage() goes into more detail about this
issue.
regards,
Boggy
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
.endif
[...]
;
; 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 lpMsgBuf:LPVOID
LOCAL error_id:DWORD
invoke GetLastError
mov error_id, eax
invoke FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or \
FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_id, \
(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."), \
SADD ("Error"), MB_ICONERROR
.else
invoke MessageBox, NULL, lpMsgBuf, SADD ("GetLastError"), MB_ICONERROR or MB_OK
invoke LocalFree, lpMsgBuf
.endif
ret
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.
WS_CHILD+WS_VISIBLE+1
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?
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW
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:
StartLoop:
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
.else
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
.endif
ExitLoop:
The Win32 API documentation for GetMessage() goes into more detail about this
issue.
regards,
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.
The program took about 5 mins to put together, that's all, i appreciate the help though.
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.
Happy New Year.