is there a way to define a skinned button in a res file? Cause I'm using a dialog as a main window and the other tutorials on skinning buttons are confusing me..
Posted on 2003-06-07 00:40:33 by EEDOK
nvm found it, I'll put it here though to show ppl how it was done..

you put this under WM_INITDIALOG
invoke BmpButton,hWin,X,Y,(ID of bitmap when not pressed),(ID of button pressed),(wParam sent when clicked)

and under WM_COMMAND you put whatever you set the wparam value to and put the functions there
Posted on 2003-06-07 00:57:08 by EEDOK
BmpButton is part of the MASM32 library, it is not a feature of the API so be sure to include the MASM32 library when you use it.

include masm32.inc
includelib masm32.lib
Posted on 2003-06-07 02:38:50 by donkey
Well I got another question, is there a way other than blindly guessing, to find out the X and Y values of where the button is supposed to go?
Posted on 2003-06-07 03:12:48 by EEDOK
I used to include a little static that I put the x/y mouse co-ordindates in. Probably don't have the code any more though it is easy enough to do. Just process the WM_MOUSEMOVE message, convert he co-ordinates to ansi then put them in a static control:
.elseif uMsg==WM_MOUSEMOVE

mov eax,lParam
push eax
movzx edx,ax
invoke dw2a, edx, ADDR buffer
invoke SendDlgItemMessage, hDlg, XStaticID, WM_SETTEXT, 0, ADDR buffer
pop eax
shr eax,16
movzx edx,ax
invoke dw2a, edx, ADDR buffer
invoke SendDlgItemMessage, hDlg, YStaticID, WM_SETTEXT, 0, ADDR buffer
mov eax,FALSE ; be sure to process the mouse move
ret
Haven't tried this but it should work as is.
Posted on 2003-06-07 03:26:15 by donkey
I figured it out, every value I get from that is 66% larger than the value of the static in the res file..
Posted on 2003-06-07 14:16:39 by EEDOK
You're welcome.

The values in your res file are in dialog units not pixels. The 66% is just a coincidence based on your selected font's average character width and screen dpi. You could adapt the algo above to do the conversion but converting DlgUnits to pixels is a very complex task (search for hell and you'll find topics on the board :) ). If 66% works for you you can use it and it probably won't present any problems.
Posted on 2003-06-07 14:53:06 by donkey
Is there a way to do this with jpg's instead of bitmaps to reduce the filesize by like 80%?
Posted on 2003-06-08 18:00:08 by EEDOK
yes
Posted on 2003-06-08 19:07:50 by donkey
can you give me hints on how to do it, or direct me to an API guide that contains it, cause the one I got doesn't even have BmpButton..
Posted on 2003-06-08 19:09:17 by EEDOK
In the MASM32 library

BitmapFromResource proc hModule:DWORD, lpName:DWORD

Description
BitmapFromResource returns a bitmap handle from a program resource.
An image may be in either .bmp, .gif, .jpg, or .wmf format


In the rc file:

999 IMAGE DISCARDABLE PICTURE.JPG
Posted on 2003-06-08 19:16:46 by donkey
cool where is the Masm library?

EDIT: AHHH just tryed assembling it and when I went to link it, the link program had a large amount of errors most of them looked something like this:
unresolved external symbol then having stuff like _CoTaskMemAlloc or _CreateCompatibleBitmap@12
Posted on 2003-06-08 19:19:42 by EEDOK
BmpButton is part of the MASM32 library, it is not a feature of the API so be sure to include the MASM32 library when you use it.

include masm32.inc
includelib masm32.lib
In your MASM32\Help folder you will find a help file called MASMLIB.HLP that will explain the functions to you. BTW we generally say thank you here. That was the idea behind the "You're Welcome" in an earlier post and the same in david's "You're welcome" in another thread. Some have noted that you seem just to ask and not thank people for their efforts, I'm weak by nature so I answered you anyway ;)

Be sure to include the ole32.inc and it's lib:

include ole32.inc
includelib ole32.lib
Posted on 2003-06-08 19:35:33 by donkey
BTW we generally say thank you here
whoa good idea, Btw Donkey did I ever mention you're the most helpful person I've seen on the internet? And does brown nosing work the same way as thanking?
Posted on 2003-06-08 19:41:07 by EEDOK
Works for me, but it is only polite to thank the people who help you. We are not required to spend our time solving other peoples problems.

These are the libs that are used by BitmapFromResource as far as I could tell, make sure they are included in your program:

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\comctl32.inc
include \masm32\include\ole32.inc
include \masm32\include\oleaut32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\oleaut32.lib
Posted on 2003-06-08 19:47:17 by donkey
k thx got it working, cept now the buttons don't show up :confused: here's a snippet of code:


.if uMsg == WM_INITDIALOG
invoke BitmapFromResource, hInstance, 174
mov Set,eax
invoke BitmapFromResource, hInstance, 173
mov Set2,eax
invoke BmpButton,hWin,92,37,addr Set,addr Set2,500
invoke BmpButton,hWin,575,37,addr Set,addr Set2,600
j/w is this the correct way?

EDIT:Would BitmapFromMemory maybe work instead?
Posted on 2003-06-08 19:53:24 by EEDOK
I don't use either function but I would assume that because the BitMapFromButton routine probably stores the bitmap handles in the extra class memory you would not pass the address but the actual handle value.

