How do you set window background color ?

Started by grofaz, September 07, 2008, 10:37:28 PM

Previous topic - Next topic

grofaz

What the heck is this:

mov     wc.hbrBackground, COLOR_WINDOW+1

I can't find any reference to COLOR_WINDOW anywhere, how do you select different colors ??

regards

PauloH

Hi, dEbugger.

Please, read this in msdn: http://msdn.microsoft.com/pt-br/ms633576(en-us,VS.85).aspx

I recommend you start studying Petzold Book about windows programming. His book teaches the fundamentals of programming windows with api's. Do a little search in Amazon.com.

Kind regards.

PauloH.

grofaz

Thanks for reply. I have windows programming material galore. COLOR_WINDOW is in windows.inc and is an equate to the numeral 5. My question is what are the numerals pertaining to? I'll keep looking.

MichaelW

If you are asking what the +1 on the end is, the structure member is the handle to a background brush or a standard system color. For whatever reason (someone else may know, I don't) the system expects the system color to be specified by its index value + 1. On my system the COLORREF value for system color index COLOR_WINDOW is 00FFFFFFh. Using the code below (MASM32 only, I didn't have time to create a GeneSys version) if I load the hbrBackground member with COLOR_WINDOW+1, the COLORREF value for the client area background is 00FFFFFFh. If I load the hbrBackground member with COLOR_WINDOW, then the COLORREF value for the client area background is 00C0C0C0h, which on my system is the COLORREF value for the COLOR_MENU index (4).

Edit:

If you are asking what the COLOR_ constants represent, they are index values for the various display elements. See the GetSysColor documentation. I posted an example that displays the system colors by index here.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
        hInst     dd          0
        hWnd      dd          0
        wc        WNDCLASSEX  <>
        msg       MSG         <>       
        className db          "test_class",0
        buffer    db          9 dup(0)
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    mov   hInst, rv(GetModuleHandle, NULL)
    mov   wc.cbSize,        sizeof WNDCLASSEX
    mov   wc.style,         CS_HREDRAW or CS_VREDRAW \
                              or CS_BYTEALIGNWINDOW
    mov   wc.lpfnWndProc,   OFFSET WndProc
    mov   wc.cbClsExtra,    NULL
    mov   wc.cbWndExtra,    NULL
    m2m   wc.hInstance,     hInst
    mov   wc.hbrBackground, COLOR_WINDOW+1
    mov   wc.lpszMenuName,  NULL
    mov   wc.lpszClassName, OFFSET className
    mov   wc.hIcon,         rv(LoadIcon, NULL, IDI_APPLICATION)
    mov   wc.hCursor,       rv(LoadCursor, NULL, IDC_ARROW)
    mov   wc.hIconSm,       0
    invoke RegisterClassEx, ADDR wc
    invoke CreateWindowEx,  WS_EX_OVERLAPPEDWINDOW,
                            ADDR className,
                            chr$("Test"),
                            WS_OVERLAPPEDWINDOW,
                            0,0,400,300,
                            NULL, NULL,
                            hInst, NULL
    mov   hWnd, eax
    invoke ShowWindow, hWnd, SW_SHOWNORMAL
    invoke UpdateWindow, hWnd   
  msgLoop:
    invoke GetMessage, ADDR msg, NULL, 0, 0
    .IF (eax != 0)
        invoke TranslateMessage, ADDR msg
        invoke DispatchMessage, ADDR msg
        jmp   msgLoop
    .ENDIF
    exit msg.wParam
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
WndProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
    LOCAL hdc:DWORD
    SWITCH uMsg
      CASE WM_LBUTTONDOWN       
        invoke GetWindowDC, hWin
        mov hdc, eax
        mov edx, lParam
        movzx ecx, dx
        shr edx, 16         
        invoke GetPixel, hdc, ecx, edx
        invoke dw2hex, eax, ADDR buffer
        invoke MessageBox, hWin, ADDR buffer, chr$("Color"),0
      CASE WM_CLOSE
        invoke DestroyWindow, hWin
      CASE WM_DESTROY
        invoke PostQuitMessage, NULL
      DEFAULT 
        invoke DefWindowProc, hWin, uMsg, wParam, lParam
        ret
    ENDSW
    xor eax, eax
    ret
WndProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


eschew obfuscation

hutch--

Use the API


    invoke CreateSolidBrush,00FF8888h


and place it in the WNDCLASSEX member for the background colour and you can set the Window background to any RGB colour you want.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php


Vortex

dEbUgGeR,

If you wish to create a dialog box, you need to process the WM_CTLCOLORDLG message like the following :

      .IF uMsg==WM_CTLCOLORDLG
            invoke  CreateSolidBrush,Blue
            mov     hBrush,eax
            ret