Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
3.4 KiB

  1. //========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "winlite.h"
  8. #include "Sys_Utils.h"
  9. #include "EngineInterface.h"
  10. #if defined( _X360 )
  11. #include "xbox/xbox_win32stubs.h"
  12. #endif
  13. #if defined( _PS3 )
  14. #include "ps3/ps3_core.h"
  15. #include "ps3/ps3_win32stubs.h"
  16. #endif
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. const unsigned int SYS_NO_ERROR = 0;
  20. const unsigned int SYS_ERROR_INVALID_HANDLE =
  21. #ifdef ERROR_INVALID_HANDLE
  22. ERROR_INVALID_HANDLE
  23. #else
  24. -1
  25. #endif
  26. ;
  27. void Sys_SetLastError(unsigned long error)
  28. {
  29. #ifdef _WIN32
  30. ::SetLastError(error);
  31. #endif
  32. }
  33. unsigned long Sys_GetLastError()
  34. {
  35. #ifdef _WIN32
  36. return ::GetLastError();
  37. #else
  38. return 0;
  39. #endif
  40. }
  41. WHANDLE Sys_CreateMutex(const char *mutexName)
  42. {
  43. #ifdef _WIN32
  44. return (WHANDLE)::CreateMutex(NULL, FALSE, TEXT(mutexName));
  45. #else
  46. return (WHANDLE) NULL;
  47. #endif
  48. }
  49. void Sys_ReleaseMutex(WHANDLE mutexHandle)
  50. {
  51. #ifdef _WIN32
  52. ::ReleaseMutex((HANDLE)mutexHandle);
  53. #endif
  54. }
  55. const unsigned int SYS_WAIT_OBJECT_0 = WAIT_OBJECT_0;
  56. const unsigned int SYS_WAIT_ABANDONED =
  57. #ifdef WAIT_ABANDONED
  58. WAIT_ABANDONED
  59. #else
  60. -2
  61. #endif
  62. ;
  63. unsigned int Sys_WaitForSingleObject(WHANDLE mutexHandle, int milliseconds)
  64. {
  65. #ifdef _WIN32
  66. return WaitForSingleObject((HANDLE)mutexHandle, milliseconds);
  67. #else
  68. return -1;
  69. #endif
  70. }
  71. unsigned int Sys_RegisterWindowMessage(const char *msgName)
  72. {
  73. #ifdef _WIN32
  74. return ::RegisterWindowMessage(msgName);
  75. #else
  76. return 0;
  77. #endif
  78. }
  79. WHANDLE Sys_FindWindow(const char *className, const char *windowName)
  80. {
  81. #ifdef _WIN32
  82. return (WHANDLE)::FindWindow(className, windowName);
  83. #else
  84. return 0;
  85. #endif
  86. }
  87. void Sys_EnumWindows(void *callbackFunction, int lparam)
  88. {
  89. #ifdef _WIN32
  90. ::EnumWindows((WNDENUMPROC)callbackFunction, lparam);
  91. #endif
  92. }
  93. #if defined( _WIN32)
  94. void Sys_GetWindowText(WHANDLE wnd, char *buffer, int bufferSize)
  95. {
  96. ::GetWindowText((HWND)wnd, buffer, bufferSize - 1);
  97. }
  98. #endif
  99. void Sys_PostMessage(WHANDLE wnd, unsigned int msg, unsigned int wParam, unsigned int lParam)
  100. {
  101. #if defined( _WIN32)
  102. ::PostMessageA((HWND)wnd, msg, wParam, lParam);
  103. #endif
  104. }
  105. #if defined( _WIN32)
  106. void Sys_SetCursorPos(int x, int y)
  107. {
  108. ::SetCursorPos(x, y);
  109. // engine->SetCursorPos(x,y); // SRC version
  110. }
  111. #endif
  112. #if defined( _WIN32)
  113. static ATOM staticWndclassAtom = 0;
  114. static WNDCLASS staticWndclass = { NULL };
  115. static LRESULT CALLBACK staticProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
  116. {
  117. return DefWindowProc(hwnd,msg,wparam,lparam);
  118. }
  119. #endif
  120. WHANDLE Sys_CreateWindowEx(const char *windowName)
  121. {
  122. /*
  123. if (!staticWndclassAtom)
  124. {
  125. memset( &staticWndclass,0,sizeof(staticWndclass) );
  126. staticWndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  127. staticWndclass.lpfnWndProc = staticProc;
  128. staticWndclass.hInstance = GetModuleHandle(NULL);
  129. staticWndclass.hIcon = 0;
  130. staticWndclass.lpszClassName = windowName;
  131. staticWndclassAtom = ::RegisterClass( &staticWndclass );
  132. DWORD error = ::GetLastError();
  133. }
  134. return (WHANDLE)::CreateWindow(windowName, windowName, 0, 0, 0, 0, 0, 0, 0, GetModuleHandle(NULL), 0);
  135. */
  136. return (WHANDLE)1;
  137. }
  138. void Sys_DestroyWindow(WHANDLE wnd)
  139. {
  140. //::DestroyWindow((HWND)wnd);
  141. }