The first problem is on the first and the last line. You cannot create instance of class ChildControls called ChildControls. What you are doing is equivalent to ChildControls ChildControls; Also, you fail create instance of the class because contructor requires a paramater ( ChildControls(const HWND parent) )
Second, the callback function cannot be part of the class.
thanks for all.
need ask 1 thing: without the EnumChildProc() function, can i get the control(not child control) with index 0(normaly it's the 1st form created)?
you told me for pass the 'this' for EnumWindows() function. and then i can use that way for catch the pointer.
i did the same thing for windows procedure, but don't works :(
when i create the control(CreateWindowEx()) i send the 'this' on last parameter and in window procedure i do: form *inst = (form*)lParam;
but by some reason i only get NULL... why?
The pointer is passed to your window procedure only once to WM_CREATE message. You must handle the WM_CREATE message, and save the pointer.
1 2 3 4 5 6 7 8 9
// in window procedure
case WM_CREATE:
{
CREATESTRUCT *cs=(CREATESTRUCT*)lParam;
form *inst=(form*)cs->lpCreateParams; // this value is equal to the last parameter of CreateWindoiwEx
SetWindowLongPtr(hwnd,GWL_USERDATA,(LONG_PTR)inst); // save it for later use
return 0;
}
To get the pointer again, use GetwindowLongPtr:
1 2
// somewhere in window porocedure, when you need it
form *inst=(form*)GetWindowLongPtr(hwnd,GWL_USERDATA);
heres the entire code: http://codepad.org/SrOIpP6t
(sorry... the class is to big for put here :( )
by some reason i can't get the form instance pointer :(
after execute the form isn't showed and then i get these ouptup message:
"Process terminated with status -1073741819 (0 minutes, 9 seconds)"
i don't know what means :(