News:

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

checkbox background color

Started by azdps, May 19, 2009, 03:08:12 AM

Previous topic - Next topic

azdps

I've been looking around but can't find a way to change the background color of a checkbox from white to something else.

UtillMasm

attach your source, and i can try add something to your codes.

....

:'(i don't have that power.

travism

I believe you could handle the WM_CTLCOLORBTN message since it handles checkboxes also and use SetBkColor. Someone can correct me if im wrong.

azdps

.586
.model flat, stdcall
option casemap :none
     
   include        /masm32/include/windows.inc
   include        /masm32/include/kernel32.inc
   include        /masm32/include/user32.inc
   include        /masm32/include/comctl32.inc
   
   includelib     /masm32/lib/kernel32.lib
   includelib     /masm32/lib/user32.lib
   includelib     /masm32/lib/comctl32.lib
   
           
   WinMain        PROTO :DWORD,:DWORD,:DWORD,:DWORD
   WndProc        PROTO :DWORD,:DWORD,:DWORD,:DWORD
   TopXY          PROTO :DWORD,:DWORD
   
.data
   ClassName      db "Example",0
   CaptionText    db "Example",0
   ButtonClass    db "button",0
   txtTest        db "test",0 
       
.data?
   hWnd            HANDLE ?
   hInstance       HANDLE ?
   hCheckbox     HANDLE ?

.code
start:

   invoke GetModuleHandle, NULL     
   mov hInstance, eax
   invoke WinMain,hInstance,NULL,NULL,SW_SHOWDEFAULT
   invoke ExitProcess,eax

; ########################################################################

WinMain proc hInst:DWORD, hPrevIns:DWORD, CmdLine:DWORD, CmdShow:DWORD

   LOCAL  wc   :WNDCLASSEX
   LOCAL  msg  :MSG
   LOCAL  Wwd  :DWORD
   LOCAL  Wht  :DWORD
   LOCAL  Wtx  :DWORD
   LOCAL  Wty  :DWORD
   
   mov    wc.cbSize,       SIZEOF WNDCLASSEX
   mov    wc.style,        CS_HREDRAW + CS_VREDRAW
   mov    wc.lpfnWndProc,  OFFSET WndProc
   mov    wc.cbClsExtra,   NULL
   mov    wc.cbWndExtra,   NULL
   mov    eax,             hInstance
   mov    wc.hInstance,    eax
   invoke LoadIcon,        NULL,IDI_HAND
   mov    wc.hIcon,        eax
   mov    wc.hIconSm,      eax
   invoke LoadCursor,      NULL,IDC_ARROW
   mov    wc.hCursor,      eax
   mov    wc.hbrBackground,COLOR_BTNFACE+1
   mov    wc.lpszMenuName, NULL
   mov    wc.lpszClassName,OFFSET ClassName
   invoke RegisterClassEx, addr wc
   
   mov    Wwd, 200
   mov    Wht, 100
   
   invoke GetSystemMetrics,SM_CXSCREEN
   invoke TopXY,Wwd,eax
   mov    Wtx, eax
   
   invoke GetSystemMetrics,SM_CYSCREEN
   invoke TopXY,Wht,eax
   mov    Wty, eax
   
   invoke CreateWindowEx, 0,
                          ADDR ClassName,
                          ADDR CaptionText,
                          WS_OVERLAPPED + WS_SYSMENU + WS_MINIMIZEBOX  + WS_CAPTION,
                          Wtx,Wty,Wwd,Wht,
                          NULL,
                          NULL,
                          hInst,
                          NULL
   mov    hWnd,eax
   invoke ShowWindow,hWnd,SW_SHOWNORMAL
   invoke UpdateWindow,hWnd
   
   StartLoop:
      invoke GetMessage,ADDR msg,NULL,0,0
      cmp eax, 0
      je ExitLoop
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage,  ADDR msg
      jmp StartLoop
   ExitLoop:

      mov eax,msg.wParam
      ret
   
WinMain endp

