Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get message from non-existing window?

Status
Not open for further replies.

6112

Programmer
Mar 18, 2002
10
AU
I created a window with API function CreateWindowEx(). Since the window object is not physically existing in my PB library, how can I write script under certain event, such as mouse click? I guessed I have to hook message of this window handle, and send message to a notify window...

But how to it? If have to write C/C++ code for callback, how?

Thank you all in advance.
 
Yes you need C++ code.

Use SetWindowLong Windows API call to assign your WINDPROC message loop to your newly created child window. Don't forget to call the previous WINDPROC ( as returned by SetWindowLong ) or you will find that Windows crashes.

This gets quite complicated and unless you've got a couple of months to spare I wouldn't try doing anything complex. Workarounds are required with PB in some cases.

 
Thank you very much. I know little C/C++ and tried. But failed. Could you please help more in details? Thank you in advance.

I tried to write a DLL like this, but The WndProc() never get be called. What is wrong?

// My DLL code:
extern DllExport int WINAPI HookMyWnd(HWND hWnd, HWND hNotify)

{

HINSTANCE hCurrInstance;
WNDCLASS cls;


hCurrInstance = (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE);


cls.hCursor = LoadCursor(NULL,IDC_ARROW);
cls.hIcon = NULL;
cls.lpszMenuName = NULL;
cls.lpszClassName = "Me";
cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
cls.hInstance = hCurrInstance;
cls.style = CS_DBLCLKS;
cls.lpfnWndProc = WndProc;
cls.cbClsExtra = 0;
cls.cbWndExtra = 0;
if (!RegisterClass(&cls)) return FALSE;

// Keep notify window into my memory for notification
hNotifyWindow = hNotify;

return TRUE;
}

LONG FAR PASCAL WndProc(HWND hWnd, UINT Msg, WPARAM WP, LPARAM LP)
{
if(Msg == WM_LBUTTONDOWN)
{
MessageBox(NULL, "Mouse Clicked", "TEST", MB_OK);
SendMessage(hNotifyWindow, 123456, 0, 0);
}


return(DefWindowProc(hWnd, Msg, WP, LP));
}


 
What you want to do is call SetWindowLong with GWL_WNDPROC and the address of your WNDPROC function. SetWindowLong returns the previous WNDPROC which you must call from the new WNDPROC. Actual C++ code is at home unfortunately but hey, if you don't suffer you don't grow.
ciao
 
Thank you very very much Sir!

Under your guide, I successfully made it! Program works greatly! It refreshes my C/C++ skills as well...

I am so happy with the expert like you to have kindly helped me.

Thank you again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top