Hang on, I'll figure something out. Apparently it uses the resources themselves. I'll rewrite the proc fast and get back to you...
Posted on 2003-06-08 19:58:37 by donkey
Use this instead of BmpButton:
BmpButton2 proc hParent:DWORD,topX:DWORD,topY:DWORD,

hBmpU:DWORD,hBmpD:DWORD,ID:DWORD

; parameters are,
; 1. Parent handle
; 2/3 top X & Y co-ordinates
; 4/5 resource ID numbers or identifiers for UP & DOWN bitmaps
; 6 ID number for control

LOCAL hButn1 :DWORD
LOCAL hImage :DWORD
LOCAL hModule :DWORD
LOCAL wid :DWORD
LOCAL hgt :DWORD
LOCAL Rct :RECT
LOCAL wc :WNDCLASSEX

invoke GetModuleHandle,NULL
mov hModule, eax

jmp @F
Bmp_Button_Class db "Bmp_Button_Class",0
@@:

mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset BmpButnProc

mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, 16
push hModule
pop wc.hInstance
mov wc.hbrBackground, COLOR_BTNFACE+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset Bmp_Button_Class
mov wc.hIcon, NULL
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor, eax
mov wc.hIconSm, NULL

invoke RegisterClassEx, ADDR wc

invoke CreateWindowEx,WS_EX_TRANSPARENT,
ADDR Bmp_Button_Class,NULL,
WS_CHILD or WS_VISIBLE,
topX,topY,100,100,hParent,ID,
hModule,NULL

mov hButn1, eax

invoke SetWindowLong, hButn1, 0, hBmpU
invoke SetWindowLong, hButn1, 4, hBmpD

jmp @F
ButnImageClass db "STATIC", 0
@@:

invoke CreateWindowEx,0,
ADDR ButnImageClass,NULL,
WS_CHILD or WS_VISIBLE or SS_BITMAP,
0,0,0,0,hButn1,ID,
hModule,NULL

mov hImage, eax

invoke SendMessage, hImage, STM_SETIMAGE, IMAGE_BITMAP, hBmpU

invoke GetWindowRect, hImage, ADDR Rct
invoke SetWindowLong, hButn1, 8, hImage

mov eax, Rct.bottom
mov edx, Rct.top
sub eax, edx
mov hgt, eax

mov eax, Rct.right
mov edx, Rct.left
sub eax, edx
mov wid, eax

invoke SetWindowPos, hButn1, HWND_TOP, 0, 0, wid,hgt, SWP_NOMOVE

invoke ShowWindow, hButn1, SW_SHOW

mov eax, hButn1

ret

BmpButton2 endp
Posted on 2003-06-08 20:07:41 by donkey
You'll need this as well:
BmpButnProc proc hWin   :DWORD,

uMsg :DWORD,
wParam :DWORD,
lParam :DWORD

LOCAL hBmpU :DWORD
LOCAL hBmpD :DWORD
LOCAL hImage :DWORD
LOCAL hParent:DWORD
LOCAL ID :DWORD
LOCAL ptX :DWORD
LOCAL ptY :DWORD
LOCAL bWid :DWORD
LOCAL bHgt :DWORD
LOCAL Rct :RECT

.data
cFlag dd 0 ; a GLOBAL variable for the "clicked" setting
.code

.if uMsg == WM_LBUTTONDOWN
invoke GetWindowLong,hWin,4
mov hBmpD, eax
invoke GetWindowLong,hWin,8
mov hImage, eax
invoke SendMessage,hImage,STM_SETIMAGE,IMAGE_BITMAP,hBmpD
invoke SetCapture,hWin
mov cFlag, 1

.elseif uMsg == WM_LBUTTONUP

.if cFlag == 0
ret
.else
mov cFlag, 0
.endif

invoke GetWindowLong,hWin,0
mov hBmpU, eax
invoke GetWindowLong,hWin,8
mov hImage, eax
invoke SendMessage,hImage,STM_SETIMAGE,IMAGE_BITMAP,hBmpU

mov eax, lParam
cwde
mov ptX, eax
mov eax, lParam
rol eax, 16
cwde
mov ptY, eax

invoke GetWindowRect,hWin,ADDR Rct

mov eax, Rct.right
mov edx, Rct.left
sub eax, edx
mov bWid, eax

mov eax, Rct.bottom
mov edx, Rct.top
sub eax, edx
mov bHgt, eax

; --------------------------------
; exclude button releases outside
; of the button rectangle from
; sending message back to parent
; --------------------------------
cmp ptX, 0
jle @F
cmp ptY, 0
jle @F
mov eax, bWid
cmp ptX, eax
jge @F
mov eax, bHgt
cmp ptY, eax
jge @F

invoke GetParent,hWin
mov hParent, eax
invoke GetDlgCtrlID,hWin
mov ID, eax
invoke SendMessage,hParent,WM_COMMAND,ID,hWin

@@:

invoke ReleaseCapture

.endif

invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret

BmpButnProc endp
Posted on 2003-06-08 20:10:15 by donkey
I'm getting errors when I run link again:
_BmpButnProc@16 already defined in Project.obj

EDIT:Fixed this error by renaming BmpButnProc but I'm getting the same thing, the buttons still don't show :confused:

EDIT2:might as well mash this question into this topic seeing how it's related. In the car example in example9 of the masm directory it displays a jpg image, I can see where it loads up the image but I'm missing the part where it displays it, can you help me with my blindness?
Posted on 2003-06-08 20:16:41 by EEDOK