News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

How to customize the back color of my window app ?

Started by Abdel Hamid, January 24, 2019, 10:29:07 AM

Previous topic - Next topic

Abdel Hamid

Hello guys , am back with another question as usual  ::)

how can i change the background color of my window app ?
i tried to use RGB macro using this line of code

RGB 0.0.255 ; to get blue color
mov wc.hbrBackground,eax ; the return RGB color is stored in eax , am i right ?

am pretty sure what am doing is totally wrong  :bgrin:

mov wc.hbrBackground,COLOR_WINDOW ; <== i wanna use a custom color instead of available constant

and why RGB is working only on WndProc procedure   :exclaim:
Regards,
AH

HSE

Not a color but a brush. You can use CreateIndirectBrush.
Equations in Assembly: SmplMath

Abdel Hamid

thank you man i've searched for the function that you mentioned  :bgrin:
it's ( CreateBrushIndirect )
after adding this lines of code :

    local logbrush : LOGBRUSH
    mov logbrush.lbStyle,BS_SOLID
    mov logbrush.lbColor,00FF0000h
    mov logbrush.lbHatch,HS_VERTICAL or HS_HORIZONTAL

and modifying this :

invoke CreateBrushIndirect,addr logbrush
    mov   wc.hbrBackground,eax

i just need to type the color in hex from now on :t
i got the right color, thank you so much for your help sir  :greenclp:

now i need to know why i cant use RGB macro on the WinMain function ?

hutch--

You have done it the right way, the hex value "00FF0000h" is in what you call COLORREF format, from right to left red, green and blue and the left most position is zero.

Abdel Hamid

Mr.Hutch , glad to hear that from you  :biggrin:
can you answer my question about RGB please ?
why am unable to use it inside WinMain procedure , while i can use it inside WndProc procedure :icon_confused:

HSE

Equations in Assembly: SmplMath

Abdel Hamid

this is pretty much easier
once again thank you  :t

felipe

Quote from: Abdel Hamid on January 24, 2019, 12:09:44 PM
can you answer my question about RGB please ?
why am unable to use it inside WinMain procedure , while i can use it inside WndProc procedure :icon_confused:

i think you will have to show your code to have an answer for that... :idea:

Abdel Hamid

Thank you for the reply mr felipe
Here's the code sir :


include masm32rt.inc
WinMain proto :DWORD,:DWORD
RGB macro red,green,blue
        xor eax,eax
        mov ah,blue
        shl eax,8
        mov ah,green
        mov al,red
endm
.data
ClassName db "SimpleWinClass",0
AppName  db "Our First Window",0
TestString     db "Win32 assembly is great and easy!",0
FontName    db "Terminal",0
Text db "Do you want to quit application ?",0
Caption db "Exit",0
.data?
hInstance DWORD ?
.code
start:
    invoke GetModuleHandle, NULL
    mov    hInstance,eax
    invoke WinMain, hInstance, SW_SHOWDEFAULT
    invoke ExitProcess,eax

WinMain proc hInst:DWORD,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
    mov eax, hInstance
    mov wc. hInstance,eax
    RGB 0.0.255 ;<= error
    invoke CreateSolidBrush,00FF0000h
    mov wc. hbrBackground,eax
    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,NULL,ADDR ClassName,ADDR AppName,\
    WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT\
    ,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
       LOCAL hdc:HDC
       LOCAL ps:PAINTSTRUCT
       LOCAL hfont:HFONT

    .IF uMsg==WM_DESTROY
        invoke PostQuitMessage,NULL
     .elseif uMsg==WM_CLOSE
      invoke MessageBox,NULL,addr Text,addr Caption,MB_ICONINFORMATION or MB_YESNO
     .if eax==IDYES
      invoke ExitProcess,eax
     .endif
    .ELSEIF uMsg==WM_PAINT
        invoke BeginPaint,hWnd, ADDR ps
        mov    hdc,eax
        invoke CreateFont,24,16,0,0,400,0,0,0,OEM_CHARSET,\
        OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
        DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,\
                                       ADDR FontName
        invoke SelectObject, hdc, eax
        mov    hfont,eax
        RGB    200,200,50 ; <= used normally
        invoke SetTextColor,hdc,eax
        RGB    0,0,255
        invoke SetBkColor,hdc,eax
        invoke TextOut,hdc,0,0,ADDR TestString,SIZEOF TestString
        invoke SelectObject,hdc, hfont
        invoke EndPaint,hWnd, ADDR ps
    .ELSE
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
    .ENDIF
    xor    eax,eax
    ret
WndProc endp

end start


jj2007

Quote from: Abdel Hamid on January 24, 2019, 10:29:07 AM
i tried to use RGB macro using this line of code

RGB 0.0.255 ; to get blue color
mov wc.hbrBackground,eax ; the return RGB color is stored in eax , am i right ?

Macro arguments are comma-separated. Your version has dots.

Abdel Hamid

hello JJ2007 thank you for your post  :t
actually you right , i've mixed between the two
now even when i use this :

RGB 0,0,255 ; separated by comas
mov wc.hbrBackground,eax

RGB macro returns RGB color , it will be stored in eax register
this member " hbrBackground " can be a color value

why nothing appears on the screen ?

jj2007

Coding rule #1: Every single character, every single line must be absolutely correct. Otherwise it won't work.

    RGB 255,0,0 ; no error
    invoke CreateSolidBrush, eax
    mov wc. hbrBackground,eax

Abdel Hamid

allright sir , this works perfectly
thank you very much for your cooperation  :biggrin:

BugCatcher

You don't have to define a RGB macro. Its already defined in the masm32rt.inc \macros.asm

Abdel Hamid

hello friend,
i just wanna know how to use it
am following (iczelion tutorials)  :bgrin: