///////////////////////////////////////////////////////////////////////////////////
// This source shows how to Hijack the DarkGDK's WNDPROC from the main window. By
// doing this, you allow your game to intercept Window's Messages (if you want
// to do so) and process them yourself.
//
// This is good if you want to send your own messages through the message pump.
// Such messages may include; SHOW_BADDIES_DEATH_ANIMATION, or MAKE_AI_THINK etc.
///////////////////////////////////////////////////////////////////////////////////
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include "globstruct.h"
// We're going to Hijack GDK's WNDPROC from them. We need to keep a hold of the
// original so that we can let the GDK handle whatever messages we don't...
// NOTE: Unless it's a GAME_SPECIFIC_MESSAGE (ie: SHOW_BADDY_DYING) you *MUST*
// call the original. They took over the original for a reason!
WNDPROC GDKWndProc = NULL;
// Here's our WNDPROC that we will use to hijack the GDK's WNDPROC...
LRESULT WINAPI MyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
// Only catches Close option of the System Menu (Top-Left Corner) or the
// Close Button from the Top-Right Corner; but illustrates the point...
if (uMsg == WM_CLOSE)
MessageBox( NULL, "We are about to close!", "Close Message...", MB_OK );
// Make sure you call the original so that GDK can handle the *real* messages...
return CallWindowProc(GDKWndProc, hWnd, uMsg, wParam, lParam);
}
// the main entry point for the application is this function
void DarkGDK ( void )
{
// First thing we're gonna do is take over GDK's WNDPROC with our own...
GDKWndProc = (WNDPROC) SetWindowLong( g_pGlob->hWnd, GWL_WNDPROC, (LONG) MyWndProc );
// Yeeeee-hhhhaaaaawwwwww.......
// Now we are ready to take over the World; the GAME-WORLD that is!
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
// our main loop
while ( LoopGDK ( ) )
{
// update the screen
dbSync ( );
}
// return back to windows
return;
}
Enjoy...
JTK