Again how?

If I make a text object, how would I go about coloring the background of it to match my window?
What do you mean by text object?

Andy
CreateWindow(TEXT("STATIC"), TEXT("Please Select a Game-Type to begin playing."), WS_VISIBLE | WS_CHILD,
20,40,400,25, hwnd, (HMENU)NULL, NULL, NULL);


The tutorial said to create it like this, which works, but the text has a un-appealing background color, which also does not match my windows color, how do I fix this problem?
WM_CTLCOLORSTATIC message
http://msdn.microsoft.com/en-us/library/windows/desktop/bb787524%28v=vs.85%29.aspx

For example:

1
2
3
4
	const COLORREF crefText  = RGB(  0,   0, 255);
	const COLORREF crefBkgnd = RGB(255, 255,   0);

	static HBRUSH s_hbrBkgnd = NULL;


s_hbrBkgnd created using CreateSolidBrush with crefBkgnd in WM_CREATE or WM_INITDIALOG, and deleted using DeleteObject() in WM_DESTROY

1
2
3
4
5
6
7
		case WM_CTLCOLORSTATIC:
		{
			HDC hdc = (HDC)wParam;
			SetTextColor(hdc, crefText);
			SetBkColor(hdc, crefBkgnd);
			return (INT_PTR)s_hbrBkgnd;
		}


Andy

PS WM_CTLCOLORSTATIC is one of a set of messages : WM_CTLCOLORDLG,
WM_CTLCOLORBTN, WM_CTLCOLOREDIT, WM_CTLCOLORLISTBOX, WM_CTLCOLORSCROLLBAR, WM_CTLCOLORSTATIC. Unfortunately, WM_CTLCOLORBTN does not work for push buttons (just checkboxes and radio buttons)
Last edited on
Mind explaining a little more in depth? Like how it knows what text's background to acsess, etc?
This did not fix the problem, heres my code


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

#include <windows.h>
#include <iostream>
#include <string>
#include <math.h>
#include "REDXWin.h"
bool REDXCURSOR = false;
std::string MODE = "NULL";
std::string OpenOrClosed = "";

const COLORREF crefText  = RGB(  0,   0, 255);
	const COLORREF crefBkgnd = RGB(250, 235,   215);

	static HBRUSH s_hbrBkgnd = NULL;


const char g_szClassName[] = "Custom Story(Red X Orginization)";

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_LBUTTONDOWN:
        {

        }
        break;

        case WM_CREATE:

{          Sleep(1000);




        CreateWindow(TEXT("STATIC"), TEXT("Please Select a Game-Type to begin playing."), WS_VISIBLE | WS_CHILD,
                     20,40,400,25, hwnd, (HMENU)NULL, NULL, NULL);

            HMENU Men1 = CreateMenu();
            HMENU WindowsTextMode = CreateMenu();
            HMENU Options1 = CreateMenu();

            AppendMenu(Men1,MF_POPUP, (UINT_PTR)Options1, "Game Type");
            AppendMenu(Options1, MF_STRING, Men1Button1, "CommandPrompt(Text Based)");
            AppendMenu(Options1, MF_STRING, Men1Button2, "Windows Mode(Semi-Graphics based)");
            AppendMenu(Options1, MF_STRING, Men1Button3, "Windows Mode(Text Based)");
            AppendMenu(Options1, MF_STRING, Men1Button4, "2D Mode");
            AppendMenu(Options1, MF_STRING, Men1Button5, "3D Mode");

            SetMenu(hwnd, Men1);

            break;
}


case WM_CTLCOLORSTATIC:
		{
			HDC hdc = (HDC)wParam;
			SetBkColor(hdc, crefBkgnd);
			return (INT_PTR)s_hbrBkgnd;
		}

case WM_COMMAND:
{
    switch( LOWORD(wParam) )
    {
        case Men1Button1:
        MODE = "CMD Mode";
        std::cout << MODE << std::endl;
            break;

        case Men1Button2:
        MODE = "Windows Mode(SGB)";
        std::cout << MODE << std::endl;
            break;

           case Men1Button3:
           MODE = "Windows Mode(TB)";
           std::cout << MODE << std::endl;
           break;

           case Men1Button4:
            MODE = "2D Mode";
            std::cout << MODE << std::endl;
            break;

           case Men1Button5:
            MODE = "3D Mode";
            std::cout << MODE << std::endl;

            break;
    }
}break;


        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}
This did not fix the problem, heres my code

Where's your call to create the brush? (using the CreateSolidBrush function?)

I did mention it in my last post. All you're doing is returning NULL for the background brush which isn't a lot of use.

Mind explaining a little more in depth?

Have you read the MSDN entry?

Like how it knows what text's background to acsess, etc?

As the MSDN entry says, the lParam is the handle to the static control's window. So if you want to color your controls differently, you can check the handle value against the handles of your various static controls.

Andy
Last edited on
I fixed it, thanks anyway :D
Topic archived. No new replies allowed.