2
0

win32Window.cpp 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #if !defined(TORQUE_SDL)
  23. #include <windows.h>
  24. #include <tchar.h>
  25. #include <winuser.h>
  26. #include "math/mMath.h"
  27. #include "gfx/gfxDevice.h"
  28. #include "gfx/gfxStructs.h"
  29. #include "windowManager/platformWindowMgr.h"
  30. #include "windowManager/win32/win32Window.h"
  31. #include "windowManager/win32/win32WindowMgr.h"
  32. #include "windowManager/win32/win32CursorController.h"
  33. #include "windowManager/win32/winDispatch.h"
  34. #include "platform/menus/popupMenu.h"
  35. #include "platform/platformInput.h"
  36. // for winState structure
  37. #include "platformWin32/platformWin32.h"
  38. const UTF16* _MainWindowClassName = L"TorqueJuggernaughtWindow";
  39. const UTF16* _CurtainWindowClassName = L"TorqueJuggernaughtCurtainWindow";
  40. #define SCREENSAVER_QUERY_DENY 0 // Disable screensaver
  41. #ifndef IDI_ICON1
  42. #define IDI_ICON1 107
  43. #endif
  44. static bool isScreenSaverRunning()
  45. {
  46. #ifndef SPI_GETSCREENSAVERRUNNING
  47. #define SPI_GETSCREENSAVERRUNNING 114
  48. #endif
  49. // Windows 2K, and higher. It might be better to hook into
  50. // the broadcast WM_SETTINGCHANGE message instead of polling for
  51. // the screen saver status.
  52. BOOL sreensaver = false;
  53. SystemParametersInfo(SPI_GETSCREENSAVERRUNNING,0,&sreensaver,0);
  54. return sreensaver;
  55. }
  56. DISPLAY_DEVICE GetPrimaryDevice()
  57. {
  58. int index = 0;
  59. DISPLAY_DEVICE dd;
  60. dd.cb = sizeof(DISPLAY_DEVICE);
  61. while (EnumDisplayDevices(NULL, index++, &dd, 0))
  62. {
  63. if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) return dd;
  64. }
  65. return dd;
  66. }
  67. Win32Window::Win32Window(): mMouseLockPosition(0,0),
  68. mShouldLockMouse(false),
  69. mMouseLocked(false),
  70. mOwningManager(NULL),
  71. mNextWindow(NULL),
  72. mWindowHandle(NULL),
  73. mOldParent(NULL),
  74. mTarget(NULL),
  75. mDevice(NULL),
  76. mAccelHandle(NULL),
  77. mSuppressReset(false),
  78. mMenuHandle(NULL),
  79. mWindowedWindowStyle(0),
  80. mPosition(0,0),
  81. mFullscreen(false)
  82. {
  83. mCursorController = new Win32CursorController( this );
  84. mVideoMode.bitDepth = 32;
  85. mVideoMode.fullScreen = false;
  86. mVideoMode.refreshRate = 60;
  87. mVideoMode.resolution.set(800,600);
  88. _registerWindowClass();
  89. }
  90. Win32Window::~Win32Window()
  91. {
  92. if(mAccelHandle)
  93. {
  94. DestroyAcceleratorTable(mAccelHandle);
  95. mAccelHandle = NULL;
  96. }
  97. // delete our win handle..
  98. DestroyWindow(mWindowHandle);
  99. // unlink ourselves from the window list...
  100. AssertFatal(mOwningManager, "Win32Window::~Win32Window - orphan window, cannot unlink!");
  101. mOwningManager->unlinkWindow(this);
  102. _unregisterWindowClass();
  103. }
  104. void* Win32Window::getSystemWindow(const WindowSystem system)
  105. {
  106. if( system == WindowSystem_Windows)
  107. return getHWND();
  108. return NULL;
  109. }
  110. GFXDevice * Win32Window::getGFXDevice()
  111. {
  112. return mDevice;
  113. }
  114. GFXWindowTarget * Win32Window::getGFXTarget()
  115. {
  116. return mTarget;
  117. }
  118. const GFXVideoMode & Win32Window::getVideoMode()
  119. {
  120. return mVideoMode;
  121. }
  122. void Win32Window::setVideoMode( const GFXVideoMode &mode )
  123. {
  124. bool needCurtain = ( mVideoMode.fullScreen != mode.fullScreen );
  125. if( needCurtain )
  126. {
  127. Con::printf( "Win32Window::setVideoMode - invoking curtain" );
  128. mOwningManager->lowerCurtain();
  129. }
  130. mVideoMode = mode;
  131. mSuppressReset = true;
  132. // Can't switch to fullscreen while a child of another window
  133. if( mode.fullScreen && !Platform::getWebDeployment() && mOwningManager->getParentWindow() )
  134. {
  135. mOldParent = reinterpret_cast<HWND>( mOwningManager->getParentWindow() );
  136. mOwningManager->setParentWindow( NULL );
  137. }
  138. else if( !mode.fullScreen && mOldParent )
  139. {
  140. mOwningManager->setParentWindow( mOldParent );
  141. mOldParent = NULL;
  142. }
  143. // Set our window to have the right style based on the mode
  144. if( mode.fullScreen && !Platform::getWebDeployment() && !mOffscreenRender )
  145. {
  146. WINDOWPLACEMENT wplacement = { sizeof( wplacement ) };
  147. DWORD dwStyle = GetWindowLong( getHWND(), GWL_STYLE );
  148. MONITORINFO mi = { sizeof(mi) };
  149. if ( GetWindowPlacement( getHWND(), &wplacement ) && GetMonitorInfo( MonitorFromWindow( getHWND(), MONITOR_DEFAULTTOPRIMARY ), &mi ) )
  150. {
  151. DISPLAY_DEVICE dd = GetPrimaryDevice();
  152. DEVMODE dv;
  153. ZeroMemory( &dv, sizeof( dv ) );
  154. dv.dmSize = sizeof( DEVMODE );
  155. EnumDisplaySettings( dd.DeviceName, ENUM_CURRENT_SETTINGS, &dv );
  156. dv.dmPelsWidth = mode.resolution.x;
  157. dv.dmPelsHeight = mode.resolution.y;
  158. dv.dmBitsPerPel = mode.bitDepth;
  159. dv.dmDisplayFrequency = mode.refreshRate;
  160. dv.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
  161. ChangeDisplaySettings( &dv, CDS_FULLSCREEN );
  162. SetWindowLong( getHWND(), GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW );
  163. SetWindowPos( getHWND(), HWND_TOP, mi.rcMonitor.left,
  164. mi.rcMonitor.top,
  165. mi.rcMonitor.right - mi.rcMonitor.left,
  166. mi.rcMonitor.bottom - mi.rcMonitor.top,
  167. SWP_NOOWNERZORDER | SWP_FRAMECHANGED );
  168. }
  169. if( mDisplayWindow )
  170. ShowWindow( getHWND(), SW_SHOWNORMAL );
  171. // Clear the menu bar from the window for full screen
  172. if( GetMenu( getHWND() ) )
  173. SetMenu( getHWND(), NULL );
  174. // When switching to Fullscreen, reset device after setting style
  175. if( mTarget.isValid() )
  176. mTarget->resetMode();
  177. mFullscreen = true;
  178. }
  179. else
  180. {
  181. DISPLAY_DEVICE dd = GetPrimaryDevice();
  182. DEVMODE dv;
  183. ZeroMemory( &dv, sizeof( dv ) );
  184. dv.dmSize = sizeof( DEVMODE );
  185. EnumDisplaySettings( dd.DeviceName, ENUM_CURRENT_SETTINGS, &dv );
  186. if ( ( WindowManager->getDesktopResolution() != mode.resolution ||
  187. ( mode.resolution.x != dv.dmPelsWidth ) || ( mode.resolution.y != dv.dmPelsHeight ) ) )
  188. ChangeDisplaySettings( NULL, 0 );
  189. // Reset device *first*, so that when we call setSize() and let it
  190. // access the monitor settings, it won't end up with our fullscreen
  191. // geometry that is just about to change.
  192. if( mTarget.isValid() )
  193. mTarget->resetMode();
  194. if ( !mOffscreenRender )
  195. {
  196. SetWindowLong( getHWND(), GWL_STYLE, mWindowedWindowStyle);
  197. SetWindowPos( getHWND(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
  198. // Put back the menu bar, if any
  199. if(mMenuHandle)
  200. {
  201. SetMenu(getHWND(), mMenuHandle);
  202. }
  203. }
  204. // Make sure we're the correct resolution for web deployment
  205. if (!Platform::getWebDeployment() || !mOwningManager->getParentWindow() || mOffscreenRender)
  206. {
  207. setSize(mode.resolution);
  208. }
  209. else
  210. {
  211. HWND parentWin = reinterpret_cast<HWND>( mOwningManager->getParentWindow() );
  212. RECT windowRect;
  213. GetClientRect( parentWin, &windowRect );
  214. Point2I res( windowRect.right - windowRect.left, windowRect.bottom - windowRect.top );
  215. if ( res.x == 0 || res.y == 0 )
  216. setSize( mode.resolution ); // Must be too early in the window set up to obtain the parent's size.
  217. else
  218. setSize( res );
  219. }
  220. if ( !mOffscreenRender )
  221. {
  222. // We have to force Win32 to update the window frame and make the window
  223. // visible and no longer topmost - this code might be possible to simplify.
  224. SetWindowPos( getHWND(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED );
  225. if(mDisplayWindow)
  226. ShowWindow( getHWND(), SW_SHOWNORMAL );
  227. }
  228. mFullscreen = false;
  229. }
  230. mSuppressReset = false;
  231. if( needCurtain )
  232. mOwningManager->raiseCurtain();
  233. SetForegroundWindow( getHWND() );
  234. getScreenResChangeSignal().trigger( this, true );
  235. }
  236. bool Win32Window::clearFullscreen()
  237. {
  238. return true;
  239. }
  240. bool Win32Window::isFullscreen()
  241. {
  242. return mFullscreen;
  243. }
  244. void Win32Window::_setFullscreen(const bool fullscreen)
  245. {
  246. if (fullscreen == mFullscreen)
  247. return;
  248. mFullscreen = fullscreen;
  249. if(fullscreen && !mOffscreenRender)
  250. {
  251. Con::printf("Win32Window::setFullscreen (full) enter");
  252. SetWindowLong( getHWND(), GWL_STYLE, WS_POPUP|WS_SYSMENU );
  253. SetWindowPos( getHWND(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
  254. }
  255. else
  256. {
  257. Con::printf("Win32Window::setFullscreen (windowed) enter");
  258. if (!mOffscreenRender)
  259. {
  260. SetWindowLong( getHWND(), GWL_STYLE, mWindowedWindowStyle);
  261. SetWindowPos( getHWND(), HWND_NOTOPMOST, 0, 0, mVideoMode.resolution.x, mVideoMode.resolution.y, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
  262. }
  263. setSize(mVideoMode.resolution);
  264. }
  265. Con::printf("Win32Window::setFullscreen exit");
  266. }
  267. bool Win32Window::setCaption( const char *cap )
  268. {
  269. return SetWindowTextA(mWindowHandle, cap);
  270. }
  271. const char * Win32Window::getCaption()
  272. {
  273. char buff[512];
  274. S32 strLen = GetWindowTextA(mWindowHandle, buff, 512);
  275. if(strLen==0)
  276. return NULL;
  277. return StringTable->insert(buff);
  278. }
  279. void Win32Window::setFocus()
  280. {
  281. ::SetFocus( mWindowHandle );
  282. }
  283. void Win32Window::setClientExtent( const Point2I newExtent )
  284. {
  285. Point2I oldExtent = getClientExtent();
  286. if (oldExtent == newExtent)
  287. return;
  288. RECT rtClient;
  289. DWORD Style, ExStyle;
  290. SetRect( &rtClient, 0, 0, newExtent.x, newExtent.y );
  291. Style = GetWindowLong( mWindowHandle, GWL_STYLE);
  292. ExStyle = GetWindowLong( mWindowHandle, GWL_EXSTYLE );
  293. AdjustWindowRectEx( &rtClient, Style, getMenuHandle() != NULL, ExStyle );
  294. if( Style & WS_VSCROLL )
  295. rtClient.right += GetSystemMetrics( SM_CXVSCROLL );
  296. if( Style & WS_HSCROLL )
  297. rtClient.bottom += GetSystemMetrics( SM_CYVSCROLL );
  298. SetWindowPos( mWindowHandle, NULL, 0, 0, rtClient.right - rtClient.left, rtClient.bottom - rtClient.top, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
  299. }
  300. const Point2I Win32Window::getClientExtent()
  301. {
  302. // Fetch Client Rect from Windows
  303. RECT clientRect;
  304. ::GetClientRect(mWindowHandle, &clientRect);
  305. // Return as a Torque Point2I - We don't care about origin as it's always 0,0
  306. return Point2I(clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
  307. }
  308. void Win32Window::setBounds( const RectI &newBounds )
  309. {
  310. RECT newRect;
  311. newRect.left = newBounds.point.x;
  312. newRect.top = newBounds.point.y;
  313. newRect.bottom = newRect.top + newBounds.extent.y;
  314. newRect.right = newRect.left + newBounds.extent.x;
  315. MoveWindow(mWindowHandle, newRect.left, newRect.top, newRect.right - newRect.left, newRect.bottom - newRect.top, true);
  316. }
  317. const RectI Win32Window::getBounds() const
  318. {
  319. // Fetch Window Rect from OS
  320. RECT windowRect;
  321. ::GetWindowRect(mWindowHandle, &windowRect);
  322. // Return as a Torque RectI
  323. return RectI(windowRect.left,windowRect.top,windowRect.right - windowRect.left, windowRect.bottom - windowRect.top);
  324. }
  325. void Win32Window::setPosition( const Point2I newPosition )
  326. {
  327. SetWindowPos( mWindowHandle, HWND_NOTOPMOST, newPosition.x, newPosition.y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE );
  328. }
  329. const Point2I Win32Window::getPosition()
  330. {
  331. RECT windowRect;
  332. GetWindowRect( mWindowHandle, &windowRect );
  333. // Return position
  334. return Point2I(windowRect.left,windowRect.top);
  335. }
  336. Point2I Win32Window::clientToScreen( const Point2I& pos )
  337. {
  338. POINT p = { pos.x, pos.y };
  339. ClientToScreen( mWindowHandle, &p );
  340. return Point2I( p.x, p.y );
  341. }
  342. Point2I Win32Window::screenToClient( const Point2I& pos )
  343. {
  344. POINT p = { pos.x, pos.y };
  345. ScreenToClient( mWindowHandle, &p );
  346. return Point2I( p.x, p.y );
  347. }
  348. void Win32Window::centerWindow()
  349. {
  350. RECT newRect;
  351. GetWindowRect(mWindowHandle,&newRect);
  352. newRect.bottom -= newRect.top;
  353. newRect.right -= newRect.left;
  354. newRect.top = 0;
  355. newRect.left = 0;
  356. HMONITOR hMon = MonitorFromWindow(mWindowHandle, MONITOR_DEFAULTTONEAREST);
  357. // Get the monitor's extents.
  358. MONITORINFO monInfo;
  359. dMemset(&monInfo, 0, sizeof(MONITORINFO));
  360. monInfo.cbSize = sizeof(MONITORINFO);
  361. GetMonitorInfo(hMon, &monInfo);
  362. // Calculate the offset to center the window in the working area
  363. S32 deltaX = ((monInfo.rcWork.right - monInfo.rcWork.left) / 2) - ((newRect.right - newRect.left) / 2);
  364. S32 deltaY = ((monInfo.rcWork.bottom - monInfo.rcWork.top) / 2) - ((newRect.bottom - newRect.top) / 2);
  365. // Calculate the new left and top position for the window
  366. S32 newLeft = newRect.left + deltaX;
  367. S32 newTop = newRect.top + deltaY;
  368. // Clamp these to be greater than 0 so that the top left corner is never offscreen
  369. newLeft = mClamp(newLeft, 0, newLeft);
  370. newTop = mClamp(newLeft, 0, newTop);
  371. // Calculate the new width and height
  372. S32 newWidth = newRect.right - newRect.left;
  373. S32 newHeight = newRect.bottom - newRect.top;
  374. // If the new width and height of the window is larger
  375. // than the working area of the monitor but is smaller
  376. // than the monitor size then have it max out at the
  377. // working area so that it will remain uncovered. We
  378. // leave it alone if it is bigger than the monitor size
  379. // (with a small fudge) to support multiple monitors.
  380. if (newLeft + newWidth > (monInfo.rcWork.right - monInfo.rcWork.left) &&
  381. newLeft + newWidth <= (monInfo.rcMonitor.right - monInfo.rcMonitor.left) + 4)
  382. newWidth = (monInfo.rcWork.right - monInfo.rcWork.left) - newLeft;
  383. if (newTop + newHeight > (monInfo.rcWork.bottom - monInfo.rcWork.top) &&
  384. newTop + newHeight <= (monInfo.rcMonitor.bottom - monInfo.rcMonitor.top) + 4)
  385. newHeight = (monInfo.rcWork.bottom - monInfo.rcWork.top) - newTop;
  386. MoveWindow( mWindowHandle, newLeft, newTop, newWidth, newHeight, true );
  387. // Make sure the resolution matches the client extent
  388. Point2I clientExt = getClientExtent();
  389. mVideoMode.resolution.set( clientExt.x, clientExt.y );
  390. // Let GFX get an update about the new resolution
  391. if (mTarget.isValid())
  392. mTarget->resetMode();
  393. }
  394. bool Win32Window::setSize( const Point2I &newSize )
  395. {
  396. // Create the window rect (screen centered if not owned by a parent)
  397. RECT newRect;
  398. newRect.left = 0;
  399. newRect.top = 0;
  400. newRect.bottom = newRect.top + newSize.y;
  401. newRect.right = newRect.left + newSize.x;
  402. // Adjust the window rect to ensure the client rectangle is the desired resolution
  403. AdjustWindowRect( &newRect, mWindowedWindowStyle, false);//(bool)(getMenuHandle() != NULL) );
  404. // Center the window on the screen if we're not a child
  405. if( !mOwningManager->mParentWindow )
  406. {
  407. HMONITOR hMon = MonitorFromWindow(mWindowHandle, MONITOR_DEFAULTTONEAREST);
  408. // Get the monitor's extents.
  409. MONITORINFO monInfo;
  410. dMemset(&monInfo, 0, sizeof(MONITORINFO));
  411. monInfo.cbSize = sizeof(MONITORINFO);
  412. GetMonitorInfo(hMon, &monInfo);
  413. // Calculate the offset to center the window in the working area
  414. S32 deltaX = ((monInfo.rcWork.right - monInfo.rcWork.left) / 2) - ((newRect.right - newRect.left) / 2);
  415. S32 deltaY = ((monInfo.rcWork.bottom - monInfo.rcWork.top) / 2) - ((newRect.bottom - newRect.top) / 2);
  416. // Calculate the new left and top position for the window
  417. S32 newLeft = newRect.left + deltaX;
  418. S32 newTop = newRect.top + deltaY;
  419. // Clamp these to be greater than 0 so that the top left corner is never offscreen
  420. newLeft = mClamp(newLeft, 0, newLeft);
  421. newTop = mClamp(newLeft, 0, newTop);
  422. // Calculate the new width and height
  423. S32 newWidth = newRect.right - newRect.left;
  424. S32 newHeight = newRect.bottom - newRect.top;
  425. // If the new width and height of the window is larger
  426. // than the working area of the monitor but is smaller
  427. // than the monitor size then have it max out at the
  428. // working area so that it will remain uncovered. We
  429. // leave it alone if it is bigger than the monitor size
  430. // (with a small fudge) to support multiple monitors.
  431. if (newLeft + newWidth > (monInfo.rcWork.right - monInfo.rcWork.left) &&
  432. newLeft + newWidth <= (monInfo.rcMonitor.right - monInfo.rcMonitor.left) + 4)
  433. newWidth = (monInfo.rcWork.right - monInfo.rcWork.left) - newLeft;
  434. if (newTop + newHeight > (monInfo.rcWork.bottom - monInfo.rcWork.top) &&
  435. newTop + newHeight <= (monInfo.rcMonitor.bottom - monInfo.rcMonitor.top) + 4)
  436. newHeight = (monInfo.rcWork.bottom - monInfo.rcWork.top) - newTop;
  437. MoveWindow( mWindowHandle, newLeft, newTop, newWidth, newHeight, true );
  438. }
  439. else // Just position it according to the mPosition plus new extent
  440. MoveWindow(mWindowHandle, newRect.left, newRect.top, newRect.right - newRect.left, newRect.bottom - newRect.top, true);
  441. // Make sure the resolution matches the client extent
  442. Point2I clientExt = getClientExtent();
  443. mVideoMode.resolution.set( clientExt.x, clientExt.y );
  444. // Let GFX get an update about the new resolution
  445. if (mTarget.isValid())
  446. mTarget->resetMode();
  447. InvalidateRect( NULL, NULL, true );
  448. return true;
  449. }
  450. bool Win32Window::isOpen()
  451. {
  452. return true;
  453. }
  454. bool Win32Window::isVisible()
  455. {
  456. // Is the window open and visible, ie. not minimized?
  457. if(!mWindowHandle)
  458. return false;
  459. if (mOffscreenRender)
  460. return true;
  461. return IsWindowVisible(mWindowHandle)
  462. && !IsIconic(mWindowHandle)
  463. && !isScreenSaverRunning();
  464. }
  465. bool Win32Window::isFocused()
  466. {
  467. if (mOffscreenRender)
  468. return true;
  469. // CodeReview This is enough to make the plugin and normal/editor scenarios
  470. // coexist but it seems brittle. I think we need a better way to detect
  471. // if we're the foreground window, maybe taking into account if any of our
  472. // window's parents are foreground? [bjg 4/30/07]
  473. if(mOwningManager->mParentWindow)
  474. return (GetFocus() == mWindowHandle || IsChild(mWindowHandle, GetFocus()));
  475. else
  476. return ((GetFocus() == mWindowHandle || IsChild(mWindowHandle, GetFocus())) && GetForegroundWindow() == mWindowHandle);
  477. }
  478. bool Win32Window::isMinimized()
  479. {
  480. if (mOffscreenRender)
  481. return false;
  482. WINDOWPLACEMENT wd;
  483. if ( GetWindowPlacement( mWindowHandle, &wd ) )
  484. {
  485. return ( wd.showCmd == SW_SHOWMINIMIZED );
  486. }
  487. return false;
  488. }
  489. bool Win32Window::isMaximized()
  490. {
  491. if (mOffscreenRender)
  492. return true;
  493. WINDOWPLACEMENT wd;
  494. if ( GetWindowPlacement( mWindowHandle, &wd ) )
  495. {
  496. return ( wd.showCmd == SW_SHOWMAXIMIZED );
  497. }
  498. return false;
  499. }
  500. WindowId Win32Window::getWindowId()
  501. {
  502. return mWindowId;
  503. }
  504. void Win32Window::minimize()
  505. {
  506. if (mOffscreenRender)
  507. return;
  508. ShowWindow( mWindowHandle, SW_MINIMIZE );
  509. }
  510. void Win32Window::maximize()
  511. {
  512. if (mOffscreenRender)
  513. return;
  514. ShowWindow( mWindowHandle, SW_MAXIMIZE );
  515. }
  516. void Win32Window::restore()
  517. {
  518. if (mOffscreenRender)
  519. return;
  520. ShowWindow( mWindowHandle, SW_RESTORE );
  521. }
  522. void Win32Window::hide()
  523. {
  524. if (mOffscreenRender)
  525. return;
  526. ShowWindow( mWindowHandle, SW_HIDE );
  527. }
  528. void Win32Window::show()
  529. {
  530. if (mOffscreenRender)
  531. return;
  532. ShowWindow( mWindowHandle, SW_SHOWNORMAL );
  533. }
  534. void Win32Window::close()
  535. {
  536. delete this;
  537. }
  538. void Win32Window::_registerWindowClass()
  539. {
  540. // Check to see if it exists already.
  541. WNDCLASSEX classInfo;
  542. if (GetClassInfoEx(GetModuleHandle(NULL),_MainWindowClassName,&classInfo))
  543. return;
  544. HMODULE appInstance = GetModuleHandle(NULL);
  545. HICON appIcon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_ICON1));
  546. // Window class shared by all MainWindow objects
  547. classInfo.lpszClassName = _MainWindowClassName;
  548. classInfo.cbSize = sizeof(WNDCLASSEX);
  549. classInfo.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  550. classInfo.lpfnWndProc = (WNDPROC)WindowProc;
  551. classInfo.hInstance = appInstance; // Owner of this class
  552. classInfo.hIcon = appIcon; // Icon name
  553. classInfo.hIconSm = appIcon; // Icon name
  554. classInfo.hCursor = LoadCursor(NULL, IDC_ARROW); // Cursor
  555. classInfo.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // Default color
  556. classInfo.lpszMenuName = NULL;
  557. classInfo.cbClsExtra = 0;
  558. classInfo.cbWndExtra = 0;
  559. if (!RegisterClassEx(&classInfo))
  560. AssertISV(false,"Window class initialization failed");
  561. classInfo.lpfnWndProc = DefWindowProc;
  562. classInfo.hCursor = NULL;
  563. classInfo.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
  564. classInfo.lpszClassName = _CurtainWindowClassName;
  565. if (!RegisterClassEx(&classInfo))
  566. AssertISV(false,"Curtain window class initialization failed");
  567. }
  568. void Win32Window::_unregisterWindowClass()
  569. {
  570. WNDCLASSEX classInfo;
  571. if (GetClassInfoEx(GetModuleHandle(NULL),_MainWindowClassName,&classInfo))
  572. UnregisterClass(_MainWindowClassName,GetModuleHandle(NULL));
  573. if (GetClassInfoEx(GetModuleHandle(NULL),_CurtainWindowClassName,&classInfo))
  574. UnregisterClass(_CurtainWindowClassName,GetModuleHandle(NULL));
  575. }
  576. LRESULT PASCAL Win32Window::WindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
  577. {
  578. // CodeReview [tom, 4/30/2007] The two casts here seem somewhat silly and redundant ?
  579. Win32Window* window = (Win32Window*)((PlatformWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA));
  580. const WindowId devId = window ? window->getWindowId() : 0;
  581. if (window && window->getOffscreenRender())
  582. return DefWindowProc(hWnd, message, wParam, lParam);
  583. switch (message)
  584. {
  585. case WM_DISPLAYCHANGE:
  586. // Update the monitor list
  587. PlatformWindowManager::get()->buildMonitorsList();
  588. if(window && window->isVisible() && !window->mSuppressReset && window->getVideoMode().bitDepth != wParam)
  589. {
  590. Con::warnf("Win32Window::WindowProc - resetting device due to display mode BPP change.");
  591. window->getGFXTarget()->resetMode();
  592. }
  593. break;
  594. case WM_MOUSEACTIVATE:
  595. SetFocus(hWnd);
  596. return MA_ACTIVATE;
  597. case WM_MOUSEMOVE:
  598. if (window && GetFocus() != hWnd && IsChild(hWnd, GetFocus()))
  599. {
  600. SetFocus(hWnd);
  601. break;
  602. }
  603. // If our foreground window is the browser and we don't have focus grab it
  604. if (Platform::getWebDeployment() && GetFocus() != hWnd)
  605. {
  606. HWND phwnd = GetParent(hWnd);
  607. while (phwnd)
  608. {
  609. if (GetForegroundWindow() == phwnd)
  610. {
  611. SetFocus(hWnd);
  612. break;
  613. }
  614. phwnd = GetParent(phwnd);
  615. }
  616. }
  617. break;
  618. // Associate the window pointer with this window
  619. case WM_CREATE:
  620. // CodeReview [tom, 4/30/2007] Why don't we just cast this to a LONG
  621. // instead of having a ton of essentially pointless casts ?
  622. SetWindowLongPtr(hWnd, GWLP_USERDATA,
  623. (LONG_PTR)((PlatformWindow*)((CREATESTRUCT*)lParam)->lpCreateParams));
  624. break;
  625. case WM_SETFOCUS:
  626. // NOTE: if wParam is NOT equal to our window handle then we are GAINING focus
  627. Dispatch(DelayedDispatch, hWnd, message, wParam, lParam);
  628. return 0;
  629. case WM_KILLFOCUS:
  630. // NOTE: if wParam is NOT equal to our window handle then we are LOSING focus
  631. Dispatch(DelayedDispatch, hWnd, message, wParam, lParam);
  632. return 0;
  633. // The window is being dragged
  634. case WM_MOVE:
  635. if(!window)
  636. break;
  637. window->mPosition.x = (int)LOWORD(lParam);
  638. window->mPosition.y = (int)HIWORD(lParam);
  639. return 0;
  640. // Update viewport when the window moves
  641. case WM_SIZE:
  642. if(window && window->mSuppressReset)
  643. break;
  644. // This is dispatched immediately to prevent a race condition with journaling and window minimizing
  645. if (wParam != SIZE_MINIMIZED && !Journal::IsPlaying())
  646. Dispatch( ImmediateDispatch, hWnd,message,wParam,lParam );
  647. if(wParam != SIZE_MINIMIZED && window != NULL )
  648. {
  649. if(!window->mVideoMode.fullScreen)
  650. {
  651. U32 width = LOWORD( lParam );
  652. U32 height = HIWORD( lParam );
  653. window->mVideoMode.resolution.set( width, height );
  654. }
  655. if(window->getGFXTarget())
  656. {
  657. Con::warnf("Win32Window::WindowProc - resetting device due to window size change.");
  658. window->getGFXTarget()->resetMode();
  659. }
  660. window->getScreenResChangeSignal().trigger(window, true);
  661. }
  662. return 0;
  663. // Limit resize to a safe minimum
  664. case WM_GETMINMAXINFO:
  665. MINMAXINFO *winfo;
  666. winfo = (MINMAXINFO*)(lParam);
  667. if(window && window->mMinimumSize.lenSquared() > 0)
  668. {
  669. winfo->ptMinTrackSize.x = window->mMinimumSize.x;
  670. winfo->ptMinTrackSize.y = window->mMinimumSize.y;
  671. }
  672. //Is the window size locked?
  673. if (window && window->isSizeLocked())
  674. {
  675. Point2I lockedSize = window->getLockedSize();
  676. winfo->ptMinTrackSize.x = lockedSize.x;
  677. winfo->ptMinTrackSize.y = lockedSize.y;
  678. winfo->ptMaxTrackSize.x = lockedSize.x;
  679. winfo->ptMaxTrackSize.y = lockedSize.y;
  680. }
  681. break;
  682. // Override background erase so window doesn't get cleared
  683. case WM_ERASEBKGND:
  684. return 1;
  685. case WM_MENUSELECT:
  686. winState.renderThreadBlocked = true;
  687. break;
  688. // Refresh the window
  689. case WM_PAINT:
  690. // Use validate instead of begin/end paint, which seem to installs
  691. // some Dx clipping state that isn't getting restored properly
  692. ValidateRect(hWnd,0);
  693. // Skip it if we're dispatching.
  694. if(Journal::IsDispatching())
  695. break;
  696. if( window == NULL )
  697. break;
  698. //// Default render if..
  699. //// 1. We have no device
  700. //// 2. We have a device but it's not allowing rendering
  701. if( !window->getGFXDevice() || !window->getGFXDevice()->allowRender() )
  702. window->defaultRender();
  703. if( winState.renderThreadBlocked )
  704. window->displayEvent.trigger(devId);
  705. break;
  706. // Power shutdown query
  707. case WM_POWERBROADCAST: {
  708. if (wParam == PBT_APMQUERYSUSPEND)
  709. if (GetForegroundWindow() == hWnd)
  710. return BROADCAST_QUERY_DENY;
  711. break;
  712. }
  713. // Screensaver activation and monitor power requests
  714. case WM_SYSCOMMAND:
  715. switch (wParam) {
  716. case SC_SCREENSAVE:
  717. case SC_MONITORPOWER:
  718. if (GetForegroundWindow() == hWnd)
  719. return SCREENSAVER_QUERY_DENY;
  720. break;
  721. }
  722. break;
  723. // Menus
  724. case WM_COMMAND:
  725. {
  726. winState.renderThreadBlocked = false;
  727. if( window == NULL )
  728. break;
  729. // [tom, 8/21/2006] Pass off to the relevant PopupMenu if it's a menu
  730. // or accelerator command. PopupMenu will in turn hand off to script.
  731. //
  732. // Note: PopupMenu::handleSelect() will not do anything if the menu
  733. // item is disabled, so we don't need to deal with that here.
  734. S32 numItems = GetMenuItemCount(window->getMenuHandle());
  735. for(S32 i = 0;i < numItems;i++)
  736. {
  737. MENUITEMINFOA mi;
  738. mi.cbSize = sizeof(mi);
  739. mi.fMask = MIIM_DATA;
  740. if(GetMenuItemInfoA(window->getMenuHandle(), i, TRUE, &mi))
  741. {
  742. if(mi.fMask & MIIM_DATA && mi.dwItemData != 0)
  743. {
  744. PopupMenu *mnu = (PopupMenu *)mi.dwItemData;
  745. PopupMenu::smSelectionEventHandled = false;
  746. PopupMenu::smPopupMenuEvent.trigger(mnu->getPopupGUID(), LOWORD(wParam));
  747. if (PopupMenu::smSelectionEventHandled)
  748. return 0;
  749. }
  750. }
  751. }
  752. }
  753. break;
  754. case WM_INITMENUPOPUP:
  755. {
  756. HMENU menu = (HMENU)wParam;
  757. MENUINFO mi;
  758. mi.cbSize = sizeof(mi);
  759. mi.fMask = MIM_MENUDATA;
  760. if(GetMenuInfo(menu, &mi) && mi.dwMenuData != 0)
  761. {
  762. PopupMenu *pm = (PopupMenu *)mi.dwMenuData;
  763. if(pm != NULL)
  764. pm->onMenuSelect();
  765. }
  766. }
  767. break;
  768. // Some events need to be consumed as well as queued up
  769. // for later dispatch.
  770. case WM_CLOSE:
  771. case WM_MOUSEWHEEL:
  772. #ifdef WM_MOUSEHWHEEL // Vista
  773. case WM_MOUSEHWHEEL:
  774. #endif
  775. // CodeReview This fixes some issues with inappropriate event handling
  776. // around device resets and in full-screen mode but feels
  777. // heavy-handed. Is it clobbering something important?
  778. // [bjg 6/13/07]
  779. case WM_KEYUP:
  780. case WM_KEYDOWN:
  781. case WM_SYSKEYUP:
  782. case WM_SYSKEYDOWN:
  783. Dispatch(DelayedDispatch,hWnd,message,wParam,lParam);
  784. return 0;
  785. }
  786. // Queue up for later and invoke the Windows default handler.
  787. Dispatch(DelayedDispatch,hWnd,message,wParam,lParam);
  788. return DefWindowProc(hWnd, message, wParam, lParam);
  789. }
  790. void Win32Window::defaultRender()
  791. {
  792. // Get Window Device Context
  793. HDC logoDC = GetDC(mWindowHandle);
  794. // Get Window Rectangle
  795. RECT lRect;
  796. GetClientRect(mWindowHandle,&lRect);
  797. // Fill with AppWorkspace color
  798. FillRect( logoDC, &lRect, (HBRUSH)GetSysColorBrush(COLOR_APPWORKSPACE) );
  799. // Release Device Context
  800. ReleaseDC(mWindowHandle,logoDC);
  801. }
  802. //-----------------------------------------------------------------------------
  803. // Accelerators
  804. //-----------------------------------------------------------------------------
  805. void Win32Window::addAccelerator(Accelerator &accel)
  806. {
  807. ACCEL winAccel;
  808. winAccel.fVirt = FVIRTKEY;
  809. winAccel.cmd = accel.mID;
  810. if(accel.mDescriptor.flags & SI_SHIFT)
  811. winAccel.fVirt |= FSHIFT;
  812. if(accel.mDescriptor.flags & SI_CTRL)
  813. winAccel.fVirt |= FCONTROL;
  814. if(accel.mDescriptor.flags & SI_ALT)
  815. winAccel.fVirt |= FALT;
  816. winAccel.key = TranslateKeyCodeToOS(accel.mDescriptor.eventCode);
  817. for(WinAccelList::iterator i = mWinAccelList.begin();i != mWinAccelList.end();++i)
  818. {
  819. if(i->cmd == winAccel.cmd)
  820. {
  821. // Already in list, just update it
  822. i->fVirt = winAccel.fVirt;
  823. i->key = winAccel.key;
  824. return;
  825. }
  826. if(i->fVirt == winAccel.fVirt && i->key == winAccel.key)
  827. {
  828. // Existing accelerator in list, don't add this one
  829. return;
  830. }
  831. }
  832. mWinAccelList.push_back(winAccel);
  833. }
  834. void Win32Window::removeAccelerator(Accelerator &accel)
  835. {
  836. for(WinAccelList::iterator i = mWinAccelList.begin();i != mWinAccelList.end();++i)
  837. {
  838. if(i->cmd == accel.mID)
  839. {
  840. mWinAccelList.erase(i);
  841. return;
  842. }
  843. }
  844. }
  845. //-----------------------------------------------------------------------------
  846. static bool isMenuItemIDEnabled(HMENU menu, U32 id)
  847. {
  848. S32 numItems = GetMenuItemCount(menu);
  849. for(S32 i = 0;i < numItems;i++)
  850. {
  851. MENUITEMINFOA mi;
  852. mi.cbSize = sizeof(mi);
  853. mi.fMask = MIIM_ID|MIIM_STATE|MIIM_SUBMENU|MIIM_DATA;
  854. if(GetMenuItemInfoA(menu, i, TRUE, &mi))
  855. {
  856. if(mi.fMask & MIIM_ID && mi.wID == id)
  857. {
  858. // This is an item on this menu
  859. return (mi.fMask & MIIM_STATE) && ! (mi.fState & MFS_DISABLED);
  860. }
  861. if((mi.fMask & MIIM_SUBMENU) && mi.hSubMenu != 0 && (mi.fMask & MIIM_DATA) && mi.dwItemData != 0)
  862. {
  863. // This is a submenu, if it can handle this ID then recurse to find correct state
  864. PopupMenu *mnu = (PopupMenu *)mi.dwItemData;
  865. if(mnu->canHandleID(id))
  866. return isMenuItemIDEnabled(mi.hSubMenu, id);
  867. }
  868. }
  869. }
  870. return false;
  871. }
  872. bool Win32Window::isAccelerator(const InputEventInfo &info)
  873. {
  874. U32 virt;
  875. virt = FVIRTKEY;
  876. if(info.modifier & SI_SHIFT)
  877. virt |= FSHIFT;
  878. if(info.modifier & SI_CTRL)
  879. virt |= FCONTROL;
  880. if(info.modifier & SI_ALT)
  881. virt |= FALT;
  882. U8 keyCode = TranslateKeyCodeToOS(info.objInst);
  883. for(S32 i = 0;i < mWinAccelList.size();++i)
  884. {
  885. const ACCEL &accel = mWinAccelList[i];
  886. if(accel.key == keyCode && accel.fVirt == virt && isMenuItemIDEnabled(getMenuHandle(), accel.cmd))
  887. return true;
  888. }
  889. return false;
  890. }
  891. //-----------------------------------------------------------------------------
  892. void Win32Window::addAccelerators(AcceleratorList &list)
  893. {
  894. if(mAccelHandle)
  895. {
  896. DestroyAcceleratorTable(mAccelHandle);
  897. mAccelHandle = NULL;
  898. }
  899. for(AcceleratorList::iterator i = list.begin();i != list.end();++i)
  900. {
  901. addAccelerator(*i);
  902. }
  903. if(mWinAccelList.size() > 0)
  904. mAccelHandle = CreateAcceleratorTable(&mWinAccelList[0], mWinAccelList.size());
  905. }
  906. void Win32Window::removeAccelerators(AcceleratorList &list)
  907. {
  908. if(mAccelHandle)
  909. {
  910. DestroyAcceleratorTable(mAccelHandle);
  911. mAccelHandle = NULL;
  912. }
  913. for(AcceleratorList::iterator i = list.begin();i != list.end();++i)
  914. {
  915. removeAccelerator(*i);
  916. }
  917. if(mWinAccelList.size() > 0)
  918. mAccelHandle = CreateAcceleratorTable(mWinAccelList.address(), mWinAccelList.size());
  919. }
  920. bool Win32Window::translateMessage(MSG &msg)
  921. {
  922. if(mAccelHandle == NULL || mWindowHandle == NULL || !mEnableAccelerators)
  923. return false;
  924. S32 ret = TranslateAccelerator(mWindowHandle, mAccelHandle, &msg);
  925. return ret != 0;
  926. }
  927. //-----------------------------------------------------------------------------
  928. // Mouse Locking
  929. //-----------------------------------------------------------------------------
  930. void Win32Window::setMouseLocked( bool enable )
  931. {
  932. if (mOffscreenRender)
  933. return;
  934. // Maintain a good state without unnecessary
  935. // cursor hides/modifications
  936. if( enable && mMouseLocked && mShouldLockMouse )
  937. return;
  938. else if(!enable && !mMouseLocked && !mShouldLockMouse )
  939. return;
  940. // Need to be focused to enable mouse lock
  941. // but we can disable it no problem if we're
  942. // not focused
  943. if( !isFocused() && enable )
  944. {
  945. mShouldLockMouse = enable;
  946. return;
  947. }
  948. // Set Flag
  949. mMouseLocked = enable;
  950. if( enable )
  951. {
  952. getCursorPosition( mMouseLockPosition );
  953. RECT r;
  954. GetWindowRect(getHWND(), &r);
  955. // Hide the cursor before it's moved
  956. setCursorVisible( false );
  957. // We have to nudge the cursor clip rect in a bit so we don't go out
  958. // side the bounds of the window... We'll just do it by 32 in all
  959. // directions, which will break for very small windows (< 200x200 or so)
  960. // but otherwise won't matter.
  961. RECT rCopy = r;
  962. rCopy.top += 32; rCopy.bottom -= 64;
  963. rCopy.left += 32; rCopy.right -= 64;
  964. ClipCursor(&rCopy);
  965. S32 centerX = (r.right + r.left) >> 1;
  966. S32 centerY = ((r.bottom + r.top) >> 1);
  967. // Consume all existing mouse events and those posted to our own dispatch queue
  968. MSG msg;
  969. PeekMessage( &msg, 0,WM_MOUSEFIRST,WM_MOUSELAST , PM_QS_POSTMESSAGE | PM_NOYIELD | PM_REMOVE );
  970. RemoveMessages( NULL, WM_MOUSEMOVE, WM_MOUSEMOVE );
  971. // Set the CursorPos
  972. SetCursorPos(centerX, centerY);
  973. // reset should lock flag
  974. mShouldLockMouse = true;
  975. }
  976. else
  977. {
  978. // This belongs before the unlock code
  979. mShouldLockMouse = false;
  980. ClipCursor(NULL);
  981. setCursorPosition( mMouseLockPosition.x,mMouseLockPosition.y );
  982. // Consume all existing mouse events and those posted to our own dispatch queue
  983. MSG msg;
  984. PeekMessage( &msg, NULL,WM_MOUSEFIRST,WM_MOUSELAST , PM_QS_POSTMESSAGE | PM_NOYIELD | PM_REMOVE );
  985. RemoveMessages( NULL, WM_MOUSEMOVE, WM_MOUSEMOVE );
  986. // Show the Cursor
  987. setCursorVisible( true );
  988. }
  989. }
  990. const UTF16 *Win32Window::getWindowClassName()
  991. {
  992. return _MainWindowClassName;
  993. }
  994. const UTF16 *Win32Window::getCurtainWindowClassName()
  995. {
  996. return _CurtainWindowClassName;
  997. }
  998. #endif