示例#1
0
文件: vid_ddraw.c 项目: matatk/agrip
void VID_Init (unsigned char *palette)
{
	DWORD		WindowStyle, ExWindowStyle;
	WNDCLASS		wc;
//	HDC				hdc;

	Cvar_Register (&vid_ref);

	vid.width = BASEWIDTH;
	vid.height = BASEHEIGHT;
	vid.aspect = ((float)vid.height / (float)vid.width) *
				(320.0 / 240.0);


//	vid.numpages = 1;
	vid.numpages = 2;	// TESTING

	vid.colormap = host_colormap;
	vid.buffer = vid_buffer;
	vid.rowbytes = BASEWIDTH;
	
	d_pzbuffer = zbuffer;

	D_InitCaches (surfcache, sizeof(surfcache));


	if (hwnd_dialog)
		DestroyWindow (hwnd_dialog);


//create window class
	hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_APPICON));

	/* Register the frame class */
	wc.style         = 0;
	wc.lpfnWndProc   = (WNDPROC)MainWndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = global_hInstance;
	wc.hIcon         = 0;
	wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
	wc.hbrBackground = NULL;
	wc.lpszMenuName  = 0;
	wc.lpszClassName = "WinQuake";

	if (!RegisterClass (&wc) )
		Sys_Error ("Couldn't register window class");


//create main window
	WindowStyle = WS_POPUP | WS_SYSMENU | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
