简体   繁体   中英

change background colour in parent window

I'm very new to win32api programming. I have 3 questions.

how to change the background colour in the parent window. i did it as folows but it dont work

wClass.hbrBackground=(HBRUSH)(RGB(255,255,255));

second question is, I use to add text in the window as follows. the text is in bold font and with a background colour. I want the text to be in normal and without background colour.

PAINTSTRUCT ps;
    HDC hDC;
    char szBuffer[]="Hello, World!";
    hDC=BeginPaint(hWnd,&ps);
    TextOut(hDC,10,10,szBuffer,strlen(szBuffer));

third question is how to add group boxes in the parent window. i searched it in the internet but this was discribed how to add group boxes on dialog boxes using resources. pls some one help me with these isue...

I'm trying to remember if Microsoft put in code to clear the client area. I know at the minimum, you can get the client rect and then use that to base a drawRect() command to the whole client area. You also may have to trap the command to erase the background

  1. > wClass.hbrBackground=(HBRUSH)(RGB(255,255,255));

I suppose the class structure requiers the handle of the brush, not the color value itself (but I'm not sure). Something like this:

wClass.hbrBackground=(HBRUSH)(CreateSolidBrush(RGB(255,255,255)));
  1. To make the text background transparent use special WinAPI function, SetBkMode(TRANSPARENT) ; (Oof, spend some time to remember it's name:) ).

  2. In most tasks it will be much better to make a dialog resource and use it like an ordinary window (drawing smth in it, putting simple windows in which you draw, etc) than take an ordinary window and try to add dialog controls in it. It became a common practice since WinForms and then WPF - every window in them is a "form" in which you can add controls, draw in it and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM