Sign in to follow this  
plywood

CreateWindowEx and what not

Recommended Posts

The dang MSDN docs make it a tough read for a newb.... So I want to create three simple child controls for my window: (1) A static text control giving instructions on what to do (2) A 2nd static txt to be displayed to the left of an edit control (3) A simple edit control Thus:
HWND txtGenInfo = CreateWindowEx(WS_VISIBLE | YADDA, ..., "Fill out the form below, STATIC, ..., NULL);

HWND txtEditInstr = CreateWindowEx(..., "User name : ", ..., NULL);

HWND edtUserName = CreateWindowEx(..., "", EDIT, ..., NULL);

How does my WndProc know which controls send messages? For instance, if I were to have a 2nd edit control, how do I differentiate between the two in my switch statement? I have a feeling that the last param in CreateWindowEx(), lpParam, has something to do with this. If it does, then perhaps someone could elaborate as to how this param accomplishing the message IDing. thx, ply

Share this post


Link to post
Share on other sites
The window procedure handles all the messages sent to the window which contains the edit controls. Sometimes the edit controls will forward messages to that window as well; these come in the form of EN_* notifications which you handle in your WM_NOTIFY handler. Sometimes other notifications will come to your window from the WM_COMMAND message. Both WM_NOTIFY and WM_COMMAND explain how to handle these situations.

Share this post


Link to post
Share on other sites
Mike,

So would I use HWND like this: (?)

HWND editControl1 = CreateWindowEx(/* ... */);

// WndProc
LRESULT CALLBACK MyWindowProc(HWND hwnd, UINT msg, WPARAM dubya, LPARAM lParam)
{
if(hwnd == editControl1)
// ?

switch(msg)
{
case WM_CREATE:
// ...
}
}



Something is missing here.... hmmmmm

Share this post


Link to post
Share on other sites
The HWND parameter to the window procedure is the handle to the window that is receiving the message. Typically, this is not going to be your edit control but rather the window you made which contains your edit control.

Share this post


Link to post
Share on other sites
Edit controls and such have their own WndProcs which handle their messages. Your WndProc won't even see them, so there's no need to be concerned about that. You may receive other messages from those windows (such as WM_NOTIFY) though, and you can tell where those came from by checking out the message-specific data passed in lParam and wParam.

hWnd in *your* WndProc is the handle of the window receiving the message (your window). This is necessary so multiple windows can be handled by the same WndProc (WndProc is the handler for the window class, not the specific window).

The only thing you should be doing in your WndProc is handling your messages and passing things you don't handle to DefWindowProc. Your controls will take care of themselves.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this