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
Not a color but a brush. You can use CreateIndirectBrush.
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 ?
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.
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:
Quote from: Abdel Hamid on November 28, 1974, 11:03:43 AM
it's ( CreateBrushIndirect )
:biggrin: I was thinking CreateSolidBrush.
this is pretty much easier
once again thank you :t
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:
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
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.
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 ?
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
allright sir , this works perfectly
thank you very much for your cooperation :biggrin:
You don't have to define a RGB macro. Its already defined in the masm32rt.inc \macros.asm
hello friend,
i just wanna know how to use it
am following (iczelion tutorials) :bgrin:
Always check the reference material, many API functions specify COLORREF values for colour. This is specifically a 32 bit value in the form 00BBGGRRh giving the location of the three colour values.
Quote from: hutch-- on January 25, 2019, 06:19:36 AM
Always check the reference material, many API functions specify COLORREF values for colour. This is specifically a 32 bit value in the form 00BBGGRRh giving the location of the three colour values.
Understood Mr.Hutch :biggrin: