39 #define THREADED // to use the proper set of macros
54 static HWND hwndApp = NULL;
55 static HDC dcApp = NULL;
56 static int fAppActive = 0;
57 static int fOldAppActive = 0;
58 static int main_window_inited = 0;
59 static char szWinTitle[128];
60 static char szWinClass[128];
61 static HANDLE hThread=NULL;
62 static DWORD ThreadID;
63 static int WinX, WinY, WinW, WinH;
64 static int Os_inited = 0;
74 #ifdef THREADED_PROCESS
116 HANDLE pHandle = GetCurrentProcess();
117 DWORD pMaskProcess = 0, pMaskSystem = 0;
119 if ( GetProcessAffinityMask(pHandle, &pMaskProcess, &pMaskSystem) ) {
121 if (pMaskProcess >= 3) {
125 if (pMaskProcess > 0) {
126 SetProcessAffinityMask(pHandle, pMaskProcess);
134 void os_init(
const char * wclass,
const char * title,
const char *app_name,
const char *version_string )
175 SetWindowText( hwndApp, szWinTitle );
187 ReleaseDC( hwndApp, dcApp );
191 DestroyWindow( hwndApp );
210 return (
uint)hwndApp;
216 dcApp = GetDC(hwndApp);
225 hwndApp = (
HWND)new_handle;
254 #ifdef THREADED_PROCESS
295 while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) ) {
296 TranslateMessage(&msg);
297 DispatchMessage(&msg);
302 #endif // THREADED_PROCESS
308 char search_string[256];
316 hMod = GetModuleHandle(NULL);
318 namelen = GetModuleFileName( hMod, myname, 127 );
319 if ( namelen < 1 )
return;
322 p = strstr( myname,
".exe" );
327 while( (*p!=
'\\') && (*p!=
'/') && (*p!=
':') )
330 if ( strlen(p) < 1 )
return;
333 sprintf( search_string,
"[run] - %s -", p );
343 CloseHandle(hThread);
354 len = GetWindowText( hwnd, tmp, 127 );
357 if ( strstr( tmp, search_string )) {
368 if (fAppActive != fOldAppActive) {
378 #ifdef THREADED_PROCESS
379 SetThreadPriority( hThread, THREAD_PRIORITY_HIGHEST );
387 SetWindowPos(hwndApp, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
402 #ifdef THREADED_PROCESS
403 SetThreadPriority( hThread, THREAD_PRIORITY_NORMAL );
411 SetWindowPos(hwndApp, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
420 fOldAppActive = fAppActive;
433 case WM_QUERYNEWPALETTE:
437 case WM_PALETTECHANGED:
440 case WM_PALETTEISCHANGING:
444 case WM_DISPLAYCHANGE:
484 latency = timeGetTime() - GetMessageTime();
488 nVirtKey = (
int)wParam;
489 lKeyData = (lParam>>16) & 255;
490 if ( (lParam>>16) & 256 ) lKeyData += 0x80;
493 if ( nVirtKey == VK_SNAPSHOT ) {
516 latency = timeGetTime() - GetMessageTime();
520 nVirtKey = (
int) wParam;
521 lKeyData = (lParam>>16) & 255;
522 if ( (lParam>>16) & 256 ) lKeyData += 0x80;
525 if ( nVirtKey == VK_SNAPSHOT ) {
536 if ( lKeyData == 0xB7 ) {
577 int flag = LOWORD(wParam);
578 fAppActive = (( flag == WA_ACTIVE) || (flag==WA_CLICKACTIVE)) ?
TRUE :
FALSE;
587 fAppActive = (
BOOL)wParam;
602 if ( wParam != SC_SCREENSAVE ){
603 return DefWindowProc(hwnd, msg, wParam, lParam);
627 return DefWindowProc(hwnd, msg, wParam, lParam);
640 if (hwndApp != NULL) {
642 ReleaseDC( hwndApp, dcApp );
646 DestroyWindow( hwndApp );
650 memset( &wclass, 0,
sizeof(WNDCLASSEX) );
652 wclass.hInstance = hInst;
653 wclass.lpszClassName = szWinClass;
661 wclass.style = CS_OWNDC;
663 wclass.cbSize =
sizeof(WNDCLASSEX);
664 wclass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(
IDI_APP_ICON) );
665 wclass.hCursor = LoadCursor(NULL, IDC_ARROW);
666 wclass.lpszMenuName = NULL;
667 wclass.cbClsExtra = 0;
668 wclass.cbWndExtra = 0;
671 wclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
673 if ( !RegisterClassEx(&wclass) ) {
674 Error(
LOCATION,
"FATAL ERROR: Unable to register window class!!" );
677 int style = WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE;
680 style |= (WS_CAPTION | WS_SYSMENU | WS_BORDER);
683 int start_x, start_y;
690 x_add = GetSystemMetrics(SM_CXFIXEDFRAME) * 2;
691 y_add = 2 * GetSystemMetrics(SM_CYFIXEDFRAME) + GetSystemMetrics(SM_CYCAPTION);
696 GetWindowRect( GetDesktopWindow(), &my_rect );
698 start_x = (my_rect.right - width - x_add) / 2;
699 start_y = (my_rect.bottom - height - y_add) / 2;
707 start_x = start_y = 0;
713 szWinClass, szWinTitle,
719 NULL, (HMENU)NULL, hInst,
723 Error(
LOCATION,
"FATAL ERROR: Unable to create game window!!" );
726 main_window_inited = 1;
735 ShowWindow( hwndApp, SW_SHOWNORMAL );
737 SetForegroundWindow( hwndApp );
738 SetActiveWindow( hwndApp );
750 #ifndef THREADED_PROCESS
755 while(PeekMessage(&msg,0,0,0,PM_NOREMOVE)) {
756 if ( msg.message == WM_DESTROY ) {
759 if (PeekMessage(&msg,0,0,0,PM_REMOVE)) {
760 TranslateMessage(&msg);
761 DispatchMessage(&msg);
771 mprintf((
"Int3(): From %s at line %d\n", file, line));
776 #if defined(_MSC_VER) && _MSC_VER >= 1400
778 #elif defined(_MSC_VER)
780 #elif defined __GNUC__
783 #error debug_int3: unknown compiler
787 #error debug_int3: unknown OS
799 static HHOOK g_hKeyboardHook = NULL;
802 #ifndef WH_KEYBOARD_LL
803 #define WH_KEYBOARD_LL 13
808 if (nCode < 0 || nCode != HC_ACTION)
809 return CallNextHookEx(g_hKeyboardHook, nCode, wParam, lParam);
821 if ( (vkCode == VK_LWIN) || (vkCode == VK_RWIN) )
825 return CallNextHookEx( g_hKeyboardHook, nCode, wParam, lParam );
828 void disableWindowsKey()
830 if (g_hKeyboardHook != NULL)
833 g_hKeyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0 );
836 void enableWindowsKey()
838 if (g_hKeyboardHook == NULL)
841 UnhookWindowsHookEx( g_hKeyboardHook );
842 g_hKeyboardHook = NULL;
void key_mark(uint code, int state, uint latency)
DWORD win32_process2(DWORD lparam)
uint os_config_read_uint(const char *section, const char *name, uint default_value)
#define MOUSE_LEFT_BUTTON
bool Cmdline_no_unfocus_pause
DWORD win32_process1(DWORD lparam)
#define MOUSE_MIDDLE_BUTTON
void os_init_registry_stuff(const char *company, const char *app, const char *version)
SDL_mutex * CRITICAL_SECTION
UINT WPARAM LPARAM lParam
const char * detect_home(void)
char Cur_path[MAX_PATH_LEN]
void os_set_title(const char *title)
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
void change_window_active_state()
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
#define ENTER_CRITICAL_SECTION(csc)
void win32_create_window(int width, int height)
DWORD win32_process(DWORD lparam)
void os_init(const char *wclass, const char *title, const char *app_name, const char *version_string)
int Cmdline_fullscreen_window
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(void)
void os_set_window(uint new_handle)
void _cdecl void void _cdecl Error(const char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
int Cmdline_voice_recognition
LRESULT CALLBACK win32_message_handler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
const char * Osreg_company_name
#define GetCurrentDirectory(i, s)
#define MOUSE_RIGHT_BUTTON
#define LEAVE_CRITICAL_SECTION(csc)
GLint GLsizei GLsizei height
char Cfile_root_dir[CFILE_ROOT_DIRECTORY_LEN]
#define INITIALIZE_CRITICAL_SECTION(csc)
void outwnd_init_debug_window(int display_under_freespace_window)
BOOL __stdcall os_enum_windows(HWND hwnd, char *search_string)
bool Cmdline_set_cpu_affinity
void debug_int3(char *file, int line)
void os_set_process_affinity()
void gameseq_post_event(int event)
void mouse_mark_button(uint flags, int set)
void gr_opengl_shutdown()
void VOICEREC_process_event(HWND hWnd)