Retrieving lpCreateParams from lParam
I am writing a Win32 GUI using API and am coming up with the following problem.
I basically have a edit control and a button associated with eachother. This means to me that when the button is pushed, it opens an Open Dialog, and then I put the file selected into the edit control.
What I am trying to do is avoid global variables and see if I can pass data through existing structs. Now in the WndProc callback function, I make a call to SendMessage() which needs the HWND of the edit control.
So when I create the button control, I try to pass the address of the edit control in the CREATESTRUCT, but am unable to successfully retrieve it later on.
My code is below, but this seems to be a pain in the ass and if anyone has any suggestions I am all ears.
Code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
...
HWND *edit1 = malloc(sizeof(HWND));
...
temp = CreateWindow(
"edit",
"",
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
5, 25,
120, 20, hwnd,
NULL, hInstance, NULL);
edit1 = &temp;
button1 = CreateWindow(
"button",
"Browse...",
WS_VISIBLE | WS_CHILD,
130, 25,
80, 20, hwnd,
(HMENU)ID_BUTTON1, hInstance, edit1);
...
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
CREATESTRUCT *cs;
HWND *hwnd_t;
...
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_BUTTON1:
{
szFile = shell_opendialog(szFile);
if (szFile != NULL)
{
cs = (CREATESTRUCT*)lParam;
hwnd_t = (HWND*)cs->lpCreateParams;
SendMessage(*hwnd_t, WM_SETTEXT, 0, (LPARAM)szFile);
}
}
...
}
Also I may have forgotten some rules about pointers, its been a while for me.