There are two combobox cells and I need them to be Read Only.
I do ES_READONLY , but you can still enter values ​​in them. I do not know why it does not work.

 hStartVertexCombo = CreateWindow(L"Combobox", NULL, WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | ES_READONLY, 97, 70, 120, 110, hWnd, NULL, hInst, NULL); hEndVertexCombo = CreateWindow(L"Combobox", NULL, WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | ES_READONLY, 307, 70, 120, 110, hWnd, NULL, hInst, NULL); 

Further, I need the Find Path button to become active when I select something in the BOTH Combobox, and now it becomes active right after I select in one.

How can this be fixed?

 if (HIWORD(wParam) == BN_CLICKED) { SendMessage(hStartVertexCombo, CBS_DROPDOWNLIST, (WPARAM)TRUE, 0); SendMessage(hEndVertexCombo, CBS_DROPDOWNLIST, (WPARAM)TRUE, 0); return; } else if (HIWORD(wParam) == CBN_SELCHANGE) { EnableWindow(hFindPathButton, 1); } 

UPD:

 if ((startIndex == CB_ERR) || (endIndex == CB_ERR)) { SetWindowText(hFilePathEdit, L"Error"); return; } 

    1 answer 1

    To make COMBOBOX read-only (replace the edit field with a static window) use the CBS_DROPDOWNLIST style for it, rather than the CBS_DROPDOWN style (see Combo Box Styles ). The ES_READONLY flag does not affect the COMBOBOX element.

    In order to highlight the button as you need, change your handler:
    ... else if (HIWORD(wParam) == CBN_SELCHANGE) { if (SendMessage(hStartVertexCombo,CB_GETCURSEL,0,0)!=CB_ERR && SendMessage(hEndVertexCombo,CB_GETCURSEL,0,0)!=CB_ERR) EnableWindow(hFindPathButton, TRUE); else EnableWindow(hFindPathButton, FALSE); }

    • and what to return in such a check (UPD? I wrote to get Error, but maybe you need something else by the rules? - dimaAf
    • Returning from window handlers depends solely on how the return value will be interpreted by the system. Those. Depending on which message you are checking in, see MSDN for how the returned values ​​for this message are interpreted. For example, for WM_COMMAND, you must return 0 if you processed the specified message, or nonzero otherwise - Denys Save