0
votes

(NB: This is probably more of a programming style / architecture question)

When the main window is created (but not yet shown), my window procedure receives WM_CREATE; this is where I call CreateWindow for the edit control:

    case WM_CREATE:
        hwndEdit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("edit"), L"Default text",
        WS_CHILD | WS_VISIBLE | ES_LEFT | ES_AUTOHSCROLL,
        10, 10, 150, 24, hWnd, (HMENU)ID_EDIT,
        hInst, NULL);
        break;

and as expected "Default text" shows up in the edit control.

I know I can also use SendMessage or SetWindowText.

So, I have three API calls to do what I want - which one should I be using?

best, Chris

1
If the target window is owned by the current process, SetWindowText causes a WM_SETTEXT message to be sent to the specified window or control - so SetWindowText is only thin shell over WM_SETTEXT in your case. and if text known at window creation time - the best just set it in call CreateWindowEx - for what additional SendMessage or SetWindowText ? - RbMm
I'm thinking about unwanted side-effects that one of these methods might have, but which I don't know about yet. If they are equally OK to use, then I will stick with my solution. - user2286339
If there is a solution that can be implemented with a single API call, why look for other solutions? - IInspectable

1 Answers

0
votes

If it is easy and convenient to set the text in CreateWindowEx, then do so.

If, for some reason, it is not convenient, then use SetWindowText.

In this case you probably don't want to use L"Default Text" as the default text in CreateWindowEx.

Since lpWindowName is optional, you may pass NULL to leave it blank.

Alternatively, you might use something which makes more sense for your application, such as L"(Loading...)".