; ###############################################################################################################################
WndProc proc hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

   .IF uMsg == WM_CREATE     
    invoke CreateWindowEx, 0,
                           addr ButtonClass,
                           addr txtTest,
                           WS_CHILD + WS_VISIBLE + BS_AUTOCHECKBOX,
                           60,30,100,20,
                           hWin,
                           0,
                           hInstance,
                           0
   mov hCheckbox,eax
                           

   .ELSEIF uMsg == WM_DESTROY
      invoke PostQuitMessage,NULL
   .ELSE
      invoke DefWindowProc,hWin,uMsg,wParam,lParam
      ret
   .ENDIF
      xor eax,eax
      ret

WndProc endp
;==============================================================
TopXY proc wDim:DWORD, sDim:DWORD
    shr sDim, 1
    shr wDim, 1
    mov eax, wDim
    sub sDim, eax
    ret
TopXY endp
;==============================================================
end start

[attachment deleted by admin]

UtillMasm

 :U
ok... i'm looking into your codes.

and... SetBkColor with WM_CTLCOLORBTN not work for 'button'.

travism

Oh I thought you were talking about the label, to change the label you need to handle WM_CTLCOLORSTATIC, but for the background of the checkbox part that is white, not even sure about that. Someone else might know sorry.

UtillMasm

no way to do that?

i give up. :wink

azdps

I haven't seen a working solution posted anywhere for checkboxes. Most posts I've seen say to use wm_ctlcolorbtn but I have yet to see an example that actually works.

MichaelW

Per the Microsoft documentation for the WM_CTLCOLORBTN message:
QuoteHowever, only owner-drawn buttons respond to the parent window processing this message.

An owner-drawn button is doable, but duplicating the functionality of the standard check box will require a substantial amount of code. You might be able to simplify the code somewhat by using predefined bitmaps, one for each button state, but it would still be a lot of effort just to change the background color.
eschew obfuscation

BATSoftware

The reason that the checkbox and radio button windows are always white is because they are hard coded bitmaps in the bowels of WINAPI. Though I no longer remember exactly where they are located, I beleive they are in USER.EXE and are NOT stored as
RT_BITMAPS either but hardcodeded.

For an enlightening look into how Windows actually draws the graphic portions of menus and buttons, refer to the API function
DRAWFRAMECONTROL. Inspection of this function will reveal the exact mentod used by Microcrap to draw button controls.
below is a code segment I once used to construct an "UNICODE on ANY Windows button control" which I developed. I no longer use the control since I determined a far more efficent and slicker way to make any button or static control "UNICODE all the time on any Windows OS" - that means Win95->Vistinka:

;       DRAW CHECKBOX
        MOV     EAX,DFCS_BUTTONCHECK OR DFCS_BUTTON3STATE OR DFCS_CHECKED
        TEST    STATE,BST_INDETERMINATE
        JNZ     @F
;
        MOV     EAX,DFCS_BUTTONCHECK OR DFCS_CHECKED
        TEST    STATE,BST_CHECKED
        JNZ     @F
;
        MOV     EAX,DFCS_BUTTONCHECK
@@:     TEST    STATE,BST_PUSHED
        JZ      @F
;
        OR      EAX,DFCS_INACTIVE
@@:     INVOKE  DrawFrameControl,DCTX,ADDR IMGRC,DFC_BUTTON,EAX

STATE is the contro'ls GWL_STATE and DCTX is the device context for the destination window. Really very simple - too bad C++ was invented and these few instructions have been replaced by pages of unnessary "Off-shored/H1-B" generated waste. Right, Gates - brilliant minds... :lol

BATSofware - assembly programming since 1983.

jj2007

Quote from: BATSoftware on May 21, 2009, 02:47:54 PM
The reason that the checkbox and radio button windows are always white is because they are hard coded bitmaps

Could the BCM_SETIMAGELIST message be an option, or does it apply only to pushbuttons? It's relatively new, needs Comclt32.dll version 6.0...

BATSoftware

For Windows XP and Vistinka it appears that BCM_SETIMAGELIST will work as long as COMCTL32.DLL V6 is installed. Note that using an imagelist will ensure that your code not run on Win 9X/NT/2000 systems. Apart from pure laziness and monopolistic behaviour of M$, there is no reason not to add imagelist support via a patches to previous versions of COMCTL32.DLL but then, M$ seldom does anything in the interest of their customers.

azdps

thanks MichaelW and BATsoftware. that pretty much cleared things up for me.