Make this working: change color of border

I have searched how to change color for control and found this post:
http://stackoverflow.com/questions/13579136/edit-control-border-and-wm-ctlcoloredit

Here I have function to create edit boxes (Thanks andy for your post http://www.cplusplus.com/forum/windows/109795/):
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
HFONT createNewFont(HWND dialog, char * fName = "Arial", int fSize=10, int fWeight = FW_BOLD ){
	const TCHAR* fontName = _T(fName);
	const long nFontSize = (long) fSize;
    
    HDC hdc = GetDC(dialog); // hWnd
    LOGFONT logFont = {0};
    logFont.lfHeight = -MulDiv(nFontSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
    logFont.lfWeight = fWeight;
    _tcscpy_s(logFont.lfFaceName, fontName);

	// A pointer to a LOGFONT structure &logFont defines 
	// the characteristics of the logical font
	HFONT hFont = CreateFontIndirect(&logFont); // hFont - handle to logical font

    ReleaseDC(dialog, hdc); // hWnd, hdc
return hFont;
}
void createEditbox1(HWND dialog, int id, int x, int y, int w, int h, HFONT hFont){
    HWND hwndEdit = CreateWindowEx(
            0, "EDIT",   // predefined class 
            NULL,         // no window title 
            WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | 
            ES_NUMBER, 
            x, y, w, h,   // set size in WM_SIZE message 
            dialog,         // parent window 
            (HMENU) id,   // edit control ID 
            (HINSTANCE) GetWindowLong(dialog, GWL_HINSTANCE), 
            NULL);        // pointer not needed 
	// Set font
	SendMessage(hwndEdit, WM_SETFONT, (WPARAM)hFont, (LPARAM)MAKELONG(TRUE, 0));
	// add text to window
	SendMessage(hwndEdit, WM_SETTEXT, 0, 0);
}
void Display_Matrix(HWND dialog, int matrixSize = 4){
	int w = 23;
	int h = 16;
	int paddingx = 2;
	int paddingy = 2;
	int offsetx = 130;
	int offsety = 130;
	int beginx = offsetx;
	int beginy = offsety;
	int stepx = w + paddingx;
	int stepy = h + paddingy;
	int endx = offsetx + ( matrixSize * stepx );
	int endy = offsety + ( matrixSize * stepy );
	int x, y, i = 0;
	int count = matrixSize * matrixSize;
	int id = 5000;
	
	HFONT hFont = createNewFont(dialog, "Arial", 8, FW_NORMAL );

	for (x = beginx-stepx; x < endx; x += stepx )
		for (y = beginy-stepy; y < endy; y += stepy ){
			id++;
		    createEditbox1(dialog, id, x, y, w, h, hFont);
			}
}


Dialog process:
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
INT_PTR CALLBACK StartupDialogProc(HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg){
	case WM_INITDIALOG:
		Init_Startup(dialog);
		return 1;
	case WM_CTLCOLOREDIT: 
          {
              HDC hdC = (HDC)wParam;

              SetTextColor( hdC, RGB(12,112,212) );

              SetBkMode( hdC, TRANSPARENT );

                RECT rect;
                GetClientRect( (HWND)lParam, &rect );                    
                HBRUSH hBrush = CreateSolidBrush( RGB(209,209,209) );
                   //FrameRect( hdC, &rect, hBrush );
                   Rectangle( hdC, (int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom );
                DeleteObject( hBrush );

              LOGBRUSH lb;
              lb.lbStyle = BS_SOLID;
              lb.lbColor = RGB(249,249,249);
              lb.lbHatch = 0;
			  CreateBrushIndirect(&lb); // LRESULT
              // GetStockObject(NULL_BRUSH);
			  return 1;
          }
     break;
	case WM_DESTROY:
  	  setts.options.page = GetDlgItemInt(dialog, IDC_O_STARTUP_PAGE, NULL, FALSE);
      setts.options.recent = GetDlgItemInt(dialog, IDC_O_STARTUP_RECENT, NULL, FALSE);
    break;
	case WM_CLOSE:
    // setts.write("Startup", "Page", value)
    // setts.write("Startup", "Recent", value)
		EndDialog(dialog, FALSE);    
		break;
	case WM_COMMAND:
		if (wParam == IDOK) {
			EndDialog(dialog, TRUE);
			return 0;
		}
	}
	return 0;
}


I tried to make it working. I would like to change the border color. Well background and text color - too.

To make the code complete:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void Combo_Fill(HWND dialog, int id, char const * * strings, size_t count)
{
	int index;
	HWND control = GetDlgItem(dialog, id);
	for (size_t i = 0; i < count; ++i){
		index = Combo_AddStringA(control, *strings++);
		SendMessageA(control, LB_SETITEMDATA, index,
			(LPARAM)(strings));
		}
}
inline LRESULT Combo_AddStringA(HWND control, LPCSTR string)
{
	return SendMessageA(control, CB_ADDSTRING, 0, (LPARAM)string);
}

extern const char *menu_recents[NUM_STARTUP_RECENTS] = { "0", "1", "2", "3", "4" };
extern const char *menu_pages[NUM_STARTUP_PAGES] = { "Messages", "Players", "Global Victory", "Disables", "Map", "Units", "Triggers" };

Last edited on
In order to use a brush or a pen you need the function SelectObject(...):

https://msdn.microsoft.com/en-us/library/aa932923.aspx
Topic archived. No new replies allowed.