/*
	WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU |
				  WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CLIPSIBLINGS |
				  WS_CLIPCHILDREN;*/
	ExWindowStyle = 0;
	mainwindow = CreateWindowEx (
		ExWindowStyle,
		"WinQuake",
		PROGRAM,
		WindowStyle,
		0, 0,
		320,
		200,
		NULL,
		NULL,
		global_hInstance,
		NULL);
	
	if (!mainwindow)
		Sys_Error ("Couldn't create DIB window");

	ShowWindow (mainwindow, SW_SHOWDEFAULT);
	UpdateWindow (mainwindow);

	setcurrentpalette (palette);

	DDraw_Init ();

	window_width = vid.width;
	window_height = vid.height;

	VID_UpdateWindowStatus ();

	vid_initialized = true;
}
示例#2
0
文件: vid_ddraw.c 项目: matatk/agrip
LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	int				fActive, fMinimized;
	int				temp;
	LONG			lRet = 0;
	PAINTSTRUCT		ps;
	HDC				hdc;

	switch (uMsg)
	{
		case WM_CREATE:
			break;

		case WM_MOVE:
			window_x = (int) LOWORD(lParam);
			window_y = (int) HIWORD(lParam);
			VID_UpdateWindowStatus ();

			//if ((modestate == MS_WINDOWED) && !in_mode_set && !Minimized)
			//	VID_RememberWindowPos ();

			break;

   	    case WM_CLOSE:
		// this causes Close in the right-click task bar menu not to work, but right
		// now bad things happen if Close is handled in that case (garbage and a
		// crash on Win95)
			//if (!in_mode_set)
			{
				if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit",
							MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
				{
					Host_Quit ();
				}
			}
			break;

		case WM_ACTIVATE:
			fActive = LOWORD(wParam);
			fMinimized = (BOOL) HIWORD(wParam);
			AppActivate(!(fActive == WA_INACTIVE), fMinimized);

		// fix the leftover Alt from any Alt-Tab or the like that switched us away
			ClearAllStates ();

			/*if (!in_mode_set)
			{
				if (windc)
					MGL_activatePalette(windc,true);

				VID_SetPalette(vid_curpal);
			}*/

			break;

		case WM_PAINT:
			hdc = GetDC (mainwindow);	// FIXME
			hdc = BeginPaint(hWnd, &ps);

			//Com_Printf ("WM_PAINT\n");	// TESTING

			/*
			if (!in_mode_set && host_initialized) {
				SCR_InvalidateScreen ();
				SCR_UpdateScreen ();
			}
			*/

			EndPaint(hWnd, &ps);
			break;

		case WM_KEYDOWN:
		case WM_SYSKEYDOWN:
			if (!in_mode_set)
				IN_TranslateKeyEvent (lParam, true);
			break;

		case WM_KEYUP:
		case WM_SYSKEYUP:
			if (!in_mode_set)
				IN_TranslateKeyEvent (lParam, true);
			break;

	// this is complicated because Win32 seems to pack multiple mouse events into
	// one update sometimes, so we always check all states and look for events
		case WM_LBUTTONDOWN:
		case WM_LBUTTONUP:
		case WM_RBUTTONDOWN:
		case WM_RBUTTONUP:
		case WM_MBUTTONDOWN:
		case WM_MBUTTONUP:
		case WM_XBUTTONDOWN:
		case WM_XBUTTONUP:
		case WM_MOUSEMOVE:
			if (!in_mode_set)
			{
				temp = 0;

				if (wParam & MK_LBUTTON)
					temp |= 1;

				if (wParam & MK_RBUTTON)
					temp |= 2;

				if (wParam & MK_MBUTTON)
					temp |= 4;

				// Win2k/XP let us bind button4 and button5
				if (wParam & MK_XBUTTON1)
					temp |= 8;

				if (wParam & MK_XBUTTON2)
					temp |= 16;

				IN_MouseEvent (temp);
			}
			break;

		// JACK: This is the mouse wheel with the Intellimouse
		// Its delta is either positive or neg, and we generate the proper
		// Event.
		case WM_MOUSEWHEEL: 
			if (in_mwheeltype != MWHEEL_DINPUT)
			{
				in_mwheeltype = MWHEEL_WINDOWMSG;

				if ((short) HIWORD(wParam) > 0) {
					Key_Event(K_MWHEELUP, true);
					Key_Event(K_MWHEELUP, false);
				} else {
					Key_Event(K_MWHEELDOWN, true);
					Key_Event(K_MWHEELDOWN, false);
				}
			}
			break;

		default:
            /* pass all unhandled messages to DefWindowProc */
            lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
	        break;

	}

    /* return 0 if handled message, 1 if not */
    return lRet;
}
示例#3
0
/* main window procedure */
LONG WINAPI MainWndProc (HWND    hWnd, UINT    uMsg, WPARAM  wParam, LPARAM  lParam) {
	extern void VID_UpdateWindowStatus (void);

    LONG lRet = 1;
	int fActive, fMinimized, temp;
	extern unsigned int uiWheelMessage;

	// VVD: didn't restore gamma after ALT+TAB on some ATI video cards (or drivers?...)
	// HACK!!! FIXME {
	extern int	restore_gamma;
	static time_t time_old;
	static float old_gamma;
	if (restore_gamma == 2) {
		if (time(NULL) - time_old > 0) {
			Cvar_SetValue(&v_gamma, old_gamma);
			restore_gamma = 0;
		}
	}
	// }

	if (uMsg == uiWheelMessage) {
		uMsg = WM_MOUSEWHEEL;
		wParam <<= 16;
	}

    switch (uMsg) {
#ifdef USINGRAWINPUT
		case WM_INPUT:
			// raw input handling
			IN_RawInput_MouseRead((HANDLE)lParam);
			break;
#endif

		case WM_KILLFOCUS:
            break;

    	case WM_SIZE:
			break;

		case WM_CREATE:

			mainwindow = hWnd;
			break;

   	    case WM_DESTROY:
			// let sound and input know about this?
			mainwindow = NULL;

//			PostQuitMessage (0);
			break;

		case WM_MOVE:
			{
				int		xPos, yPos;
				RECT r;
				int		style;

				if ( !r_fullscreen.integer )
				{
					xPos = (short) LOWORD(lParam);    // horizontal position 
					yPos = (short) HIWORD(lParam);    // vertical position 

					r.left   = 0;
					r.top    = 0;
					r.right  = 1;
					r.bottom = 1;
    
					style = GetWindowLong( hWnd, GWL_STYLE );
					AdjustWindowRect( &r, style, FALSE );
    
					Cvar_SetValue( &vid_xpos, xPos + r.left );
					Cvar_SetValue( &vid_ypos, yPos + r.top );
					vid_xpos.modified = false;
					vid_ypos.modified = false;
				}

				VID_UpdateWindowStatus();
			}
			break;

   	    case WM_CLOSE:
			if (MessageBox (mainwindow, "Are you sure you want to quit?", "ezQuake : Confirm Exit",
						MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
			{
				Host_Quit ();
			}

	        break;

		case WM_ACTIVATE:
			fActive = LOWORD(wParam);
			fMinimized = (BOOL) HIWORD(wParam);
			AppActivate(!(fActive == WA_INACTIVE), fMinimized);

			// VVD: didn't restore gamma after ALT+TAB on some ATI video cards (or drivers?...)
			// HACK!!! FIXME {
			if (restore_gamma == 1) {
				time_old = time(NULL);
				restore_gamma = 2;
				old_gamma = v_gamma.value;
				Cvar_SetValue(&v_gamma, old_gamma + 0.01);
			}
			// }
			// fix the leftover Alt from any Alt-Tab or the like that switched us away
			ClearAllStates ();

			break;

		case WM_SYSKEYDOWN:
			if ( wParam == 13 )
			{
				if ( glw_state.vid_canalttab )
				{
					Cvar_LatchedSetValue( &r_fullscreen, !r_fullscreen.integer );
					Cbuf_AddText( "vid_restart\n" );
				}
				return 0;
			}
			// fall through
		case WM_KEYDOWN:
#ifdef WITH_KEYMAP
			IN_TranslateKeyEvent (lParam, wParam, true);
#else // WITH_KEYMAP
			Key_Event (IN_MapKey(lParam), true);
#endif // WITH_KEYMAP else
			break;

		case WM_KEYUP:
		case WM_SYSKEYUP:
#ifdef WITH_KEYMAP
			IN_TranslateKeyEvent (lParam, wParam, false);
#else // WITH_KEYMAP
			Key_Event (IN_MapKey(lParam), false);
#endif // WITH_KEYMAP else
			break;

		case WM_SYSCHAR:
			// keep Alt-Space from happening
			break;
		// this is complicated because Win32 seems to pack multiple mouse events into
		// one update sometimes, so we always check all states and look for events
		case WM_LBUTTONDOWN:
		case WM_LBUTTONUP:
		case WM_RBUTTONDOWN:
		case WM_RBUTTONUP:
		case WM_MBUTTONDOWN:
		case WM_MBUTTONUP:
		case WM_XBUTTONDOWN:
		case WM_XBUTTONUP:
#ifdef MM_CODE
		case WM_LBUTTONDBLCLK:
		case WM_RBUTTONDBLCLK:
		case WM_MBUTTONDBLCLK:
		case WM_XBUTTONDBLCLK:
#endif // MM_CODE
			temp = 0;

			if (wParam & MK_LBUTTON)
				temp |= 1;

			if (wParam & MK_RBUTTON)
				temp |= 2;

			if (wParam & MK_MBUTTON)
				temp |= 4;

			if (wParam & MK_XBUTTON1)
				temp |= 8;

			if (wParam & MK_XBUTTON2)
				temp |= 16;

			IN_MouseEvent (temp);

			break;

		// JACK: This is the mouse wheel with the Intellimouse
		// Its delta is either positive or neg, and we generate the proper Event.
		case WM_MOUSEWHEEL:
			if (in_mwheeltype != MWHEEL_DINPUT)
			{
				in_mwheeltype = MWHEEL_WINDOWMSG;

				if ((short) HIWORD(wParam) > 0) {
					Key_Event(K_MWHEELUP, true);
					Key_Event(K_MWHEELUP, false);
				} else {
					Key_Event(K_MWHEELDOWN, true);
					Key_Event(K_MWHEELDOWN, false);
				}

				// when an application processes the WM_MOUSEWHEEL message, it must return zero
				lRet = 0;
			}
			break;

		case WM_MWHOOK:
			MW_Hook_Message (lParam);
			break;

		case MM_MCINOTIFY:
			lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
			break;

		default:
			/* pass all unhandled messages to DefWindowProc */
			lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
			break;
	}

	/* return 1 if handled message, 0 if not */
	return lRet;
}