News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

color of button

Started by Sturgeon, December 07, 2006, 12:13:37 PM

Previous topic - Next topic

Darrel

Just tested it with your code and it doesn't work. Will read up on it a little later.

ToutEnMasm

Hello,
the WM_CTLCOLORSTATIC message is only for STATIC controls , not for buttons and didn't work in that case.
To have a 3d look button , just run the button generator , check the raised rectangle box,select the BS_OWNERDRAW style and copy the producted code in your sample,it work.

If you want a button with rounded border,you can interest youself with "region",there is a sample in MSDN.
                                                        ToutEnMasm

Darrel

Here is what I threw together to display a green button with black text.

[attachment deleted by admin]

ToutEnMasm

Hello,
Best and more simple way to create a special look button is to use an icon.
There is plentyfull of them in the web.
The icon can be in a single color and can be made easily.
Here is a sample.

;create it with BS_ICON style
.data
bouton db "BUTTON",0
Hicone1 dd 0
hButCtrl dd 0
.code
invoke LoadIcon,hInstance,ID_BUTTON
mov Hicone1,eax

invoke CreateWindowEx,0,ADDR bouton,NULL,WS_CHILD or WS_VISIBLE or BS_ICON,
PosX,PosY,Largeur,Hauteur,hWnd,NULL,hInstance,NULL
mov hButCtrl,eax ;se retrouve dans le lparam de WM_COMMAND

invoke SendMessage,hButCtrl,BM_SETIMAGE,IMAGE_ICON,Hicone1
;with two images
;uMsg == WM_LBUTTONUP message BM_SETIMAGE
;uMsg == WM_LBUTTONDOWN message BM_SETIMAGE

six_L

#19
hey,Sturgeon

what all of them told you isn't color button. it's the bmp or ico button.

do you remember the BELCODER? he told you a correct method about color button.
here is his code.

until now, the button demo in "XXCONTROLs" is best.
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include \masm32\macros\macros.asm
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
DrawItem PROTO :HWND,:LPARAM
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
ClassButName db "Button",0
ClassName db "SimpleWinClass",0
AppName db "Our First Window",0
ButtonText1 db "&Msg",0
ButtonText2 db "&Exit",0
hbrBtnBrush dd 0
IDC_MSG equ 403
IDC_EXIT equ 404

CR_BACKGROUND equ 0ff00ffh
CR_FOREGROUND equ 0ff00h
CR_HIGHLIGHT equ 0ffh

CR_INPUT equ 0ff0000h
CR_INPUT2 equ 0FFffh
szCaption db "Color Button Demo",0
szMsg db "Please pay attention to 'MSG' Button on Clicking.",0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hBgColor HBRUSH    ?
hFgColor HBRUSH    ?
hInColor HBRUSH    ?
hIn2Color HBRUSH    ?
hEdge HPEN      ?
hEdge2 HPEN      ?
; Font & text
BoldFont LOGFONT   <?>
sBtnText TCHAR     16 dup(?)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code     
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
invoke GetModuleHandle, NULL
mov    hInstance,eax
invoke GetCommandLine
mov    CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

mov   wc.cbSize,SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra,NULL
mov   wc.cbWndExtra,NULL
push  hInstance
pop   wc.hInstance
mov   wc.hbrBackground,COLOR_WINDOW+1
mov   wc.lpszMenuName,NULL
mov   wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov   wc.hIcon,eax
mov   wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov   wc.hCursor,eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,0,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,400,300,260,120,NULL,NULL,\
hInst,NULL
mov   hwnd,eax
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov     eax,msg.wParam
ret
WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.IF uMsg==WM_CREATE
;---------------------------------------------------------------------
; Create brushes for custom colors
invoke CreateSolidBrush, CR_BACKGROUND
mov hBgColor, eax

invoke CreateSolidBrush, CR_INPUT
mov hInColor, eax

invoke CreatePen, PS_INSIDEFRAME, 2, CR_FOREGROUND
mov hEdge, eax
invoke CreatePen, PS_INSIDEFRAME, 2, CR_INPUT2
mov hEdge2, eax
;---------------------------------------------------------------------
INVOKE CreateWindowEx,WS_EX_LEFT,ADDR ClassButName,ADDR ButtonText1,\
WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT OR BS_OWNERDRAW or WS_CLIPCHILDREN,\
30,30,80,30,hWnd, IDC_MSG, hInstance, NULL

INVOKE CreateWindowEx,WS_EX_LEFT,ADDR ClassButName,ADDR ButtonText2,\
WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT OR BS_OWNERDRAW ,\
140,30,80,30,hWnd, IDC_EXIT, hInstance, NULL

.elseif uMsg == WM_COMMAND
.if wParam ==  IDC_EXIT
invoke SendMessage, hWnd, WM_CLOSE, 0, 0
.elseif wParam ==  IDC_MSG
invoke MessageBox,hWnd,addr szMsg,addr szCaption,MB_OK
.endif

;.elseif uMsg == WM_CTLCOLORDLG
; mov eax, hBgColor
; ret
 
.elseif uMsg == WM_DRAWITEM
invoke DrawItem, hWnd, lParam
invoke DrawItem, hWnd, lParam

.ELSEIF uMsg==WM_DESTROY

;---------------------------------------------------------------------
; Restore the memory used for graphic objects
invoke DeleteObject, hEdge
invoke DeleteObject, hInColor
invoke DeleteObject, hIn2Color
invoke DeleteObject, hFgColor
invoke DeleteObject, hBgColor
;---------------------------------------------------------------------
invoke PostQuitMessage,NULL
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DrawItem PROC uses esi hWnd:HWND,lParam:LPARAM

mov esi, lParam
assume esi: ptr DRAWITEMSTRUCT

;buttons color
invoke SelectObject, [esi].hdc, hInColor

;frame color
.if [esi].itemState & ODS_SELECTED
invoke SelectObject, [esi].hdc, hEdge2
.else
invoke SelectObject, [esi].hdc, hEdge
.endif

invoke FillRect, [esi].hdc, ADDR [esi].rcItem, hBgColor
invoke RoundRect, [esi].hdc, [esi].rcItem.left, [esi].rcItem.top, [esi].rcItem.right, [esi].rcItem.bottom, 6, 6

.if [esi].itemState & ODS_SELECTED
invoke OffsetRect, ADDR [esi].rcItem, 1, 1
.endif

; Write the text
invoke GetDlgItemText, hWnd, [esi].CtlID, ADDR sBtnText, SIZEOF sBtnText
invoke SetBkMode, [esi].hdc, TRANSPARENT

;textcolor
.if [esi].itemState & ODS_SELECTED
invoke SetTextColor, [esi].hdc, CR_INPUT2
.else
invoke SetTextColor, [esi].hdc, CR_HIGHLIGHT
.endif

invoke DrawText, [esi].hdc, ADDR sBtnText, -1, ADDR [esi].rcItem, DT_CENTER or DT_VCENTER or DT_SINGLELINE

.if [esi].itemState & ODS_SELECTED
invoke OffsetRect, ADDR [esi].rcItem, -1, -1
.endif

; Draw the focus rectangle
.if [esi].itemState & ODS_FOCUS
invoke InflateRect, ADDR [esi].rcItem, -3, -3
;INVOKE DrawFocusRect, [esi].hdc, ADDR [esi].rcItem
.endif
assume esi:nothing

mov eax, TRUE
ret
DrawItem ENDP
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

end start

[attachment deleted by admin]
regards

Sturgeon

#20
Thanks to all. For this i used "BmpButton". But my problem in that I want to useĀ  WM_CTLCOLORBTN. Is it realy?