Quake DeveLS - Quake2 Windows

Author: Curtis "CurMo" Moxley
Difficulty: FairlyEasy

This is a fairly simple mod to show that it is possible to spawn windows from/in Quake2. I have never had any problems with doing it, but Divide has told me that in some vid-modes the window doesn't show up, or it will lock up Quake, so I'm not sure. This is just to basically give you an idea of how to go about it. I won't go into in depth windows programming, I'm only going to use the generic MessageBox. Some problems you may notice right away is that in fullscreen mode it will (most likely) pop up the MessageBox box but it will be

a) Distorted to the vid mode you're in (of course)
b) It will be in some weird colors (Quake2 palette)
c) It will also show the Quake2 caption at the top when it opens the window
d) You must hit enter again to make Quake2 resume play (after you hit OK on the MessageBox)
e) In some vid modes the cursor won't turn on, even if you turned it on. I'm sure there's prolly some other way that Quake is capturing the mouse in various video modes, but I'm not gonna worry about that here.

In Windowed Mode the MessageBox window is in normal windows color and resolution, and the cursor should work (it always seems to for me)

OK! Time to get started! I'm going to keep this very generic. The MessageBox window will spawn whenever you enter deathmatch mode in this tutorial.

First: Start a normal quake2 project, like you can learn to do in other tutorials.

1) Add a new file to your project, mine is called qwindow.c
2) In qwindow.c add these lines:

#include "g_local.h" 	//This is NOT necessary, but I put it in there for future stuff
#include <windows.h> 	//Needed for most windows stuff

void SpawnWindow(edict_t *ent)    //edict_t *ent is NOT necessary, but I have it in there in case I decide 
 //I need to do something with it in the future.
{
	HWND		hwnd;    	//Holds the handle to a window (will be q2 window)
	HCURSOR	hCursor;

	hwnd = FindWindow(NULL, "Quake 2");		//Get handle of the window titled Quake2
 	MessageBeep(0xFFFFFFFF);  			//Stanard windows beep :: Just to show
//Another built-in in q2 for the hell of it
    	hCursor = LoadCursor(NULL, IDC_ARROW);	//Set the cursor to  the standard arrow
ShowCursor(TRUE);			    	//Show the cursor (doesn't always work)

MessageBox(hwnd, "You're in Deathmatch Mode", 
"Quake2Window", MB_OK | MB_ICONEXCLAMATION);
 		//Messagebox(HWND, TEXT, TITLE,
//ATTRIBUTES
    	return;
  }




3) Now all that you need to do is call this from somewhere, and since we want it to pop up at the start of deathmatch, we will put it in p_client.c
4) In p_client.c look for:
void SP_misc_teleporter_dest (edict_t *ent);
At the top of the file. Under it put:
void SpawnWindow (edict_t *ent);
5) Again, in p_client.c look for:
void ClientBeginDeathmatch (edict_t *ent)
{
G_InitEdict (ent);
...
5) Right after ClientEndServerFrame (ent); add SpawnWindow (ent);
6) Compile the dll
7) Put the gamex86.dll that was just made into some directory like quake2\window
8) Start quake2: quake2 +set game window
9) In the console of quake2, type "deathmatch 1" (no quotes) and hit enter.
10) Type map base1 and hit enter in the console.
11) Quake should load map base1 and start it in deathmatch mode, and as soon as it loads will pop the MessageBox up. If it doesn't seem to work try a different video mode.

Tip: If it seems like q2 is locked up (it probably isn't), just hit enter once to get ridda the MessageBox, and once more to return to play, most of the time it will pop it back into q2 (it should ;).

That should do it! I haven't done much testing with this other than to show that it CAN be done.. I'm sure it's possible to spawn a more complex window, but I really didn't want to go into doing that in this tutorial. Again, sometimes the cursor doesn't show up, so just hit enter twice, sometimes it might actually lock Quake2 (so I'm told), so good luck! Remember not to get too heavy into windows junk in Q2 though, there are those linux users out there you need to think about!!

Tutorial by Curtis "CurMo" Moxley.


This site, and all content and graphics displayed on it,
are ©opyrighted to the Quake DeveLS team. All rights received.
Got a suggestion? Comment? Question? Hate mail? Send it to us!
Oh yeah, this site is best viewed in 16 Bit or higher, with the resolution on 800*600.
Thanks to Planet Quake for their great help and support with hosting.
Best viewed with Netscape 4