1 Replies - 509 Views - Last Post: 16 October 2019 - 12:32 PM

#1 BCriss   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-May 19

Change background color of a element in a main window

Posted 04 May 2019 - 01:51 AM

Hello :)/>

I have a main window application, inside which I have windows with elements like bitmaps, buttons, text, etc.
How do I change the background color for one of them? For example a message line, defined like this:
; Message line
Invoke CreateWindowEx, WS_EX_CLIENTEDGE,
       ADDR szStatic,
       NULL,
       SS_CENTER or WS_BORDER or WS_CHILD or WS_VISIBLE,
       50, 50, 200, 30,
       hWnd, cID_stMSGLINE, hInst, NULL
mov hMSGLINE,eax


Where hWnd is the handle of the main application window.
How do I change the background color only of the hMSGLINE window?
I tried intercepting the Erasebackground event like this:
CASE WM_ERASEBKGND
    RGB 0,200,25
    invoke CreateSolidBrush,eax
    invoke SetClassLong, hwin, GCL_HBRBACKGROUND, eax


But only the background of the main window gets changed.

Can anyone provide a simple example of main window with a background color with a text window in it with different background color?
Thank you for your help !

Is This A Good Question/Topic? 0
  • +

Replies To: Change background color of a element in a main window

#2 CMalcheski   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-January 15

Re: Change background color of a element in a main window

Posted 16 October 2019 - 12:32 PM

View PostBCriss, on 04 May 2019 - 01:51 AM, said:

Hello :)/>/>

I have a main window application, inside which I have windows with elements like bitmaps, buttons, text, etc.
How do I change the background color for one of them? For example a message line, defined like this:
; Message line
Invoke CreateWindowEx, WS_EX_CLIENTEDGE,
       ADDR szStatic,
       NULL,
       SS_CENTER or WS_BORDER or WS_CHILD or WS_VISIBLE,
       50, 50, 200, 30,
       hWnd, cID_stMSGLINE, hInst, NULL
mov hMSGLINE,eax


Where hWnd is the handle of the main application window.
How do I change the background color only of the hMSGLINE window?
I tried intercepting the Erasebackground event like this:
CASE WM_ERASEBKGND
    RGB 0,200,25
    invoke CreateSolidBrush,eax
    invoke SetClassLong, hwin, GCL_HBRBACKGROUND, eax


But only the background of the main window gets changed.

Can anyone provide a simple example of main window with a background color with a text window in it with different background color?
Thank you for your help !


This gets more complicated than you may want to deal with. While Windows offers a ton of message handling for things like this, in my experience those routes have failed so often that it doesn't even occur to me to use them anymore. NM_CustomDraw ate up more wasted hours than anything else in Windows. I never got it to work correctly 99% of the time. There are control-dependent messages which may get the job done for you - i.e. wm_ctlcolorstatic for STATIC class windows, bn_paint for buttons, etc. Look more closely at the notifications for the specific window type you want to change. Personally I had so much trouble with Windows misbehavior, trying to control things at these low levels, that I no longer use Windows controls at all. Everything in my apps is custom coded from the ground up and guess what? No more problems. It behaves as advertised. Imagine that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1