Re: Howto handle win32 messages ?
- From: Aurelien Minet <a minet prim-time fr>
- To: "Rastatter, Ken (OH32)" <Ken Rastatter Honeywell com>
- Cc: "'gtk-app-devel-list gnome org'" <gtk-app-devel-list gnome org>
- Subject: Re: Howto handle win32 messages ?
- Date: Wed, 11 Jun 2003 13:06:31 +0200
Hi Ken,
Since I'm planning on adding DDE server functionality to my
GTK+ app, I also have a need to process Win32 messages that
GDK/GTK+ would otherwise ignore.
I am in the same case, I got an ATL/COM server runing and I have got
process the message it emits.
Here is yet another idea: install an idle function that looks for
messages of interest with PeekMessage(). Here is what I have so
far:
gboolean dde_idle(gpointer data)
{
MSG msg;
if (PeekMessage(&msg, NULL, XTYP_CONNECT, XTYP_CONNECT, PM_NOREMOVE))
{
OutputDebugString("Received message XTYP_CONNECT!\n");
}
return(TRUE);
}
...
g_idle_add(dde_idle, NULL);
...
I have had this idea too, but you need some idle time to be sure it
will be call. So I drop it.
Note how I'm limiting which messages I am looking for. In the
example above I'm looking for a single message (XTYP_CONNECT).
I tried peeking for all messages with
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
and then I tried peeking for a smaller number of messages with
PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE);
but, much to my surprise, both screwed up GTK+ message
processing in interesting ways.
Why would peeking and not removing the messages screw up GTK's
message processing? Another undocumented Microsoft "feature"
in PeekMessage()? *sigh*
I think it could be better if you give the hWnd of the GTK main window
instead of NULL.
But TranslateMessage(&msg) or/and DispatchMessage(&msg) before
returning TRUE may prevent screwing up GTK+ messages , I am not sure.
It could be a problem with the GTK+ translation messages system.
Regards
Aurelien
Here is the solution I used with GTK+ 2.2.1 :
( There are some strange casts cause it's C++, they are't need in C)
WNDPROC OldWinProc=NULL; // a global var :\
/*in my create_window function which creates the main gtk window with
menu ...*/
GtkWidget *window;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
....
return window;
/* in main() */
...
window= create_window();
...
gtk_init(&argc, &argv);
...
HWND hWnd = (struct HWND__ *) gdk_win32_drawable_get_handle( (
window->window ) );
change_WndProc(HWND hWnd);
gtk_widget_show (window);
gtk_main ();
void change_WndProc(HWND hWnd)
{
OldWinProc= (WNDPROC) GetWindowLong(hWnd,GWL_WNDPROC);
SetWindowLong(hWnd,GWL_WNDPROC,(LONG)(WNDPROC)MyWinProc);
}
LONG CALLBACK MyWinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch( msg )
{
case WM_XXX :
.......
break;
case MY_MESSAGE :
.....
break;
default:
return
CallWindowProc((WNDPROC)OldWinProc,hWnd,msg,wParam,lParam);
}
return TRUE ; /*by default */
}
PS: As Tor Lillqvist wrote in a previous mail, GTK+ 2.2.2 will have a
gdk_window_add_filter() function in order to handle messages. GTK+ 2.2.2
is just out but I have time to test it (and compile it) .
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]