0
votes

I've just created multiple edit boxes (11x11 controls) based on this article: https://msdn.microsoft.com/en-us/library/windows/desktop/hh298433%28v=vs.85%29.aspx Well, not exactly same, but I used the code in case WM_CREATE: block to create huge number of controls.

I use this dialog process on the parent window:

INT_PTR CALLBACK StartupDialogProc(HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg){
    case WM_INITDIALOG:
        Init_Startup(dialog);
        return 1;
/*
    case EN_CHANGE:
    case WM_CTLCOLOREDIT: 
          {
              HDC hdC = (HDC)wParam;

                COLORREF crColorBackground = RGB(255,0,0);  
                    if (crColorBackground)
                        SetBkColor(hdC, crColorBackground);

              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:
        EndDialog(dialog, FALSE);    
        break;
    case WM_COMMAND:
        if (wParam == IDOK) {
            EndDialog(dialog, TRUE);
            return 0;
        }
    }
    return 0;
}

There is few things unclear to me: 1) if I would like to change color of border for all edit controls from id 5001 to id 5121, how to do that? To me, the commented code does not work (when would it be uncommented). It looks like I have this in incorrect place. 2) how correctly create the dialog processes to all the controls? Because there is big number and could be yet few times higher, should I just call a loop from 5001 to id 5121 and call the function: INT_PTR CALLBACK EditDlgProc(HWND dialog, UINT msg, WPARAM wParam, LPARAM lParam) - that won't work, because every function would need to have different name.

1

1 Answers

1
votes

To change the border color of edit control, you have to subclass the edit control and override WM_NCPAINT. That's a little advanced, and you don't really need it. You can just use WS_EX_CLIENTEDGE flag:

CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT" ...

Also make sure project manifest is setup so you get modern window's look.

This would be an error if it had not been commented out:

case EN_CHANGE:
case WM_CTLCOLOREDIT: 

Each case should end in break; or return 0;

Moreover, WM_CTLCOLOREDIT should return a brush which was created on heap. It should not return 1. See documentation :

There are also other errors in that section, you should just get rid of that. See this example for painting.