void sdl_monitor_info::refresh() { #if (SDLMAME_SDL2) SDL_DisplayMode dmode; #if defined(SDLMAME_WIN32) SDL_GetDesktopDisplayMode(m_handle, &dmode); #else SDL_GetCurrentDisplayMode(m_handle, &dmode); #endif SDL_Rect dimensions; SDL_GetDisplayBounds(m_handle, &dimensions); m_pos_size = SDL_Rect_to_osd_rect(dimensions); m_usuable_pos_size = SDL_Rect_to_osd_rect(dimensions); m_is_primary = (m_handle == 0); #else #if defined(SDLMAME_WIN32) // Win32 version MONITORINFOEX info; info.cbSize = sizeof(info); GetMonitorInfo((HMONITOR)m_handle, (LPMONITORINFO)&info); m_pos_size = RECT_to_osd_rect(info.rcMonitor); m_usuable_pos_size = RECT_to_osd_rect(info.rcWork); m_is_primary = ((info.dwFlags & MONITORINFOF_PRIMARY) != 0); char *temp = utf8_from_wstring(info.szDevice); strncpy(m_name, temp, ARRAY_LENGTH(m_name) - 1); osd_free(temp); #elif defined(SDLMAME_MACOSX) // Mac OS X Core Imaging version CGDirectDisplayID primary; CGRect dbounds; // get the main display primary = CGMainDisplayID(); dbounds = CGDisplayBounds(primary); m_is_primary = (m_handle == 0); m_pos_size = osd_rect(0, 0, dbounds.size.width - dbounds.origin.x, dbounds.size.height - dbounds.origin.y); m_usuable_pos_size = m_pos_size; strncpy(m_name, "Mac OS X display", ARRAY_LENGTH(m_name) - 1); #elif defined(SDLMAME_X11) || defined(SDLMAME_NO_X11) // X11 version { #if defined(SDLMAME_X11) // X11 version int screen; SDL_SysWMinfo info; SDL_VERSION(&info.version); if ( SDL_GetWMInfo(&info) && (info.subsystem == SDL_SYSWM_X11) ) { screen = DefaultScreen(info.info.x11.display); SDL_VideoDriverName(m_name, ARRAY_LENGTH(m_name) - 1); m_pos_size = osd_rect(0, 0, DisplayWidth(info.info.x11.display, screen), DisplayHeight(info.info.x11.display, screen)); /* FIXME: If Xinerame is used we should compile a list of monitors * like we do for other targets and ignore SDL. */ if ((XineramaIsActive(info.info.x11.display)) && video_config.restrictonemonitor) { XineramaScreenInfo *xineinfo; int numscreens; xineinfo = XineramaQueryScreens(info.info.x11.display, &numscreens); m_pos_size = osd_rect(0, 0, xineinfo[0].width, xineinfo[0].height); XFree(xineinfo); } m_usuable_pos_size = m_pos_size; m_is_primary = (m_handle == 0); } else #endif // defined(SDLMAME_X11) { static int first_call=0; static int cw = 0, ch = 0; SDL_VideoDriverName(m_name, ARRAY_LENGTH(m_name) - 1); if (first_call==0) { const char *dimstr = osd_getenv(SDLENV_DESKTOPDIM); const SDL_VideoInfo *sdl_vi; sdl_vi = SDL_GetVideoInfo(); #if (SDL_VERSION_ATLEAST(1,2,10)) cw = sdl_vi->current_w; ch = sdl_vi->current_h; #endif first_call=1; if ((cw==0) || (ch==0)) { if (dimstr != NULL) { sscanf(dimstr, "%dx%d", &cw, &ch); } if ((cw==0) || (ch==0)) { osd_printf_warning("WARNING: SDL_GetVideoInfo() for driver <%s> is broken.\n", m_name); osd_printf_warning(" You should set SDLMAME_DESKTOPDIM to your desktop size.\n"); osd_printf_warning(" e.g. export SDLMAME_DESKTOPDIM=800x600\n"); osd_printf_warning(" Assuming 1024x768 now!\n"); cw=1024; ch=768; } } } m_pos_size = osd_rect(0, 0, cw, ch); m_usuable_pos_size = m_pos_size; m_is_primary = (m_handle == 0); } } #elif defined(SDLMAME_OS2) // OS2 version m_pos_size = osd_rect(0, 0, WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ), WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) ); m_usuable_pos_size = m_pos_size; m_is_primary = (m_handle == 0); strncpy(m_name, "OS/2 display", ARRAY_LENGTH(m_name) - 1); #else #error Unknown SDLMAME_xx OS type! #endif { static int info_shown=0; if (!info_shown) { osd_printf_verbose("SDL Device Driver : %s\n", m_name); osd_printf_verbose("SDL Monitor Dimensions: %d x %d\n", m_pos_size.width(), m_pos_size.height()); info_shown = 1; } } #endif // (SDLMAME_SDL2) }
//**************************************************************************************** void CBCGPDropDownFrame::RecalcLayout (BOOL /*bNotify*/) { #ifdef _DEBUG if (m_pParentBtn != NULL) { ASSERT_VALID (m_pParentBtn); ASSERT (m_pParentBtn->m_pPopupMenu == this); } #endif // _DEBUG if (!::IsWindow (m_hWnd) || !::IsWindow (m_wndToolBar.m_hWnd)) { return; } CBCGPToolBar* pParentBar = m_pParentBtn == NULL ? NULL : DYNAMIC_DOWNCAST (CBCGPToolBar, m_pParentBtn->m_pWndParent); BOOL bHorz = pParentBar->IsHorizontal (); CSize size = m_wndToolBar.CalcSize(bHorz); size.cx += iBorderSize * 3; size.cy += iBorderSize * 4; //--------------------------------------------- // Adjust the menu position by the screen size: //--------------------------------------------- CRect rectScreen; MONITORINFO mi; mi.cbSize = sizeof (MONITORINFO); if (GetMonitorInfo (MonitorFromPoint (CPoint (m_x, m_y), MONITOR_DEFAULTTONEAREST), &mi)) { rectScreen = mi.rcWork; } else { ::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0); } if (m_x + size.cx > rectScreen.right) { //----------------------------------------------------- // Menu can't be overlapped with the parent popup menu! //----------------------------------------------------- CBCGPToolBar* pParentBar = m_pParentBtn == NULL ? NULL : DYNAMIC_DOWNCAST (CBCGPToolBar, m_pParentBtn->m_pWndParent); if (pParentBar != NULL && (pParentBar->IsHorizontal ()) == 0) { //------------------------------------------------ // Parent menu bar is docked vertical, place menu // in the left or right side of the parent frame: //------------------------------------------------ CRect rectParent; pParentBar->GetWindowRect (rectParent); m_x = rectParent.left - size.cx; } else { m_x = rectScreen.Width () - size.cx - 1; } } if (m_y + size.cy > rectScreen.bottom) { m_y -= size.cy; if (m_pParentBtn != NULL) { m_y -= m_pParentBtn->m_rect.Height () + 4; } else if (m_y < 0) { m_y = 0; } } SetWindowPos (NULL, m_x, m_y, size.cx, size.cy, SWP_NOZORDER | SWP_NOACTIVATE); }
bool UpdatePopupPosition(PopupWnd2 *prev, PopupWnd2 *wnd) { if (!wnd) return false; if (!PopupOptions.ReorderPopups && wnd->isPositioned()) return false; int POPUP_SPACING = PopupOptions.spacing; POINT pos = { 0 }; SIZE prevSize = { 0 }; if (prev) prevSize = prev->getSize(); // we have only one monitor (cant check it together with 1.if) RECT rc; if (GetSystemMetrics(SM_CMONITORS) == 1) SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); else { // Multimonitor stuff (we have more then 1) HWND hWnd; if (PopupOptions.Monitor == MN_MIRANDA) hWnd = pcli->hwndContactList; else // PopupOptions.Monitor == MN_ACTIVE hWnd = GetForegroundWindow(); HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY); MONITORINFOEX mnti; mnti.cbSize = sizeof(MONITORINFOEX); if (GetMonitorInfo(hMonitor, &mnti) == TRUE) memcpy(&rc, &(mnti.rcWork), sizeof(RECT)); else SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); } rc.left += PopupOptions.gapLeft - POPUP_SPACING; rc.right -= PopupOptions.gapRight - POPUP_SPACING; rc.top += PopupOptions.gapTop - POPUP_SPACING; rc.bottom -= PopupOptions.gapBottom - POPUP_SPACING; if (PopupOptions.Spreading == SPREADING_VERTICAL) { switch (PopupOptions.Position) { case POS_UPPERLEFT: pos.x = rc.left + POPUP_SPACING; pos.y = (prev ? (prev->getPosition().y + prev->getSize().cy) : rc.top) + POPUP_SPACING; break; case POS_LOWERLEFT: pos.x = rc.left + POPUP_SPACING; pos.y = (prev ? prev->getPosition().y : rc.bottom) - wnd->getSize().cy - POPUP_SPACING; break; case POS_LOWERRIGHT: pos.x = rc.right - wnd->getSize().cx - POPUP_SPACING; pos.y = (prev ? prev->getPosition().y : rc.bottom) - wnd->getSize().cy - POPUP_SPACING; break; case POS_UPPERRIGHT: pos.x = rc.right - wnd->getSize().cx - POPUP_SPACING; pos.y = (prev ? (prev->getPosition().y + prev->getSize().cy) : rc.top) + POPUP_SPACING; break; } } else { switch (PopupOptions.Position) { case POS_UPPERLEFT: pos.x = (prev ? (prev->getPosition().x + prev->getSize().cx) : rc.left) + POPUP_SPACING; pos.y = rc.top + POPUP_SPACING; break; case POS_LOWERLEFT: pos.x = (prev ? (prev->getPosition().x + prev->getSize().cx) : rc.left) + POPUP_SPACING; pos.y = rc.bottom - wnd->getSize().cy - POPUP_SPACING; break; case POS_LOWERRIGHT: pos.x = (prev ? prev->getPosition().x : rc.right) - wnd->getSize().cx - POPUP_SPACING; pos.y = rc.bottom - wnd->getSize().cy - POPUP_SPACING; break; case POS_UPPERRIGHT: pos.x = (prev ? prev->getPosition().x : rc.right) - wnd->getSize().cx - POPUP_SPACING; pos.y = rc.top + POPUP_SPACING; break; } } wnd->setPosition(pos); return true; }
void Win32EGLWindow::createNativeWindow( int &left, int &top, uint &width, uint &height, String &title ) { // destroy current window, if any if (mWindow) destroy(); #ifdef OGRE_STATIC_LIB HINSTANCE hInst = GetModuleHandle( NULL ); #else # if OGRE_DEBUG_MODE == 1 HINSTANCE hInst = GetModuleHandle("RenderSystem_GLES_d.dll"); # else HINSTANCE hInst = GetModuleHandle("RenderSystem_GLES.dll"); # endif #endif mWindow = 0; mClosed = false; mIsDepthBuffered = true; mColourDepth = mIsFullScreen? 32 : GetDeviceCaps(GetDC(0), BITSPIXEL); HWND parent = 0; bool vsync = false; String border; bool outerSize = false; bool hwGamma = false; int monitorIndex = -1; HMONITOR hMonitor = NULL; if (!mIsExternal) { DWORD dwStyle = WS_VISIBLE | WS_CLIPCHILDREN; DWORD dwStyleEx = 0; MONITORINFOEX monitorInfoEx; RECT rc; // If we didn't specified the adapter index, or if it didn't find it if (hMonitor == NULL) { POINT windowAnchorPoint; // Fill in anchor point. windowAnchorPoint.x = left; windowAnchorPoint.y = top; // Get the nearest monitor to this window. hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTONEAREST); } // Get the target monitor info memset(&monitorInfoEx, 0, sizeof(MONITORINFOEX)); monitorInfoEx.cbSize = sizeof(MONITORINFOEX); GetMonitorInfo(hMonitor, &monitorInfoEx); //size_t devNameLen = strlen(monitorInfoEx.szDevice); //mDeviceName = new char[devNameLen + 1]; //strcpy(mDeviceName, monitorInfoEx.szDevice); // No specified top left -> Center the window in the middle of the monitor if (left == -1 || top == -1) { int screenw = monitorInfoEx.rcMonitor.right - monitorInfoEx.rcMonitor.left; int screenh = monitorInfoEx.rcMonitor.bottom - monitorInfoEx.rcMonitor.top; SetRect(&rc, 0, 0, width, height); AdjustWindowRect(&rc, dwStyle, false); // clamp window dimensions to screen size int outerw = (rc.right-rc.left < screenw)? rc.right-rc.left : screenw; int outerh = (rc.bottom-rc.top < screenh)? rc.bottom-rc.top : screenh; if (left == -1) left = monitorInfoEx.rcMonitor.left + (screenw - outerw) / 2; else if (monitorIndex != -1) left += monitorInfoEx.rcMonitor.left; if (top == -1) top = monitorInfoEx.rcMonitor.top + (screenh - outerh) / 2; else if (monitorIndex != -1) top += monitorInfoEx.rcMonitor.top; } else if (monitorIndex != -1) { left += monitorInfoEx.rcMonitor.left; top += monitorInfoEx.rcMonitor.top; } mWidth = width; mHeight = height; mTop = top; mLeft = left; if (mIsFullScreen) { dwStyle |= WS_POPUP; dwStyleEx |= WS_EX_TOPMOST; mTop = monitorInfoEx.rcMonitor.top; mLeft = monitorInfoEx.rcMonitor.left; } else { if (parent) { dwStyle |= WS_CHILD; } else { if (border == "none") dwStyle |= WS_POPUP; else if (border == "fixed") dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; else dwStyle |= WS_OVERLAPPEDWINDOW; } int screenw = GetSystemMetrics(SM_CXSCREEN); int screenh = GetSystemMetrics(SM_CYSCREEN); if (!outerSize) { // Calculate window dimensions required // to get the requested client area SetRect(&rc, 0, 0, mWidth, mHeight); AdjustWindowRect(&rc, dwStyle, false); mWidth = rc.right - rc.left; mHeight = rc.bottom - rc.top; // Clamp window rect to the nearest display monitor. if (mLeft < monitorInfoEx.rcMonitor.left) mLeft = monitorInfoEx.rcMonitor.left; if (mTop < monitorInfoEx.rcMonitor.top) mTop = monitorInfoEx.rcMonitor.top; if ((int)mWidth > monitorInfoEx.rcMonitor.right - mLeft) mWidth = monitorInfoEx.rcMonitor.right - mLeft; if ((int)mHeight > monitorInfoEx.rcMonitor.bottom - mTop) mHeight = monitorInfoEx.rcMonitor.bottom - mTop; } } // register class and create window WNDCLASS wc = { CS_OWNDC, WindowEventUtilities::_WndProc, 0, 0, hInst, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), (HBRUSH)GetStockObject(BLACK_BRUSH), NULL, "OgreGLWindow" }; RegisterClass(&wc); if (mIsFullScreen) { DEVMODE displayDeviceMode; memset(&displayDeviceMode, 0, sizeof(displayDeviceMode)); displayDeviceMode.dmSize = sizeof(DEVMODE); displayDeviceMode.dmBitsPerPel = mColourDepth; displayDeviceMode.dmPelsWidth = mWidth; displayDeviceMode.dmPelsHeight = mHeight; displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; /* if (mDisplayFrequency) { displayDeviceMode.dmDisplayFrequency = mDisplayFrequency; displayDeviceMode.dmFields |= DM_DISPLAYFREQUENCY; if (ChangeDisplaySettingsEx(mDeviceName, &displayDeviceMode, NULL, CDS_FULLSCREEN | CDS_TEST, NULL) != DISP_CHANGE_SUCCESSFUL) { LogManager::getSingleton().logMessage(LML_NORMAL, "ChangeDisplaySettings with user display frequency failed"); displayDeviceMode.dmFields ^= DM_DISPLAYFREQUENCY; } } if (ChangeDisplaySettingsEx(mDeviceName, &displayDeviceMode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL) LogManager::getSingleton().logMessage(LML_CRITICAL, "ChangeDisplaySettings failed"); */ } // Pass pointer to self as WM_CREATE parameter mWindow = CreateWindowEx(dwStyleEx, "OgreGLWindow", title.c_str(), dwStyle, mLeft, mTop, mWidth, mHeight, parent, 0, hInst, this); WindowEventUtilities::_addRenderWindow(this); LogManager::getSingleton().stream() << "Created Win32Window '" << mName << "' : " << mWidth << "x" << mHeight << ", " << mColourDepth << "bpp"; } RECT rc; // top and left represent outer window position GetWindowRect(mWindow, &rc); mTop = rc.top; mLeft = rc.left; // width and height represent drawable area only GetClientRect(mWindow, &rc); mWidth = rc.right; mHeight = rc.bottom; mNativeDisplay = GetDC(mWindow); mEglDisplay = eglGetDisplay(mNativeDisplay); mGLSupport->setGLDisplay(mEglDisplay); mEglSurface = createSurfaceFromWindow(mEglDisplay, mWindow); }
void InitOutput(ScreenInfo * pScreenInfo, int argc, char *argv[]) { int i; if (serverGeneration == 1) XwinExtensionInit(); /* Log the command line */ winLogCommandLine(argc, argv); #if CYGDEBUG winDebug("InitOutput\n"); #endif /* Validate command-line arguments */ if (serverGeneration == 1 && !winValidateArgs()) { FatalError("InitOutput - Invalid command-line arguments found. " "Exiting.\n"); } #ifdef XWIN_XF86CONFIG /* Try to read the xorg.conf-style configuration file */ if (!winReadConfigfile()) winErrorFVerb(1, "InitOutput - Error reading config file\n"); #else winMsg(X_INFO, "xorg.conf is not supported\n"); winMsg(X_INFO, "See http://x.cygwin.com/docs/faq/cygwin-x-faq.html " "for more information\n"); winConfigFiles(); #endif /* Load preferences from XWinrc file */ LoadPreferences(); /* Setup global screen info parameters */ pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER; pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD; pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER; pScreenInfo->numPixmapFormats = NUMFORMATS; /* Describe how we want common pixmap formats padded */ for (i = 0; i < NUMFORMATS; i++) { pScreenInfo->formats[i] = g_PixmapFormats[i]; } /* Load pointers to DirectDraw functions */ winGetDDProcAddresses(); /* Detect supported engines */ winDetectSupportedEngines(); #ifdef XWIN_MULTIWINDOW /* Load libraries for taskbar grouping */ winPropertyStoreInit(); #endif /* Store the instance handle */ g_hInstance = GetModuleHandle(NULL); /* Create the messaging window */ if (serverGeneration == 1) winCreateMsgWindowThread(); /* Initialize each screen */ for (i = 0; i < g_iNumScreens; ++i) { /* Initialize the screen */ if (-1 == AddScreen(winScreenInit, argc, argv)) { FatalError("InitOutput - Couldn't add screen %d", i); } } /* Unless full xinerama has been explicitly enabled, register all native screens with pseudoramiX */ if (!noPanoramiXExtension) noPseudoramiXExtension = TRUE; if ((g_ScreenInfo[0].fMultipleMonitors) && !noPseudoramiXExtension) { int pass; noRRXineramaExtension = TRUE; PseudoramiXExtensionInit(); /* Add primary monitor on pass 0, other monitors on pass 1, to ensure the primary monitor is first in XINERAMA list */ for (pass = 0; pass < 2; pass++) { int iMonitor; for (iMonitor = 1; ; iMonitor++) { struct GetMonitorInfoData data; QueryMonitor(iMonitor, &data); if (data.bMonitorSpecifiedExists) { MONITORINFO mi; mi.cbSize = sizeof(MONITORINFO); if (GetMonitorInfo(data.monitorHandle, &mi)) { /* pass == 1 XOR primary monitor flags is set */ if ((!(pass == 1)) != (!(mi.dwFlags & MONITORINFOF_PRIMARY))) { /* Note the screen origin in a normalized coordinate space where (0,0) is at the top left of the native virtual desktop area */ data.monitorOffsetX = data.monitorOffsetX - GetSystemMetrics(SM_XVIRTUALSCREEN); data.monitorOffsetY = data.monitorOffsetY - GetSystemMetrics(SM_YVIRTUALSCREEN); winDebug ("InitOutput - screen %d added at virtual desktop coordinate (%d,%d) (pseudoramiX) \n", iMonitor-1, data.monitorOffsetX, data.monitorOffsetY); PseudoramiXAddScreen(data.monitorOffsetX, data.monitorOffsetY, data.monitorWidth, data.monitorHeight); } } } else break; } } } #if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) /* Generate a cookie used by internal clients for authorization */ if (g_fXdmcpEnabled || g_fAuthEnabled) winGenerateAuthorization(); /* Perform some one time initialization */ if (1 == serverGeneration) { /* Allow multiple threads to access Xlib */ if (XInitThreads() == 0) { ErrorF("XInitThreads failed.\n"); } /* * setlocale applies to all threads in the current process. * Apply locale specified in LANG environment variable. */ if (!setlocale(LC_ALL, "")) { ErrorF("setlocale failed.\n"); } /* See if X supports the current locale */ if (XSupportsLocale() == FALSE) { ErrorF("Warning: Locale not supported by X, falling back to 'C' locale.\n"); setlocale(LC_ALL, "C"); } } #endif #if CYGDEBUG || YES winDebug("InitOutput - Returning.\n"); #endif }
MONITORINFO DisplayManager::Info(HMONITOR monitor) { MONITORINFO mInfo = {}; mInfo.cbSize = sizeof(MONITORINFO); GetMonitorInfo(monitor, &mInfo); return mInfo; }
//--------------------------------------------------------------------------- bool CInternalWindow::BeginSplash() { #ifdef _WIN32 // load bitmap HANDLE hbmpSplash = LoadImage(GetModuleHandle( NULL ), _W("splash.bmp"), IMAGE_BITMAP, 0,0, LR_DEFAULTSIZE | LR_LOADFROMFILE); if (!hbmpSplash) return false; // Register splash class WNDCLASS wc = { 0 }; wc.lpfnWndProc = DefWindowProc; wc.hInstance = GetModuleHandle( NULL ); wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = _W("P3DSplash"); RegisterClass(&wc); // Create splash window and layered content widget m_hsplash = CreateWindow(_W("P3DSplash"), NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, wc.hInstance, NULL); HWND m_hlayered = CreateWindowEx(WS_EX_LAYERED, _W("P3DSplash"), NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, m_hsplash, NULL, wc.hInstance, NULL); // get the size of the bitmap BITMAP bm; GetObjectW(hbmpSplash, sizeof(bm), &bm); SIZE sizeSplash = { bm.bmWidth, bm.bmHeight }; // get the primary monitor's info POINT ptZero = { 0 }; HMONITOR hmonPrimary = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY); MONITORINFO monitorinfo = { 0 }; monitorinfo.cbSize = sizeof(monitorinfo); GetMonitorInfo(hmonPrimary, &monitorinfo); // center the splash screen in the middle of the primary work area const RECT & rcWork = monitorinfo.rcWork; POINT ptOrigin; ptOrigin.x = rcWork.left + (rcWork.right - rcWork.left - sizeSplash.cx) / 2; ptOrigin.y = rcWork.top + (rcWork.bottom - rcWork.top - sizeSplash.cy) / 2; // create a memory DC holding the splash bitmap HDC hdcScreen = GetDC(NULL); HDC hdcMem = CreateCompatibleDC(hdcScreen); HBITMAP hbmpOld = (HBITMAP) SelectObject(hdcMem, hbmpSplash); // use the source image's alpha channel for blending BLENDFUNCTION blend = { 0 }; blend.BlendOp = AC_SRC_OVER; blend.SourceConstantAlpha = 255; blend.AlphaFormat = AC_SRC_ALPHA; // paint the window (in the right location) with the alpha-blended bitmap UpdateLayeredWindow(m_hlayered, hdcScreen, &ptOrigin, &sizeSplash, hdcMem, &ptZero, RGB(0, 0, 0), &blend, ULW_ALPHA); // delete temporary objects SelectObject(hdcMem, hbmpOld); DeleteDC(hdcMem); ReleaseDC(NULL, hdcScreen); #elif defined(X_WIN_PRESENT) //load the splash image using Imlib2 Imlib_Image image = imlib_load_image("splash.bmp"); if(!image) return false; imlib_context_set_image(image); //obtain root window (current screen) attributes int screen = DefaultScreen(m_display); XWindowAttributes rootWinAttribs; XGetWindowAttributes #endif return true; }
int _tmain(int argc, _TCHAR* argv[]) { //---------------- hLog = fopen("log.txt", "w"); LPCTSTR path = L".\\options.ini"; TCHAR stecilPicturePathResult[4096]; TCHAR maskedPicturePathResult[4096]; TCHAR serverPortResult[255]; TCHAR serverIPResult[255]; TCHAR listenUDPPortResult[255]; TCHAR listenUDPIPResult[255]; TCHAR colorResult[255]; TCHAR shiftXResult[255]; TCHAR shiftYResult[255]; TCHAR isEyeWindowShowResult[255]; TCHAR isEyePositionWindowShowResult[255]; TCHAR isCalibrateResult[255]; char buffer[4096]; GetPrivateProfileString(_T("Base"), _T("stecilPicturePath"), _T(""), stecilPicturePathResult, sizeof(buffer), path); GetPrivateProfileString(_T("Base"), _T("maskedPicturePath"), _T(""), maskedPicturePathResult, sizeof(buffer), path); GetPrivateProfileString(_T("Base"), _T("serverPort"), _T(""), serverPortResult, 255, path); GetPrivateProfileString(_T("Base"), _T("serverIP"), _T(""), serverIPResult, 255, path); GetPrivateProfileString(_T("Base"), _T("listenUDPPort"), _T(""), listenUDPPortResult, 255, path); GetPrivateProfileString(_T("Base"), _T("listenUDPIP"), _T(""), listenUDPIPResult, 255, path); GetPrivateProfileString(_T("Base"), _T("color"), _T(""), colorResult, 255, path); GetPrivateProfileString(_T("Base"), _T("shiftX"), _T(""), shiftXResult, 255, path); GetPrivateProfileString(_T("Base"), _T("shiftY"), _T(""), shiftYResult, 255, path); GetPrivateProfileString(_T("Base"), _T("isEyeWindowShow"), _T(""), isEyeWindowShowResult, 255, path); GetPrivateProfileString(_T("Base"), _T("isEyePositionWindowShow"), _T(""), isEyePositionWindowShowResult, 255, path); GetPrivateProfileString(_T("Base"), _T("isCalibrate"), _T(""), isCalibrateResult, 255, path); int shiftXint = _ttoi(shiftXResult); int shiftYint = _ttoi(shiftYResult); int serverPortint = _ttoi(serverPortResult); int listenUDPPortint = _ttoi(listenUDPPortResult); desiredColor = wcstoul(colorResult, NULL, 0x10); char serverIPChar[255]; wcstombs(serverIPChar, serverIPResult, wcslen(serverIPResult) + 1); char listenUDPIPChar[255]; wcstombs(listenUDPIPChar, listenUDPIPResult, wcslen(listenUDPIPResult) + 1); bool isEyeWindowShowBool = false; bool isEyePositionWindowShow = false; bool isCalibrate = false; if(_tcscmp(isEyeWindowShowResult, L"true") == 0){ isEyeWindowShowBool = true; } if(_tcscmp(isEyePositionWindowShowResult, L"true") == 0){ isEyePositionWindowShow = true; } if(_tcscmp(isCalibrateResult, L"true") == 0){ isCalibrate = true; } //getchar(); //return 0; // screenMasker.exe 757575 checker4px.pgm stencil.pgm 23 45 Y" // parse arguments //E:\OrlovPA\screenMasker\screenmasker\screenMasker_bin\screenMasker_bin\screenMasker.exe 757575 bg.pgm stencil.pgm 0 //LPWSTR *argc; //LPWSTR bgPath; //wchar_t newBgPath[] = L"E:\\OrlovPA\\screenMasker\\screenmasker\\screenMasker_bin\\screenMasker_bin\\bg.pgm"; //wchar_t newBgPath[] = maskedPicturePathResult; //LPWSTR stencilPath; //wchar_t newStencilPath[] = L"E:\\OrlovPA\\screenMasker\\screenmasker\\screenMasker_bin\\screenMasker_bin\\stencil.pgm"; //int localstencilX, localstencilY, localCoursor; //wchar_t myColor = '757575'; //const wchar_t * myColorAdress = &myColor; //desiredColor = wcstoul(L"1a3399", NULL, 0x10); //desiredColor = 757575; isCoursor = 1; // read background and stencil to buffers UINT8 *bytes; int width; int height; //bytes = readPGM(bgPath, &width, &height); bytes = readPGM(maskedPicturePathResult, &width, &height); //bytes = readPGM(newBgPath, &width, &height); if(bytes == NULL) { return 1; } bgBmpBytes = bytes; bgBmpWidth = width; bgBmpHeight = height; //bytes = readPGM(newStencilPath, &width, &height); bytes = readPGM(stecilPicturePathResult, &width, &height); if(bytes == NULL){ return 1; } stencilBmpBytes = bytes; stencilBmpWidth = width; stencilBmpHeight = height; //---------------- POINT pt = {}; HMONITOR hMon; MONITORINFO monitorInfo = {}; GetCursorPos(&pt); hMon = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY); monitorInfo.cbSize = sizeof(MONITORINFO); GetMonitorInfo(hMon, &monitorInfo); mX = monitorInfo.rcMonitor.left; mY = monitorInfo.rcMonitor.top; mW = monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left; mH = monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top; WNDCLASSEX wc; MSG msg; // Init wc wc.cbSize = sizeof( WNDCLASSEX ); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetModuleHandle(0); wc.hIcon = NULL; wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = NULL; wc.hIconSm = NULL; wc.lpszClassName = toString("animation_class"); wc.lpszMenuName = NULL; // Register wc if ( !RegisterClassEx(&wc) ) { MessageBox( NULL, toString("Failed to register window class."), toString("Error"), MB_OK ); return 0; } // Make window hwnd = CreateWindowEx( //WS_EX_APPWINDOW, WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TRANSPARENT, toString("animation_class"), toString("Animation"), WS_POPUP | WS_SYSMENU, mX, mY, mW, mH, NULL, NULL, GetModuleHandle(0), NULL ); assert(hwnd); /* RECT rcClient, rcWindow; POINT ptDiff; // Get window and client sizes GetClientRect( hwnd, &rcClient ); GetWindowRect( hwnd, &rcWindow ); // Find offset between window size and client size ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right; ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom; // Resize client MoveWindow( hwnd, rcWindow.left, rcWindow.top, width + ptDiff.x, height + ptDiff.y, false); //UpdateLayeredWindow(hwnd, NULL, &ptDst, &siz, hdcOutBmp, &ptZero, 0, &blendFunc, ULW_ALPHA); //SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 0x0, LWA_COLORKEY); */ ShowWindow( hwnd, SW_SHOWDEFAULT ); UpdateWindow( hwnd ); initGpuResources( bgBmpBytes, stencilBmpBytes, bgBmpWidth, bgBmpHeight, stencilBmpHeight, stencilBmpWidth, mW, mH ); //**************************** AccuracyStruct accuracyData; SystemInfoStruct systemInfoData; CalibrationStruct calibrationData; int ret_calibrate = 0, ret_validate = 0, ret_connect = 0; char c = ' '; char repeat = ' '; std::cout << "Output from iViewXAPI Demo"<< std::endl; // define logger iV_SetLogger(1, "ScreenMasker.txt"); std::cout << "ScreenMasker on iViewX API" << std::endl; // connect to iViewX ret_connect = iV_Connect(serverIPChar, serverPortint, listenUDPIPChar, listenUDPPortint); switch(ret_connect) { case RET_SUCCESS: std::cout << "Connection was established successfully" << std::endl; // read out meta data from iViewX std::cout << "GetSystemInfo: " << iV_GetSystemInfo(&systemInfoData) << std::endl; std::cout << "SystemInfo ETSystem: " << systemInfoData.iV_ETDevice << std::endl; std::cout << "SystemInfo iV_Version: " << systemInfoData.iV_MajorVersion << "." << systemInfoData.iV_MinorVersion << "." << systemInfoData.iV_Buildnumber << std::endl; std::cout << "SystemInfo API_Version: " << systemInfoData.API_MajorVersion << "." << systemInfoData.API_MinorVersion << "." << systemInfoData.API_Buildnumber << std::endl; std::cout << "SystemInfo samplerate: " << systemInfoData.samplerate << std::endl; break; case ERR_COULD_NOT_CONNECT: std::cout << "Connection could not be established" << std::endl; break; case ERR_WRONG_PARAMETER: std::cout << "Wrong Parameter used" << std::endl; break; default: std::cout << "Any other error appeared" << std::endl; return 0; } if(ret_connect == RET_SUCCESS) { calibrationData.method = 5; calibrationData.speed = 0; calibrationData.displayDevice = 0; calibrationData.targetShape = 20; calibrationData.foregroundBrightness = 250; calibrationData.backgroundBrightness = 100; calibrationData.autoAccept = 1; calibrationData.targetSize = 10; calibrationData.visualization = 1; strcpy(calibrationData.targetFilename, ""); iV_SetupCalibration(&calibrationData); // start calibration //std::cout << "Do you want to calibrate? (y)es | (n)o" << std::endl; //c = getchar(); if(isCalibrate){ ret_calibrate = iV_Calibrate(); switch(ret_calibrate){ case RET_SUCCESS: std::cout << "Calibration done successfully" << std::endl; // start validation ret_validate = iV_Validate(); break; case ERR_NOT_CONNECTED: std::cout << "iViewX is not reachable" << std::endl; break; case ERR_WRONG_PARAMETER: std::cout << "Wrong Parameter used" << std::endl; break; case ERR_WRONG_DEVICE: std::cout << "Not possible to calibrate connected Eye Tracking System" << std::endl; break; default: std::cout << "An unknown error appeared" << std::endl; break; } } // show accuracy only if validation was successful if(ret_validate == RET_SUCCESS){ std::cout << "iV_GetAccuracy: " << iV_GetAccuracy(&accuracyData, 0) << std::endl; std::cout << "AccuracyData DevX: " << accuracyData.deviationLX << " DevY: " << accuracyData.deviationLY << std::endl; //getchar(); } if(isEyeWindowShowBool){ iV_ShowEyeImageMonitor(); } if(isEyePositionWindowShow){ iV_ShowTrackingMonitor(); iV_ShowSceneVideoMonitor(); } // start data output via callback function // define a callback function for receiving samples iV_SetSampleCallback(SampleCallbackFunction); iV_SetTrackingMonitorCallback(TrackingMonitorCallbackFunction); while ( GetMessage(&msg, 0, 0, NULL) > 0 ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } /* getchar(); iV_SetSampleCallback(NULL); iV_SetTrackingMonitorCallback(NULL); std::cout << "iV_Disconnect: " << iV_Disconnect() << std::endl; getchar(); */ } freeGpuResources(); fclose(hLog); return 0; }
/* createwindow(). Creates a new window, _w * _h in size, optionally fullscreen. */ HWND CDisplayDX::createwindow( uint32 _w, uint32 _h, const bool _bFullscreen ) { m_bFullScreen = _bFullscreen; HMODULE hInstance = GetModuleHandle(NULL); EnumMonitors(); WNDCLASS wndclass = {0}; RECT windowRect; SetRect( &windowRect, 0, 0, _w, _h ); g_Log->Info( "CDisplayDX::createwindow x=%u y=%u w=%u h=%u", 0, 0, _w, _h); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = (WNDPROC)CDisplayDX::wndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(1)); wndclass.hCursor = NULL;//LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = L"ElectricsheepWndClass"; static bool wndclassAlreadyRegistered = false; if( wndclassAlreadyRegistered == false && !RegisterClass (&wndclass) ) { return 0; } wndclassAlreadyRegistered = true; /*if( _bFullscreen ) { DEVMODE dmScreenSettings; memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); dmScreenSettings.dmSize = sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = _w; dmScreenSettings.dmPelsHeight = _h; dmScreenSettings.dmBitsPerPel = 32; dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; if( ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL ) OutputDebugString("Failed to change display settings"); }*/ unsigned long exStyle; unsigned long style; if( _bFullscreen ) { exStyle = WS_EX_APPWINDOW | WS_EX_TOPMOST; style = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; } else { exStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; } AdjustWindowRectEx( &windowRect, style, false, exStyle ); int ww = windowRect.right - windowRect.left; int hh = windowRect.bottom - windowRect.top; int xx = 0; int yy = 0; g_Log->Info( "CDisplayDX::createwindow AdjustWindowRectEx x=%u y=%u w=%u h=%u", 0, 0, ww, hh); MONITORINFO monitorInfo; for( DWORD iMonitor = 0; iMonitor < m_dwNumMonitors; iMonitor++ ) { if (iMonitor == m_DesiredScreenID && _bFullscreen) { MonitorInfo *pMonitorInfo = &m_Monitors[iMonitor]; monitorInfo.cbSize = sizeof(MONITORINFO); GetMonitorInfo( pMonitorInfo->hMonitor, &monitorInfo ); pMonitorInfo->rcScreen = monitorInfo.rcMonitor; //SetWindowPos( hWnd, HWND_TOPMOST, monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top, monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top, SWP_NOACTIVATE ); xx = monitorInfo.rcMonitor.left; yy = monitorInfo.rcMonitor.top; ww = monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left; hh = monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top; g_Log->Info( "CDisplayDX::createwindow SetWindowPos x=%u y=%u w=%u h=%u", monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top, monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top); } } HWND hWnd = CreateWindowEx( exStyle, L"ElectricsheepWndClass", L"Electricsheep", style, xx, yy, ww, hh, NULL, NULL, hInstance, NULL ); BlankUnusedMonitors(wndclass, hWnd, hInstance); return hWnd; }
static bool gfx_ctx_wgl_set_video_mode(void *data, unsigned width, unsigned height, bool fullscreen) { DWORD style; MSG msg; RECT mon_rect; MONITORINFOEX current_mon; bool windowed_full; RECT rect = {0}; HMONITOR hm_to_use = NULL; driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); monitor_info(¤t_mon, &hm_to_use); mon_rect = current_mon.rcMonitor; g_resize_width = width; g_resize_height = height; windowed_full = settings->video.windowed_fullscreen; if (fullscreen) { if (windowed_full) { style = WS_EX_TOPMOST | WS_POPUP; g_resize_width = width = mon_rect.right - mon_rect.left; g_resize_height = height = mon_rect.bottom - mon_rect.top; } else { style = WS_POPUP | WS_VISIBLE; if (!set_fullscreen(width, height, current_mon.szDevice)) goto error; /* Display settings might have changed, get new coordinates. */ GetMonitorInfo(hm_to_use, (MONITORINFO*)¤t_mon); mon_rect = current_mon.rcMonitor; g_restore_desktop = true; } } else { style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; rect.right = width; rect.bottom = height; AdjustWindowRect(&rect, style, FALSE); g_resize_width = width = rect.right - rect.left; g_resize_height = height = rect.bottom - rect.top; } g_hwnd = CreateWindowEx(0, "RetroArch", "RetroArch", style, fullscreen ? mon_rect.left : g_pos_x, fullscreen ? mon_rect.top : g_pos_y, width, height, NULL, NULL, NULL, NULL); if (!g_hwnd) goto error; if (!fullscreen || windowed_full) { if (!fullscreen && settings->ui.menubar_enable) { RECT rc_temp = {0, 0, height, 0x7FFF}; SetMenu(g_hwnd, LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_MENU))); SendMessage(g_hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rc_temp); g_resize_height = height += rc_temp.top + rect.top; SetWindowPos(g_hwnd, NULL, 0, 0, width, height, SWP_NOMOVE); } ShowWindow(g_hwnd, SW_RESTORE); UpdateWindow(g_hwnd); SetForegroundWindow(g_hwnd); SetFocus(g_hwnd); } win32_show_cursor(!fullscreen); /* Wait until GL context is created (or failed to do so ...) */ while (!g_inited && !g_quit && GetMessage(&msg, g_hwnd, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } if (g_quit) goto error; p_swap_interval = (BOOL (APIENTRY *)(int))wglGetProcAddress("wglSwapIntervalEXT"); gfx_ctx_wgl_swap_interval(data, g_interval); driver->display_type = RARCH_DISPLAY_WIN32; driver->video_display = 0; driver->video_window = (uintptr_t)g_hwnd; return true; error: gfx_ctx_wgl_destroy(data); return false; }
static int CommonControlSetFullscreen(vout_display_t *vd, bool is_fullscreen) { vout_display_sys_t *sys = vd->sys; #ifdef MODULE_NAME_IS_direct3d9 if (sys->use_desktop && is_fullscreen) return VLC_EGENERIC; #endif /* */ if (sys->parent_window) return VLC_EGENERIC; /* */ HWND hwnd = sys->hparent && sys->hfswnd ? sys->hfswnd : sys->hwnd; /* Save the current windows placement/placement to restore when fullscreen is over */ WINDOWPLACEMENT window_placement; window_placement.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(hwnd, &window_placement); if (is_fullscreen) { msg_Dbg(vd, "entering fullscreen mode"); /* Change window style, no borders and no title bar */ SetWindowLong(hwnd, GWL_STYLE, WS_CLIPCHILDREN | WS_VISIBLE); if (sys->hparent) { /* Retrieve current window position so fullscreen will happen *on the right screen */ HMONITOR hmon = MonitorFromWindow(sys->hparent, MONITOR_DEFAULTTONEAREST); MONITORINFO mi; mi.cbSize = sizeof(MONITORINFO); if (GetMonitorInfo(hmon, &mi)) SetWindowPos(hwnd, 0, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOZORDER|SWP_FRAMECHANGED); } else { /* Maximize non embedded window */ ShowWindow(hwnd, SW_SHOWMAXIMIZED); } if (sys->hparent) { /* Hide the previous window */ RECT rect; GetClientRect(hwnd, &rect); SetParent(sys->hwnd, hwnd); SetWindowPos(sys->hwnd, 0, 0, 0, rect.right, rect.bottom, SWP_NOZORDER|SWP_FRAMECHANGED); HWND topLevelParent = GetAncestor(sys->hparent, GA_ROOT); ShowWindow(topLevelParent, SW_HIDE); } SetForegroundWindow(hwnd); } else { msg_Dbg(vd, "leaving fullscreen mode"); /* Change window style, no borders and no title bar */ SetWindowLong(hwnd, GWL_STYLE, EventThreadGetWindowStyle(sys->event)); if (sys->hparent) { RECT rect; GetClientRect(sys->hparent, &rect); SetParent(sys->hwnd, sys->hparent); SetWindowPos(sys->hwnd, 0, 0, 0, rect.right, rect.bottom, SWP_NOZORDER|SWP_FRAMECHANGED); HWND topLevelParent = GetAncestor(sys->hparent, GA_ROOT); ShowWindow(topLevelParent, SW_SHOW); SetForegroundWindow(sys->hparent); ShowWindow(hwnd, SW_HIDE); } else { /* return to normal window for non embedded vout */ SetWindowPlacement(hwnd, &window_placement); ShowWindow(hwnd, SW_SHOWNORMAL); } } return VLC_SUCCESS; }
struct Box_s *RemoveFriend_Create(struct Box_s *roster, char *name, char *group) { struct Box_s *dialog; struct Box_s *pbox; struct removefrienddata_s *data = malloc(sizeof(*data)); char gonnaremove[256]; int x, y; { RECT windowrect; HMONITOR hm; MONITORINFO mi; windowrect.left = roster->x; windowrect.right = windowrect.left + roster->w - 1; windowrect.top = roster->y; windowrect.bottom = windowrect.top + roster->h - 1; hm = MonitorFromRect(&windowrect, MONITOR_DEFAULTTONEAREST); mi.cbSize = sizeof(mi); GetMonitorInfo(hm, &mi); x = mi.rcWork.left + (mi.rcWork.right - mi.rcWork.left - 432) / 2; y = mi.rcWork.top + (mi.rcWork.bottom - mi.rcWork.top - 128) / 2; } dialog = Box_Create(x, y, 520, 128, BOX_VISIBLE); dialog->bgcol = DefaultBG; dialog->focus = dialog; dialog->OnKeyDown = RemoveFriend_OnKeyDown; i18n_stringsub(gonnaremove, 256, _("Remove %1 from Friends List?"), Model_GetFriendNick(name)); dialog->titlebar = TitleBarOnly_Add(dialog, gonnaremove); dialog->OnActive = TitleBarRoot_OnActive; dialog->OnInactive = TitleBarRoot_OnInactive; gonnaremove[0] = 0; i18n_stringsub(gonnaremove, 256, _("Are you sure that you want to remove %1 from your friends list?"), Model_GetFriendNick(name)); pbox = Box_Create(32, 48, 400, 16, BOX_TRANSPARENT | BOX_VISIBLE); pbox->fgcol = PresenceFG; Box_SetText(pbox, gonnaremove); Box_AddChild(dialog, pbox); if (group) { pbox = StdButton_Create(dialog->w - 500, 128 - 32, 170, _("Remove from all groups"), 0); Button2_SetOnButtonHit(pbox, RemoveFriend_OnRemoveAll); Box_AddChild(dialog, pbox); pbox = StdButton_Create(dialog->w - 310, 128 - 32, 170, _("Remove from this group"), 0); Button2_SetOnButtonHit(pbox, RemoveFriend_OnRemoveGroup); Box_AddChild(dialog, pbox); pbox = StdButton_Create(dialog->w - 120, 128 - 32, 100, _("Don't Remove"), 0); Button2_SetOnButtonHit(pbox, RemoveFriend_OnCancel); Box_AddChild(dialog, pbox); } else { pbox = StdButton_Create(dialog->w - 310, 128 - 32, 170, _("Remove from all groups"), 0); Button2_SetOnButtonHit(pbox, RemoveFriend_OnRemoveAll); Box_AddChild(dialog, pbox); pbox = StdButton_Create(dialog->w - 120, 128 - 32, 100, _("Don't Remove"), 0); Button2_SetOnButtonHit(pbox, RemoveFriend_OnCancel); Box_AddChild(dialog, pbox); } data->name = strdup(name); data->group = strdup(group); dialog->boxdata = data; Box_CreateWndCustom(dialog, _("Remove Friend"), roster->hwnd); BringWindowToTop(dialog->hwnd); return dialog; }
void Init() { CIniReader iniReader(""); res_x = iniReader.ReadInteger("MAIN", "X", 0); res_y = iniReader.ReadInteger("MAIN", "Y", 0); if (!res_x || !res_y) { HMONITOR monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); MONITORINFO info; info.cbSize = sizeof(MONITORINFO); GetMonitorInfo(monitor, &info); res_x = info.rcMonitor.right - info.rcMonitor.left; res_y = info.rcMonitor.bottom - info.rcMonitor.top; } if ((*(DWORD*)0x45E93B == 640)) { CPatch::SetUInt(0x45E939 + 0x2, res_x); CPatch::SetUInt(0x45E93F + 0x3, res_y); CPatch::SetUInt(0x45E9A1 + 0x2, res_x); CPatch::SetUInt(0x45E9A7 + 0x3, res_y); CPatch::SetUInt(0x45EA09 + 0x2, res_x); CPatch::SetUInt(0x45EA0F + 0x3, res_y); CPatch::SetUInt(0x45EA71 + 0x2, res_x); CPatch::SetUInt(0x45EA77 + 0x3, res_y); CPatch::SetUInt(0x45EAD9 + 0x2, res_x); CPatch::SetUInt(0x45EADF + 0x3, res_y); CPatch::SetUInt(0x45EB3D + 0x1, res_x); CPatch::SetUInt(0x45EB48 + 0x1, res_y); CPatch::SetFloat(0x9B38EC, static_cast<float>(res_x) / static_cast<float>(res_y)); } else { /*CPatch::SetUInt(0x946A37 + 0x4, res_x); CPatch::SetUInt(0x946A3F + 0x4, res_y); CPatch::SetUInt(0x9469FE + 0x4, res_x); CPatch::SetUInt(0x946A06 + 0x4, res_y); CPatch::SetUInt(0x9469C5 + 0x4, res_x); CPatch::SetUInt(0x9469CD + 0x4, res_y); CPatch::SetUInt(0x946995 + 0x4, res_x); CPatch::SetUInt(0x94699D + 0x4, res_y); CPatch::SetUInt(0x946964 + 0x4, res_x); CPatch::SetUInt(0x94696C + 0x4, res_y); //CPatch::SetUInt(0x45EB3D + 0x1, res_x); //CPatch::SetUInt(0x45EB48 + 0x1, res_y); CPatch::RedirectJump(0x41FD70, asm_patch); CPatch::SetFloat(0x9B38EC, static_cast<float>(res_x) / static_cast<float>(res_y));*/ } }
void CConEmuCtrl::MakeScreenshot(bool abFullscreen /*= false*/) { BOOL lbRc = FALSE; HDC hScreen = NULL; RECT rcWnd = {}; HWND hWnd = GetForegroundWindow(); if (!hWnd) { DisplayLastError(L"GetForegroundWindow() == NULL"); return; } HMONITOR hMon = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); MONITORINFO mi = {sizeof(mi)}; if (!GetMonitorInfo(hMon, &mi)) { DisplayLastError(L"GetMonitorInfo() failed"); return; } if (!abFullscreen) { GetWindowRect(hWnd, &rcWnd); bool bDlg = ((GetWindowLongPtr(hWnd, GWL_STYLE) & DS_MODALFRAME) == DS_MODALFRAME); if (gpConEmu->IsGlass()) { if (bDlg && (gnOsVer == 0x601)) { rcWnd.top -= 5; rcWnd.left -= 5; rcWnd.right += 3; rcWnd.bottom += 5; } else if (gnOsVer >= 0x602) { if (bDlg) { rcWnd.top -= 5; rcWnd.left -= 5; rcWnd.right += 3; rcWnd.bottom += 5; } else { rcWnd.left += 2; rcWnd.right -= 2; rcWnd.bottom -= 2; } } } // Отрезать края при Zoomed/Fullscreen RECT rcVisible = {}; if (!IntersectRect(&rcVisible, &rcWnd, gpConEmu->isFullScreen() ? &mi.rcMonitor : &mi.rcWork)) { DisplayLastError(L"Window out of monitor rectangle"); return; } rcWnd = rcVisible; } else { rcWnd = mi.rcMonitor; } hScreen = GetDC(NULL); lbRc = DumpImage(hScreen, NULL, rcWnd.left, rcWnd.top, rcWnd.right-rcWnd.left, rcWnd.bottom-rcWnd.top, NULL, FALSE/*NoTransparency, 24bit*/); if (!lbRc) { DisplayLastError(L"Creating screenshot failed!"); } ReleaseDC(NULL, hScreen); }
int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow ) { HWND hwnd = NULL; RegisterHotKey( hwnd, TOP_LEFT, MOD_CONTROL|MOD_WIN, VK_NUMPAD7 ); RegisterHotKey( hwnd, TOP, MOD_CONTROL|MOD_WIN, VK_NUMPAD8 ); RegisterHotKey( hwnd, TOP_RIGHT, MOD_CONTROL|MOD_WIN, VK_NUMPAD9 ); RegisterHotKey( hwnd, CENTER_LEFT, MOD_CONTROL|MOD_WIN, VK_NUMPAD4 ); RegisterHotKey( hwnd, CENTER, MOD_CONTROL|MOD_WIN, VK_NUMPAD5 ); RegisterHotKey( hwnd, CENTER_RIGHT, MOD_CONTROL|MOD_WIN, VK_NUMPAD6 ); RegisterHotKey( hwnd, BOTTOM_LEFT, MOD_CONTROL|MOD_WIN, VK_NUMPAD1 ); RegisterHotKey( hwnd, BOTTOM, MOD_CONTROL|MOD_WIN, VK_NUMPAD2 ); RegisterHotKey( hwnd, BOTTOM_RIGHT, MOD_CONTROL|MOD_WIN, VK_NUMPAD3 ); if( RegisterHotKey( hwnd, EXIT, MOD_CONTROL|MOD_WIN, VK_NUMPAD0 ) ) { MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) != 0 ) { if( msg.message = WM_HOTKEY ) { HWND hwndActive = GetForegroundWindow(); RECT rect; GetWindowRect( hwndActive, &rect ); HMONITOR hmonitor = MonitorFromWindow( hwndActive, MONITOR_DEFAULTTONULL ); MONITORINFO mi; mi.cbSize = sizeof( MONITORINFO ); GetMonitorInfo( hmonitor, &mi ); int x = rect.left; int y = rect.top; switch( ( WINDOW_POSITION )msg.wParam ) { case TOP_LEFT: x = mi.rcWork.left; y = mi.rcWork.top; break; case TOP: x = mi.rcWork.left + ( ( ( mi.rcWork.right - mi.rcWork.left ) - ( rect.right - rect.left ) ) / 2 ); y = mi.rcWork.top; break; case TOP_RIGHT: x = mi.rcWork.right - ( rect.right - rect.left ); y = mi.rcWork.top; break; case CENTER_LEFT: x = mi.rcWork.left; y = mi.rcWork.top + ( ( ( mi.rcWork.bottom - mi.rcWork.top ) - ( rect.bottom - rect.top ) ) / 2 ); break; case CENTER: x = mi.rcWork.left + ( ( ( mi.rcWork.right - mi.rcWork.left ) - ( rect.right - rect.left ) ) / 2 ); y = mi.rcWork.top + ( ( ( mi.rcWork.bottom - mi.rcWork.top ) - ( rect.bottom - rect.top ) ) / 2 ); break; case CENTER_RIGHT: x = mi.rcWork.right - ( rect.right - rect.left ); y = mi.rcWork.top + ( ( ( mi.rcWork.bottom - mi.rcWork.top ) - ( rect.bottom - rect.top ) ) / 2 ); break; case BOTTOM_LEFT: x = mi.rcWork.left; y = mi.rcWork.bottom - ( rect.bottom - rect.top ); break; case BOTTOM: x = mi.rcWork.left + ( ( ( mi.rcWork.right - mi.rcWork.left ) - ( rect.right - rect.left ) ) / 2 ); y = mi.rcWork.bottom - ( rect.bottom - rect.top ); break; case BOTTOM_RIGHT: x = mi.rcWork.right - ( rect.right - rect.left ); y = mi.rcWork.bottom - ( rect.bottom - rect.top ); break; } SetWindowPos( hwndActive, HWND_TOP, x, y, 0, 0, SWP_NOSIZE ); if( msg.message == WM_QUIT || msg.wParam == EXIT ) break; } } UnregisterHotKey( hwnd, TOP_LEFT ); UnregisterHotKey( hwnd, TOP ); UnregisterHotKey( hwnd, TOP_RIGHT ); UnregisterHotKey( hwnd, CENTER_LEFT ); UnregisterHotKey( hwnd, CENTER ); UnregisterHotKey( hwnd, CENTER_RIGHT ); UnregisterHotKey( hwnd, BOTTOM_LEFT ); UnregisterHotKey( hwnd, BOTTOM ); UnregisterHotKey( hwnd, BOTTOM_RIGHT ); UnregisterHotKey( hwnd, EXIT ); } }
void HMDDeviceFactory::EnumerateDevices(EnumerateVisitor& visitor) { MonitorSet monitors; monitors.MonitorCount = 0; // Get all the monitor handles EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM)&monitors); // DeviceManager* manager = getManager(); DISPLAY_DEVICE dd, ddm; UINT i, j; for (i = 0; (ZeroMemory(&dd, sizeof(dd)), dd.cb = sizeof(dd), EnumDisplayDevices(0, i, &dd, 0)) != 0; i++) { /* wchar_t buff[500], flagsBuff[200]; swprintf_s(buff, 500, L"\nDEV: \"%s\" \"%s\" 0x%08x=%s\n \"%s\" \"%s\"\n", dd.DeviceName, dd.DeviceString, dd.StateFlags, FormatDisplayStateFlags(flagsBuff, 200, dd.StateFlags), dd.DeviceID, dd.DeviceKey); ::OutputDebugString(buff); */ for (j = 0; (ZeroMemory(&ddm, sizeof(ddm)), ddm.cb = sizeof(ddm), EnumDisplayDevices(dd.DeviceName, j, &ddm, 0)) != 0; j++) { /* wchar_t mbuff[500]; swprintf_s(mbuff, 500, L"MON: \"%s\" \"%s\" 0x%08x=%s\n \"%s\" \"%s\"\n", ddm.DeviceName, ddm.DeviceString, ddm.StateFlags, FormatDisplayStateFlags(flagsBuff, 200, ddm.StateFlags), ddm.DeviceID, ddm.DeviceKey); ::OutputDebugString(mbuff); */ // Our monitor hardware has string "RTD2205" in it // Nate's device "CVT0003" if (wcsstr(ddm.DeviceID, L"RTD2205") || wcsstr(ddm.DeviceID, L"CVT0003") || wcsstr(ddm.DeviceID, L"MST0030") || wcsstr(ddm.DeviceID, L"OVR00") ) // Part of Oculus EDID. { String deviceId(ddm.DeviceID); String displayDeviceName(ddm.DeviceName); // The default monitor coordinates int mx = 0; int my = 0; int mwidth = 1280; int mheight = 800; // Find the matching MONITORINFOEX for this device so we can get the // screen coordinates MONITORINFOEX info; for (int m=0; m < monitors.MonitorCount; m++) { info.cbSize = sizeof(MONITORINFOEX); GetMonitorInfo(monitors.Monitors[m], &info); if (_tcsstr(ddm.DeviceName, info.szDevice) == ddm.DeviceName) { // If the device name starts with the monitor name // then we found the matching DISPLAY_DEVICE and MONITORINFO // so we can gather the monitor coordinates mx = info.rcMonitor.left; my = info.rcMonitor.top; //mwidth = info.rcMonitor.right - info.rcMonitor.left; //mheight = info.rcMonitor.bottom - info.rcMonitor.top; break; } } HMDDeviceCreateDesc hmdCreateDesc(this, deviceId, displayDeviceName); if (hmdCreateDesc.Is7Inch()) { // Physical dimension of SLA screen. hmdCreateDesc.SetScreenParameters(mx, my, mwidth, mheight, 0.14976f, 0.0936f); } else { hmdCreateDesc.SetScreenParameters(mx, my, mwidth, mheight, 0.12096f, 0.0756f); } OVR_DEBUG_LOG_TEXT(("DeviceManager - HMD Found %s - %s\n", deviceId.ToCStr(), displayDeviceName.ToCStr())); // Notify caller about detected device. This will call EnumerateAddDevice // if the this is the first time device was detected. visitor.Visit(hmdCreateDesc); break; } } } }
void Win32ToggleFullscreen( vout_thread_t *p_vout ) { HWND hwnd = (p_vout->p_sys->hparent && p_vout->p_sys->hfswnd) ? p_vout->p_sys->hfswnd : p_vout->p_sys->hwnd; /* Save the current windows placement/placement to restore when fullscreen is over */ WINDOWPLACEMENT window_placement = getWindowState( hwnd ); p_vout->b_fullscreen = ! p_vout->b_fullscreen; /* We want to go to Fullscreen */ if( p_vout->b_fullscreen ) { msg_Dbg( p_vout, "entering fullscreen mode" ); /* Change window style, no borders and no title bar */ int i_style = WS_CLIPCHILDREN | WS_VISIBLE; SetWindowLong( hwnd, GWL_STYLE, i_style ); if( p_vout->p_sys->hparent ) { #ifdef UNDER_CE POINT point = {0,0}; RECT rect; ClientToScreen( p_vout->p_sys->hwnd, &point ); GetClientRect( p_vout->p_sys->hwnd, &rect ); SetWindowPos( hwnd, 0, point.x, point.y, rect.right, rect.bottom, SWP_NOZORDER|SWP_FRAMECHANGED ); #else /* Retrieve current window position so fullscreen will happen *on the right screen */ HMONITOR hmon = MonitorFromWindow(p_vout->p_sys->hparent, MONITOR_DEFAULTTONEAREST); MONITORINFO mi; if (GetMonitorInfo(hmon, &mi)) SetWindowPos( hwnd, 0, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOZORDER|SWP_FRAMECHANGED ); #endif } else { /* Maximize non embedded window */ ShowWindow( hwnd, SW_SHOWMAXIMIZED ); } if( p_vout->p_sys->hparent ) { /* Hide the previous window */ RECT rect; GetClientRect( hwnd, &rect ); SetParent( p_vout->p_sys->hwnd, hwnd ); SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0, rect.right, rect.bottom, SWP_NOZORDER|SWP_FRAMECHANGED ); #ifdef UNDER_CE HWND topLevelParent = GetParent( p_vout->p_sys->hparent ); #else HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT ); #endif ShowWindow( topLevelParent, SW_HIDE ); } SetForegroundWindow( hwnd ); } else { msg_Dbg( p_vout, "leaving fullscreen mode" ); /* Change window style, no borders and no title bar */ SetWindowLong( hwnd, GWL_STYLE, p_vout->p_sys->i_window_style ); if( p_vout->p_sys->hparent ) { RECT rect; GetClientRect( p_vout->p_sys->hparent, &rect ); SetParent( p_vout->p_sys->hwnd, p_vout->p_sys->hparent ); SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0, rect.right, rect.bottom, SWP_NOZORDER|SWP_FRAMECHANGED ); #ifdef UNDER_CE HWND topLevelParent = GetParent( p_vout->p_sys->hparent ); #else HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT ); #endif ShowWindow( topLevelParent, SW_SHOW ); SetForegroundWindow( p_vout->p_sys->hparent ); ShowWindow( hwnd, SW_HIDE ); } else { /* return to normal window for non embedded vout */ SetWindowPlacement( hwnd, &window_placement ); ShowWindow( hwnd, SW_SHOWNORMAL ); } /* Make sure the mouse cursor is displayed */ PostMessage( p_vout->p_sys->hwnd, WM_VLC_SHOW_MOUSE, 0, 0 ); } /* Update the object variable and trigger callback */ var_SetBool( p_vout, "fullscreen", p_vout->b_fullscreen ); }
// ---------------------------------------------------------------------- // Windows proc for the one and only window in this app. // // ---------------------------------------------------------------------- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HBRUSH hbrLit = NULL; static HBRUSH hbrUnlit = NULL; static HFONT hFont = NULL; static UINT_PTR nTimerId = 101; switch (message) { case WM_CREATE: { // Make BLACK the transparency color SetLayeredWindowAttributes(hWnd, RGB(0,0,0), 0, LWA_COLORKEY); // Initialize the DPI scalar. InitializeDPIScale(hWnd); // Create brushes and font that will be used in WM_PAINT hbrLit = CreateSolidBrush(RGB(0,128,255)); hbrUnlit = CreateSolidBrush(RGB(0,64,128)); hFont = CreateFont(DPIScale(64), 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, 0, 0, 0, 0, 0, L"Segoe UI"); // Position at the center of the primary monitor POINT const ptZeroZero = {}; HMONITOR hMonitor = MonitorFromPoint(ptZeroZero, MONITOR_DEFAULTTOPRIMARY); MONITORINFO mi = {sizeof(mi)}; GetMonitorInfo(hMonitor, &mi); SIZE const size = { g_currentVolume.cSteps * DPIScale(10), DPIScale(60) }; POINT const pt = { mi.rcMonitor.left + (mi.rcMonitor.left + mi.rcMonitor.right - size.cx) / 2, mi.rcMonitor.top + (mi.rcMonitor.top + mi.rcMonitor.bottom - size.cy) / 2 }; SetWindowPos(hWnd, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, SWP_SHOWWINDOW); break; } case WM_DESTROY: { DeleteObject(hbrLit); DeleteObject(hbrUnlit); DeleteObject(hFont); PostQuitMessage(0); return 0; } case WM_ERASEBKGND: { // Don't do any erasing here. It's done in WM_PAINT to avoid flicker. return 1; } case WM_VOLUMECHANGE: { // get the new volume level g_pVolumeMonitor->GetLevelInfo(&g_currentVolume); // make window visible for 2 seconds ShowWindow(hWnd, SW_SHOW); InvalidateRect(hWnd, NULL, TRUE); nTimerId = SetTimer(hWnd, 101, 2000, NULL); return 0; } case WM_ENDPOINTCHANGE: { g_pVolumeMonitor->ChangeEndpoint(); return 0; } case WM_TIMER: { // make the window go away ShowWindow(hWnd, SW_HIDE); KillTimer(hWnd, nTimerId); return 0; } case WM_PAINT: { PAINTSTRUCT ps; HPAINTBUFFER hBufferedPaint = NULL; RECT rc; GetClientRect(hWnd, &rc); HDC hdc = BeginPaint(hWnd, &ps); if (g_bDblBuffered) { // Get doublebuffered DC HDC hdcMem; hBufferedPaint = BeginBufferedPaint(hdc, &rc, BPBF_COMPOSITED, NULL, &hdcMem); if (hBufferedPaint) { hdc = hdcMem; } } // black background (transparency color) FillRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH)); // Draw LEDs for (UINT i = 0; i < (g_currentVolume.cSteps-1); i++) { RECT const rcLed = { DPIScale(i * 10), DPIScale(10), DPIScale(i * 10 + 8), rc.bottom-DPIScale(15) }; if ((i < g_currentVolume.nStep) && (!g_currentVolume.bMuted)) FillRect(hdc, &rcLed, hbrLit); else FillRect(hdc, &rcLed, hbrUnlit); } if (g_currentVolume.bMuted) { HGDIOBJ hof = SelectObject(hdc, hFont); SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, RGB(255, 64, 64)); RECT rcText = rc; rcText.bottom -= DPIScale(11); DrawText(hdc, L"MUTED", -1, &rcText, DT_CENTER | DT_SINGLELINE | DT_VCENTER); SelectObject(hdc, hof); } if (hBufferedPaint) { // end painting BufferedPaintMakeOpaque(hBufferedPaint, NULL); EndBufferedPaint(hBufferedPaint, TRUE); } EndPaint(hWnd, &ps); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); }
BOOL ViWmManager::monitorEnumerator( HMONITOR hMonitor , HDC /* hdcMonitor */ , LPRECT /* intersectionRect */ , LPARAM userData ) { static int monitorCount = 0; ViWmManager &instance = *reinterpret_cast<ViWmManager*>( userData ); DesktopLayout &myLayout = instance.currentLayout; MONITORINFOEX minfo; minfo.cbSize = sizeof( MONITORINFOEX ); GetMonitorInfo( hMonitor, &minfo ); // as MSDN state that some value may be negative for non-primary // displays, we abs the width & height to get correct value to // work on. int winWidth = abs(minfo.rcWork.right - minfo.rcWork.left); int winHeight = abs(minfo.rcWork.bottom - minfo.rcWork.top); // yeah our nice window... HWND fullScreenWin = CreateWindowEx ( WS_EX_LAYERED | WS_EX_NOACTIVATE | (monitorCount == 0 ? WS_EX_APPWINDOW : 0) , fullScreenWindowClassName , TEXT("ABack") , WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS /* style */ , minfo.rcWork.left , minfo.rcWork.top , winWidth , winHeight , NULL , NULL /* menu */ , GetModuleHandle(0) , NULL ); if (!fullScreenWin) { int err = GetLastError(); MessageBox( NULL , TEXT("Error Creating Background Window") , TEXT("Error") , MB_OK | MB_ICONERROR); exit( err ); /* Bail */ } // if NULL, we need to create the menu action // a bit hugly :s if ( monitorCount++ == 0 ) { instance.hotkeysDefinition.push_back( HotKey( 'Z', new Actions::ActionMenu( instance.globalHotkeyListener , instance.hotkeysDefinition ))); } // ok we need our window to be always on bottom, let's hack to get that // we also specify our really wanted size =) SetWindowPos( fullScreenWin , HWND_BOTTOM , minfo.rcWork.left , minfo.rcWork.top , winWidth , winHeight , /*SWP_NOACTIVATE | */SWP_NOMOVE | SWP_NOSIZE ); Renderer::RenderWindow *newWindow = new Renderer::RenderWindow( fullScreenWin , minfo.rcWork.left , minfo.rcWork.top , winWidth , winHeight ); Screen newScreen ( *newWindow , minfo.rcWork.left , minfo.rcWork.top , winWidth , winHeight ); myLayout.push_back( newScreen ); // we make the window transparent here newWindow->begin( true ); newWindow->end(); assert( myLayout.size() >= 1 ); return TRUE; }
static Bool winGetWorkArea(RECT * prcWorkArea, winScreenInfo * pScreenInfo) { int iPrimaryWidth, iPrimaryHeight; int iWidth, iHeight; int iLeft, iTop; int iPrimaryNonWorkAreaWidth, iPrimaryNonWorkAreaHeight; /* Use GetMonitorInfo to get work area for monitor */ if (!pScreenInfo->fMultipleMonitors) { MONITORINFO mi; mi.cbSize = sizeof(MONITORINFO); if (GetMonitorInfo(pScreenInfo->hMonitor, &mi)) { *prcWorkArea = mi.rcWork; winDebug("winGetWorkArea - Monitor %d WorkArea: %d %d %d %d\n", pScreenInfo->iMonitor, (int) prcWorkArea->top, (int) prcWorkArea->left, (int) prcWorkArea->bottom, (int) prcWorkArea->right); } else { ErrorF("winGetWorkArea - GetMonitorInfo() failed for monitor %d\n", pScreenInfo->iMonitor); } /* Bail out here if we aren't using multiple monitors */ return TRUE; } /* SPI_GETWORKAREA only gets the work area of the primary screen. */ SystemParametersInfo(SPI_GETWORKAREA, 0, prcWorkArea, 0); winDebug("winGetWorkArea - Primary Monitor WorkArea: %d %d %d %d\n", (int) prcWorkArea->top, (int) prcWorkArea->left, (int) prcWorkArea->bottom, (int) prcWorkArea->right); /* Get size of full virtual screen */ iWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN); iHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN); winDebug("winGetWorkArea - Virtual screen is %d x %d\n", iWidth, iHeight); /* Get origin of full virtual screen */ iLeft = GetSystemMetrics(SM_XVIRTUALSCREEN); iTop = GetSystemMetrics(SM_YVIRTUALSCREEN); winDebug("winGetWorkArea - Virtual screen origin is %d, %d\n", iLeft, iTop); /* Get size of primary screen */ iPrimaryWidth = GetSystemMetrics(SM_CXSCREEN); iPrimaryHeight = GetSystemMetrics(SM_CYSCREEN); winDebug("winGetWorkArea - Primary screen is %d x %d\n", iPrimaryWidth, iPrimaryHeight); /* Work out how much of the primary screen we aren't using */ iPrimaryNonWorkAreaWidth = iPrimaryWidth - (prcWorkArea->right - prcWorkArea->left); iPrimaryNonWorkAreaHeight = iPrimaryHeight - (prcWorkArea->bottom - prcWorkArea->top); /* Update the rectangle to include all monitors */ if (iLeft < 0) { prcWorkArea->left = iLeft; } if (iTop < 0) { prcWorkArea->top = iTop; } prcWorkArea->right = prcWorkArea->left + iWidth - iPrimaryNonWorkAreaWidth; prcWorkArea->bottom = prcWorkArea->top + iHeight - iPrimaryNonWorkAreaHeight; winDebug("winGetWorkArea - Adjusted WorkArea for multiple " "monitors: %d %d %d %d\n", (int) prcWorkArea->top, (int) prcWorkArea->left, (int) prcWorkArea->bottom, (int) prcWorkArea->right); return TRUE; }
void sdlvideo_monitor_refresh(sdl_monitor_info *monitor) { #if (SDLMAME_SDL2) SDL_DisplayMode dmode; SDL_GetDesktopDisplayMode(monitor->handle, &dmode); monitor->monitor_width = dmode.w; monitor->monitor_height = dmode.h; monitor->center_width = dmode.w; monitor->center_height = dmode.h; #else #if defined(SDLMAME_WIN32) // Win32 version MONITORINFOEX info; info.cbSize = sizeof(info); GetMonitorInfo((HMONITOR)monitor->handle, (LPMONITORINFO)&info); monitor->center_width = monitor->monitor_width = info.rcMonitor.right - info.rcMonitor.left; monitor->center_height = monitor->monitor_height = info.rcMonitor.bottom - info.rcMonitor.top; char *temp = utf8_from_wstring(info.szDevice); strcpy(monitor->monitor_device, temp); osd_free(temp); #elif defined(SDLMAME_MACOSX) // Mac OS X Core Imaging version CGDirectDisplayID primary; CGRect dbounds; // get the main display primary = CGMainDisplayID(); dbounds = CGDisplayBounds(primary); monitor->center_width = monitor->monitor_width = dbounds.size.width - dbounds.origin.x; monitor->center_height = monitor->monitor_height = dbounds.size.height - dbounds.origin.y; strcpy(monitor->monitor_device, "Mac OS X display"); #elif defined(SDLMAME_X11) || defined(SDLMAME_NO_X11) // X11 version { #if defined(SDLMAME_X11) // X11 version int screen; SDL_SysWMinfo info; SDL_VERSION(&info.version); if ( SDL_GetWMInfo(&info) && (info.subsystem == SDL_SYSWM_X11) ) { screen = DefaultScreen(info.info.x11.display); SDL_VideoDriverName(monitor->monitor_device, sizeof(monitor->monitor_device)-1); monitor->monitor_width = DisplayWidth(info.info.x11.display, screen); monitor->monitor_height = DisplayHeight(info.info.x11.display, screen); if ((XineramaIsActive(info.info.x11.display)) && video_config.restrictonemonitor) { XineramaScreenInfo *xineinfo; int numscreens; xineinfo = XineramaQueryScreens(info.info.x11.display, &numscreens); monitor->center_width = xineinfo[0].width; monitor->center_height = xineinfo[0].height; XFree(xineinfo); } else { monitor->center_width = monitor->monitor_width; monitor->center_height = monitor->monitor_height; } } else #endif // defined(SDLMAME_X11) { static int first_call=0; static int cw, ch; SDL_VideoDriverName(monitor->monitor_device, sizeof(monitor->monitor_device)-1); if (first_call==0) { char *dimstr = osd_getenv(SDLENV_DESKTOPDIM); const SDL_VideoInfo *sdl_vi; sdl_vi = SDL_GetVideoInfo(); #if (SDL_VERSION_ATLEAST(1,2,10)) cw = sdl_vi->current_w; ch = sdl_vi->current_h; #endif first_call=1; if ((cw==0) || (ch==0)) { if (dimstr != NULL) { sscanf(dimstr, "%dx%d", &cw, &ch); } if ((cw==0) || (ch==0)) { mame_printf_warning("WARNING: SDL_GetVideoInfo() for driver <%s> is broken.\n", monitor->monitor_device); mame_printf_warning(" You should set SDLMAME_DESKTOPDIM to your desktop size.\n"); mame_printf_warning(" e.g. export SDLMAME_DESKTOPDIM=800x600\n"); mame_printf_warning(" Assuming 1024x768 now!\n"); cw=1024; ch=768; } } } monitor->monitor_width = cw; monitor->monitor_height = ch; monitor->center_width = cw; monitor->center_height = ch; } } #elif defined(SDLMAME_OS2) // OS2 version monitor->center_width = monitor->monitor_width = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ); monitor->center_height = monitor->monitor_height = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ); strcpy(monitor->monitor_device, "OS/2 display"); #else #error Unknown SDLMAME_xx OS type! #endif { static int info_shown=0; if (!info_shown) { mame_printf_verbose("SDL Device Driver : %s\n", monitor->monitor_device); mame_printf_verbose("SDL Monitor Dimensions: %d x %d\n", monitor->monitor_width, monitor->monitor_height); info_shown = 1; } } #endif // (SDLMAME_SDL2) }
void khm_adjust_window_dimensions_for_display(RECT * pr, int dock) { HMONITOR hmon; RECT rm; long x, y, width, height; x = pr->left; y = pr->top; width = pr->right - pr->left; height = pr->bottom - pr->top; /* if the rect doesn't intersect with the display area of any monitor, we just default to the primary monitor. */ hmon = MonitorFromRect(pr, MONITOR_DEFAULTTOPRIMARY); if (hmon == NULL) { /* huh? we'll just center this on the primary screen */ goto nomonitor; } else { MONITORINFO mi; ZeroMemory(&mi, sizeof(mi)); mi.cbSize = sizeof(mi); if (!GetMonitorInfo(hmon, &mi)) goto nomonitor; CopyRect(&rm, &mi.rcWork); goto adjust_dims; } nomonitor: /* for some reason we couldn't get a handle on a monitor or we couldn't get the metrics for that monitor. We default to setting things up on the primary monitor. */ SetRectEmpty(&rm); if (!SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID) &rm, 0)) goto done_with_monitor; adjust_dims: if (width > (rm.right - rm.left)) width = rm.right - rm.left; if (height > (rm.bottom - rm.top)) height = rm.bottom - rm.top; switch (dock & KHM_DOCKF_DOCKHINT) { case KHM_DOCK_TOPLEFT: x = rm.left; y = rm.top; break; case KHM_DOCK_TOPRIGHT: x = rm.right - width; y = rm.top; break; case KHM_DOCK_BOTTOMRIGHT: x = rm.right - width; y = rm.bottom - height; break; case KHM_DOCK_BOTTOMLEFT: x = rm.left; y = rm.bottom - height; break; case KHM_DOCK_AUTO: { int cxt, cyt; cxt = GetSystemMetrics(SM_CXDRAG); cyt = GetSystemMetrics(SM_CYDRAG); if (x > rm.left && (x - rm.left) < cxt) x = rm.left; else if ((x + width) < rm.right && (rm.right - (x + width)) < cxt) x = rm.right - width; if (y > rm.top && (y - rm.top) < cyt) y = rm.top; else if ((y + height) < rm.bottom && (rm.bottom - (y + height)) < cyt) y = rm.bottom - height; } break; } if (!(dock & KHM_DOCKF_XBORDER)) { if (x < rm.left) x = rm.left; if (x + width > rm.right) x = rm.right - width; if (y < rm.top) y = rm.top; if (y + height > rm.bottom) y = rm.bottom - height; } done_with_monitor: pr->left = x; pr->top = y; pr->right = x + width; pr->bottom = y + height; }
BOOL DXContext::Internal_Init(DXCONTEXT_PARAMS *pParams, BOOL bFirstInit) { memcpy(&m_current_mode, pParams, sizeof(DXCONTEXT_PARAMS)); memset(&myWindowState,0,sizeof(myWindowState)); // various checks if (m_current_mode.screenmode != WINDOWED) m_current_mode.m_skin = 0; // 1. destroy old window if (m_hwnd) { m_ignore_wm_destroy = 1; DestroyWindow(m_hwnd); m_ignore_wm_destroy = 0; m_hwnd = NULL; } // 2. CHECK TO MAKE SURE DIRECTX/DDRAW IS INSTALLED if (bFirstInit) { // Test for DirectX 9 + start it // note: if you don't call LoadLibrary here, and you're on a system // where DX9 is missing, Direct3DCreate8() might crash; so call it. int d3d9_already_loaded = (GetModuleHandle("d3d9.dll") != NULL) ? 1 : 0; if (!d3d9_already_loaded) m_hmod_d3d9 = LoadLibrary("d3d9.dll"); if ((!d3d9_already_loaded && !m_hmod_d3d9) || !(m_lpD3D = Direct3DCreate9(D3D_SDK_VERSION)) ) { MissingDirectX(NULL); m_lastErr = DXC_ERR_CREATE3D; return FALSE; } if (!m_hmod_d3dx9) m_hmod_d3dx9 = FindD3DX9(m_hwnd_winamp); if ((!m_hmod_d3dx9)) { MissingDirectX(NULL); m_lastErr = DXC_ERR_CREATE3D; return FALSE; } } // 3. get the smallest single rectangle that encloses ALL the monitors on the desktop: SetRect(&m_all_monitors_rect, 0, 0, 0, 0); EnumDisplayMonitors(NULL, NULL, MyMonitorEnumProc, (LPARAM)&m_all_monitors_rect); // 4. some DirectX- / DDraw-specific stuff. Also determine hPluginMonitor. HMONITOR hPluginMonitor = NULL; { D3DADAPTER_IDENTIFIER9 temp; // find the ordinal # of the adapter whose GUID matches what the user picked from the config panel, // and whose DeviceName matches as well. // if no match found, use D3DADAPTER_DEFAULT. m_ordinal_adapter = D3DADAPTER_DEFAULT; int nAdapters = m_lpD3D->GetAdapterCount(); { for (int i=0; i<nAdapters; i++) { if ((m_lpD3D->GetAdapterIdentifier(i, /*D3DENUM_NO_WHQL_LEVEL*/ 0, &temp) == D3D_OK) && (memcmp(&temp.DeviceIdentifier, &m_current_mode.adapter_guid, sizeof(GUID))==0) && !strcmp(temp.DeviceName, m_current_mode.adapter_devicename) ) { m_ordinal_adapter = i; break; } } } if (m_lpD3D->GetAdapterIdentifier(m_ordinal_adapter, /*D3DENUM_NO_WHQL_LEVEL*/ 0, &temp) == D3D_OK) { StringCbCopy(m_szDriver, sizeof(m_szDriver), temp.Driver); StringCbCopy(m_szDesc, sizeof(m_szDesc), temp.Description); } int caps_ok = 0; int caps_tries = 0; int changed_fs_disp_mode; // try to get the device caps for the adapter selected from the config panel. // if GetDeviceCaps() fails, it's probably because the adapter has been // removed from the system (or disabled), so we try again with other adapter(s). do { changed_fs_disp_mode = 0; SetRect(&m_monitor_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); // get bounding rect of the monitor attached to the adapter (to assist w/window positioning) // note: in vert/horz span setups (psuedo-multimon), // this will be 2048x768 or 1024x1536 or something like that. hPluginMonitor = m_lpD3D->GetAdapterMonitor(m_ordinal_adapter); /*if (hPluginMonitor) { MONITORINFO mi; mi.cbSize = sizeof(mi); if (GetMonitorInfo(hPluginMonitor, &mi)) { memcpy(&m_monitor_rect, &mi.rcMonitor, sizeof(RECT)); memcpy(&m_monitor_work_rect, &mi.rcWork, sizeof(RECT)); } }*/ if (bFirstInit) { for (int i=0; i<min(nAdapters, MAX_DXC_ADAPTERS); i++) { // if this is the first call to Init, get the display mode's original color format, // before we go changing it: D3DDISPLAYMODE d3ddm; if (FAILED(m_lpD3D->GetAdapterDisplayMode(i, &d3ddm))) { d3ddm.Format = D3DFMT_UNKNOWN; } m_orig_windowed_mode_format[i] = d3ddm.Format; } } // figure out pixel (color) format for back buffer: (m_current_mode.display_mode.Format) if (m_current_mode.screenmode!=FULLSCREEN && m_ordinal_adapter < MAX_DXC_ADAPTERS) m_current_mode.display_mode.Format = m_orig_windowed_mode_format[m_ordinal_adapter]; // else // for fullscreen, use what they gave us if (m_current_mode.display_mode.Format == D3DFMT_UNKNOWN || !TestFormat(m_ordinal_adapter, m_current_mode.display_mode.Format)) { // if they try to run the plugin without ever running the config panel // first (& pressing OK), then the fullscreen pixelformat hasn't been // chosen... so we try all the possilibities until one works: if (TestFormat(m_ordinal_adapter,D3DFMT_A8R8G8B8)) m_current_mode.display_mode.Format = D3DFMT_A8R8G8B8; else if (TestFormat(m_ordinal_adapter,D3DFMT_X8R8G8B8)) m_current_mode.display_mode.Format = D3DFMT_X8R8G8B8; else if (TestFormat(m_ordinal_adapter,D3DFMT_R8G8B8)) m_current_mode.display_mode.Format = D3DFMT_R8G8B8 ; else if (TestFormat(m_ordinal_adapter,D3DFMT_R5G6B5)) m_current_mode.display_mode.Format = D3DFMT_R5G6B5 ; else if (TestFormat(m_ordinal_adapter,D3DFMT_X1R5G5B5)) m_current_mode.display_mode.Format = D3DFMT_X1R5G5B5; else if (TestFormat(m_ordinal_adapter,D3DFMT_A1R5G5B5)) m_current_mode.display_mode.Format = D3DFMT_A1R5G5B5; else if (TestFormat(m_ordinal_adapter,D3DFMT_A4R4G4B4)) m_current_mode.display_mode.Format = D3DFMT_A4R4G4B4; else if (TestFormat(m_ordinal_adapter,D3DFMT_X4R4G4B4)) m_current_mode.display_mode.Format = D3DFMT_X4R4G4B4; } if (m_current_mode.display_mode.Format==D3DFMT_UNKNOWN) { wchar_t title[64]; m_lastErr = DXC_ERR_FORMAT; MessageBoxW(m_hwnd, WASABI_API_LNGSTRINGW(IDS_DIRECTX_INIT_FAILED), WASABI_API_LNGSTRINGW_BUF(IDS_MILKDROP_ERROR, title, 64), MB_OK|MB_SETFOREGROUND|MB_TOPMOST); return FALSE; } if (m_current_mode.screenmode == FULLSCREEN) changed_fs_disp_mode = CheckAndCorrectFullscreenDispMode(m_ordinal_adapter, &m_current_mode.display_mode); // figure out pixel format of the z-buffer: (m_zFormat) m_zFormat = D3DFMT_UNKNOWN; /* if (TestDepth(m_ordinal_adapter,D3DFMT_D32 )) m_zFormat=D3DFMT_D32; else if (TestDepth(m_ordinal_adapter,D3DFMT_D24S8 )) m_zFormat=D3DFMT_D24S8; else if (TestDepth(m_ordinal_adapter,D3DFMT_D24X4S4 )) m_zFormat=D3DFMT_D24X4S4; else if (TestDepth(m_ordinal_adapter,D3DFMT_D24X8 )) m_zFormat=D3DFMT_D24X8; else if (TestDepth(m_ordinal_adapter,D3DFMT_D16 )) m_zFormat=D3DFMT_D16; else if (TestDepth(m_ordinal_adapter,D3DFMT_D15S1 )) m_zFormat=D3DFMT_D15S1; else if (TestDepth(m_ordinal_adapter,D3DFMT_D16_LOCKABLE)) m_zFormat=D3DFMT_D16_LOCKABLE; */ // get device caps: memset(&m_caps, 0, sizeof(m_caps)); if (FAILED(m_lpD3D->GetDeviceCaps(m_ordinal_adapter, D3DDEVTYPE_HAL, &m_caps))) { // that adapter was found in the system, but it might be disabled // (i.e. 'extend my Windows desktop onto this monitor') is unchecked) // so, try other adapters (try all sequentially). if (caps_tries < nAdapters) { // try again, this time using the default adapter: m_ordinal_adapter = caps_tries; caps_tries++; } else { wchar_t title[64]; m_lastErr = DXC_ERR_CAPSFAIL; MessageBoxW(m_hwnd, WASABI_API_LNGSTRINGW(IDS_DXC_ERR_CAPSFAIL), WASABI_API_LNGSTRINGW_BUF(IDS_MILKDROP_ERROR, title, 64), MB_OK|MB_SETFOREGROUND|MB_TOPMOST); return FALSE; } } else { caps_ok = 1; } } while (!caps_ok); if (changed_fs_disp_mode) { wchar_t title[64]; MessageBoxW(m_hwnd, WASABI_API_LNGSTRINGW(IDS_FS_DISPLAY_MODE_SELECTED_IS_INVALID), WASABI_API_LNGSTRINGW_BUF(IDS_MILKDROP_WARNING, title, 64), MB_OK|MB_SETFOREGROUND|MB_TOPMOST); } switch (m_current_mode.display_mode.Format) { case D3DFMT_R8G8B8 : m_bpp = 32; break; case D3DFMT_A8R8G8B8: m_bpp = 32; break; case D3DFMT_X8R8G8B8: m_bpp = 32; break; case D3DFMT_R5G6B5 : m_bpp = 16; break; case D3DFMT_X1R5G5B5: m_bpp = 16; break; case D3DFMT_A1R5G5B5: m_bpp = 16; break; case D3DFMT_A8R3G3B2: m_bpp = 16; break; case D3DFMT_A4R4G4B4: m_bpp = 16; break; case D3DFMT_X4R4G4B4: m_bpp = 16; break; case D3DFMT_R3G3B2 : m_bpp = 8; break; // misleading? implies a palette... } } // 5. set m_monitor_rect and m_monitor_work_rect. if (hPluginMonitor) { MONITORINFO mi; mi.cbSize = sizeof(mi); if (GetMonitorInfo(hPluginMonitor, &mi)) { m_monitor_rect = mi.rcMonitor; m_monitor_rect_orig = mi.rcMonitor; m_monitor_work_rect = mi.rcWork; m_monitor_work_rect_orig = mi.rcWork; } } // 6. embedded window stuff [where the plugin window is integrated w/winamp] if (m_current_mode.m_skin) { // set up the window's position on screen // note that we'd prefer to set the CLIENT size we want, but we can't, so we'll just do // this here, and later, adjust the client rect size to what's left... int size = GetWindowedModeAutoSize(0); // note: requires 'm_monitor_rect' has been set! myWindowState.r.left = GetPrivateProfileIntW(L"settings",L"avs_wx",64,m_szIniFile); myWindowState.r.top = GetPrivateProfileIntW(L"settings",L"avs_wy",64,m_szIniFile); myWindowState.r.right = myWindowState.r.left + GetPrivateProfileIntW(L"settings",L"avs_ww",size+24,m_szIniFile); myWindowState.r.bottom = myWindowState.r.top + GetPrivateProfileIntW(L"settings",L"avs_wh",size+40,m_szIniFile); // only works on winamp 2.90+! int success = 0; if (GetWinampVersion(mod1.hwndParent) >= 0x2900) { SET_EMBED_GUID((&myWindowState), avs_guid); myWindowState.flags |= EMBED_FLAGS_NOTRANSPARENCY; HWND (*e)(embedWindowState *v); *(void**)&e = (void *)SendMessage(mod1.hwndParent,WM_WA_IPC,(LPARAM)0,IPC_GET_EMBEDIF); if (e) { m_current_mode.parent_window = e(&myWindowState); if (m_current_mode.parent_window) { SetWindowText(m_current_mode.parent_window, m_szWindowCaption); success = 1; } } } if (!success) m_current_mode.m_skin = 0; } // remember the client rect that was originally desired... RECT windowed_mode_desired_client_rect; windowed_mode_desired_client_rect.top = GetPrivateProfileIntW(L"settings",L"nMainWndTop",-1,m_szIniFile); windowed_mode_desired_client_rect.left = GetPrivateProfileIntW(L"settings",L"nMainWndLeft",-1,m_szIniFile); windowed_mode_desired_client_rect.right = GetPrivateProfileIntW(L"settings",L"nMainWndRight",-1,m_szIniFile); windowed_mode_desired_client_rect.bottom = GetPrivateProfileIntW(L"settings",L"nMainWndBottom",-1,m_szIniFile); // ...and in case windowed mode init fails severely, // set it up to try next time for a simple 256x256 window. WriteSafeWindowPos(); // 7. create the window, if not already created if (!m_hwnd) { m_hwnd = CreateWindowEx( MY_EXT_WINDOW_STYLE, // extended style MAKEINTATOM(m_classAtom), // class m_szWindowCaption, // caption MY_WINDOW_STYLE, // style 0, // left 0, // top 256, // temporary width 256, // temporary height m_current_mode.parent_window, // parent window NULL, // menu m_hInstance, // instance (LPVOID)m_uWindowLong ); // parms if (!m_hwnd) { wchar_t title[64]; m_lastErr = DXC_ERR_CREATEWIN; MessageBoxW(m_hwnd, WASABI_API_LNGSTRINGW(IDS_CREATEWINDOW_FAILED), WASABI_API_LNGSTRINGW_BUF(IDS_MILKDROP_ERROR, title, 64), MB_OK|MB_SETFOREGROUND|MB_TOPMOST); return FALSE; } SendMessage(m_hwnd_winamp, WM_WA_IPC, (WPARAM)m_hwnd, IPC_SETVISWND); if (m_current_mode.m_skin) { if (GetWinampVersion(mod1.hwndParent) < 0x5051) ShowWindow(m_current_mode.parent_window,SW_SHOWNA); // showing the parent wnd will make it size the child, too else SendMessage(m_current_mode.parent_window, WM_USER+102, 0, 0); // benski> major hack alert. winamp's embedwnd will call ShowWindow in response. SendMessage moves us over to the main thread (we're currently sitting on the viz thread) } } // 8. minimize winamp before creating devices & such, so there aren't // any confusing window-focus issues MinimizeWinamp(hPluginMonitor); // 9. loop to try and create the window. // if in windowed mode and not enough vidmem, it will try again w/smaller window // (repeatedly, until window client size would be < 64) int iteration = 0; int device_ok = 0; do { // set the window position if (m_current_mode.screenmode==DESKTOP || m_current_mode.screenmode==FAKE_FULLSCREEN) { int x = m_monitor_rect.right - m_monitor_rect.left; int y = m_monitor_rect.bottom - m_monitor_rect.top; if (x >= y*2) { // (pseudo-multimon modes like 2048x768) int mid = (m_monitor_rect.left + m_monitor_rect.right)/2; if (m_current_mode.m_dualhead_horz==1) // show on left side m_monitor_rect.right = mid; else if (m_current_mode.m_dualhead_horz==2) // show on right side m_monitor_rect.left = mid; } else if (y > x*4/3) { // (pseudo-multimon modes like 1024x1536) int mid = (m_monitor_rect.top + m_monitor_rect.bottom)/2; if (m_current_mode.m_dualhead_vert==1) // show on top half m_monitor_rect.bottom = mid; else if (m_current_mode.m_dualhead_vert==2) // show on bottom half m_monitor_rect.top = mid; } // recompute width & height (into x,y): x = m_monitor_rect.right - m_monitor_rect.left; y = m_monitor_rect.bottom - m_monitor_rect.top; m_client_width = x; m_client_height = y; m_window_width = x; m_window_height = y; if (m_current_mode.screenmode == DESKTOP) { // note: we initially hide the window, and then // only display it once the desktop is all nice & ready. // see CPluginShell::DrawAndDisplay(). RECT r = m_monitor_rect; // if possible, shrink the desktop window so it doesn't cover the taskbar. HWND hTaskbar = FindWindow("Shell_TrayWnd", ""); if (hTaskbar) { RECT taskbar; GetWindowRect(hTaskbar, &taskbar); int tbw = taskbar.right - taskbar.left; int tbh = taskbar.bottom-taskbar.top; if (taskbar.bottom == m_monitor_rect.bottom && taskbar.left == m_monitor_rect.left && taskbar.right == m_monitor_rect.right) { r.bottom -= tbh; } else if (taskbar.top == m_monitor_rect.top && taskbar.left == m_monitor_rect.left && taskbar.right == m_monitor_rect.right) { r.top += tbh; } else if (taskbar.left == m_monitor_rect.left && taskbar.top == m_monitor_rect.top && taskbar.bottom == m_monitor_rect.bottom) { r.left += tbw; } else if (taskbar.right == m_monitor_rect.right && taskbar.top == m_monitor_rect.top && taskbar.bottom == m_monitor_rect.bottom) { r.right -= tbw; } m_client_width = r.right - r.left; m_client_height = r.bottom - r.top; m_REAL_client_width = m_client_width; m_REAL_client_height = m_client_height; m_window_width = m_client_width; m_window_height = m_client_height; //...ok, but text is squished - some w/h is not right... } SetWindowPos(m_hwnd,HWND_BOTTOM,r.left,r.top,r.right-r.left,r.bottom-r.top,SWP_HIDEWINDOW); } else // FAKE_FULLSCREEN { if (memcmp(&m_all_monitors_rect, &m_monitor_rect, sizeof(RECT))==0) { // there's only one display, and it's entirely covered // by the plugin -> PUT THE PLUGIN ABOVE THE TASKBAR // -> normally, if the user clicked another window, // it would pop the taskbar to the top; but we don't // have to worry about that here, since we're taking // up the whole screen. // -> don't worry about making the text, etc. avoid // the taskbar in this case (see DrawAndDisplay()) // -> DO worry about hiding the mouse cursor in this case // (see WM_SETCURSOR handler) m_fake_fs_covers_all = 1; //SetWindowPos(m_hwnd,HWND_TOPMOST,m_monitor_rect.left,m_monitor_rect.top,m_window_width,m_window_height,SWP_SHOWWINDOW); } else { // there is space to work outside of the plugin window. // -> here we pretty much have to let the taskbar stay on // top, because it really likes to be there; i.e., // if you click any other window, it automatically // pops up again. // -> therefore, TRY TO KEEP THE WINDOW ON BOTTOM // (below the taskbar). (see PushWindowToBack) // -> don't worry about hiding the mouse cursor in this case // (see WM_SETCURSOR handler) // -> DO worry about making the text, etc. avoid // the taskbar in this case (see DrawAndDisplay()) // (note that if taskbar is in the way, they can move it, // since there are other monitors available) m_fake_fs_covers_all = 0; //SetWindowPos(m_hwnd,HWND_TOP,m_monitor_rect.left,m_monitor_rect.top,m_window_width,m_window_height,SWP_SHOWWINDOW); } SetWindowPos(m_hwnd,HWND_TOPMOST,m_monitor_rect.left,m_monitor_rect.top,m_window_width,m_window_height,SWP_SHOWWINDOW); } } else if (m_current_mode.screenmode == FULLSCREEN) { int x = m_current_mode.display_mode.Width ; int y = m_current_mode.display_mode.Height; int cx = m_monitor_rect.right - m_monitor_rect.left; int cy = m_monitor_rect.bottom - m_monitor_rect.top; // test #1 if (x >= y*2 || y > x*4/3) // tackle problem of vert/horz spans { wchar_t title[64]; int ret = MessageBoxW(m_hwnd, WASABI_API_LNGSTRINGW(IDS_TRYING_TO_ENTER_FS_MODE_WITH_MULTIPLE_DISPLAYS), WASABI_API_LNGSTRINGW_BUF(IDS_TIP, title, 64), MB_OKCANCEL|MB_SETFOREGROUND|MB_TOPMOST); if (ret==IDCANCEL) { m_lastErr = DXC_ERR_USER_CANCELED; return FALSE; } } // test #2 if ((cx >= cy*2 && x < y*2) || (cy > cx*4/3 && y <= x*4/3)) { wchar_t title[64]; int ret = MessageBoxW(m_hwnd, WASABI_API_LNGSTRINGW(IDS_TRYING_TO_ENTER_FS_MODE_WITH_MULTIPLE_DISPLAYS_2), WASABI_API_LNGSTRINGW_BUF(IDS_TIP, title, 64), MB_OKCANCEL|MB_SETFOREGROUND|MB_TOPMOST); if (ret==IDCANCEL) { m_lastErr = DXC_ERR_USER_CANCELED; return FALSE; } } m_client_width = x; m_client_height = y; m_window_width = x; m_window_height = y; SetWindowPos(m_hwnd,HWND_TOPMOST,m_monitor_rect.left,m_monitor_rect.top,m_window_width,m_window_height,SWP_SHOWWINDOW); } else // WINDOWED { RECT margin; if (m_current_mode.m_skin) { RECT r1, r2; GetWindowRect(m_current_mode.parent_window, &r1); GetWindowRect(m_hwnd , &r2); margin.left = r2.left - r1.left; margin.right = r1.right - r2.right; margin.top = r2.top - r1.top; margin.bottom= r1.bottom - r2.bottom; } else { RECT r1; SetRect(&r1, 0, 0, 256, 256); AdjustWindowRect(&r1, MY_WINDOW_STYLE, 0); margin.left = 0 - r1.left; margin.right = r1.right - 256; margin.top = 0 - r1.top; margin.bottom= r1.bottom - 256; } int autosize = 1; RECT r = windowed_mode_desired_client_rect; if (iteration==0 && r.top != -1 && r.left != -1 && r.bottom != -1 && r.right != -1) { // use prev. window coordinates: m_REAL_client_width = r.right - r.left; m_REAL_client_height = r.bottom - r.top; GetSnappedClientSize(); if (m_current_mode.m_skin) // check this here in case they got a non-aligned size by resizing when "integrated with winamp" was unchecked, then checked it & ran the plugin... { // STRANGE ALIGNMENTS FOR THE WINDOW FRAME: (required by winamp 2): // the window frame's width must be divisible by 25, and height by 29. if (GetWinampVersion(mod1.hwndParent) < 0x4000) // ... winamp 5 doesn't have this prob. (test vs. 0x4000 because winamp5 betas have version tags like 0x4987) { m_REAL_client_width = ((m_client_width + margin.left + margin.right)/25)*25 - margin.left - margin.right; m_REAL_client_height = ((m_client_height + margin.top + margin.bottom)/29)*29 - margin.top - margin.bottom; GetSnappedClientSize(); } } // transform screen-space CLIENT rect into screen-space WINDOW rect r.top = windowed_mode_desired_client_rect.top - margin.top; r.left = windowed_mode_desired_client_rect.left - margin.left; r.right = r.left + margin.left + m_REAL_client_width + margin.right; r.bottom = r.top + margin.top + m_REAL_client_height + margin.bottom; // make sure the window is entirely visible on the selected monitor; // otherwise, autosize/place it. // (note that this test is only appled 1) at startup, and 2) after a resize/max/restore. // this test is not applied when merely moving the window.) if (r.top >= m_monitor_work_rect.top && r.left >= m_monitor_work_rect.left && r.right <= m_monitor_work_rect.right && r.bottom <= m_monitor_work_rect.bottom) { if (m_current_mode.m_skin) { m_window_width = m_REAL_client_width ; // m_window_width/height are for OUR borderless window, not the embedwnd parent frame. m_window_height = m_REAL_client_height; SetWindowPos(m_current_mode.parent_window,HWND_NOTOPMOST, r.left, r.top, r.right-r.left, r.bottom-r.top, /*SWP_SHOWWINDOW|*//*SWP_ASYNCWINDOWPOS*/0); SetWindowPos(m_hwnd ,HWND_NOTOPMOST, windowed_mode_desired_client_rect.left, windowed_mode_desired_client_rect.top, m_REAL_client_width, m_REAL_client_height, SWP_SHOWWINDOW); } else { m_window_width = r.right - r.left; m_window_height = r.bottom - r.top; SetWindowPos(m_hwnd,HWND_NOTOPMOST,r.left,r.top,m_window_width,m_window_height,SWP_SHOWWINDOW); } autosize = 0; } } if (autosize) { int size = GetWindowedModeAutoSize(iteration); // note: requires 'm_monitor_rect' has been set! m_REAL_client_width = size; m_REAL_client_height = size; GetSnappedClientSize(); if (m_current_mode.m_skin) { // STRANGE ALIGNMENTS FOR THE WINDOW FRAME: (required by winamp 2): // the window frame's width must be divisible by 25, and height by 29. if (GetWinampVersion(mod1.hwndParent) < 0x4000) // ... winamp 5 doesn't have this prob. (test vs. 0x4000 because winamp5 betas have version tags like 0x4987) { m_REAL_client_width = ((m_client_width + margin.left + margin.right)/25)*25 - margin.left - margin.right; m_REAL_client_height = ((m_client_height + margin.top + margin.bottom)/29)*29 - margin.top - margin.bottom; GetSnappedClientSize(); } m_window_width = m_client_width ; // m_window_width/height are for OUR [borderless] window, not the parent window (which is the embedwnd frame). m_window_height = m_client_height; SetWindowPos(m_current_mode.parent_window,HWND_NOTOPMOST, m_monitor_work_rect.left+32, m_monitor_work_rect.top+32, m_client_width + margin.left + margin.right, m_client_height + margin.top + margin.bottom, /*SWP_SHOWWINDOW|*//*SWP_ASYNCWINDOWPOS*/0); SetWindowPos(m_hwnd ,HWND_NOTOPMOST, m_monitor_work_rect.left+32 + margin.left, m_monitor_work_rect.top+32 + margin.top, m_client_width, m_client_height, SWP_SHOWWINDOW); } else { SetRect(&r, 0, 0, size, size); AdjustWindowRect(&r, MY_WINDOW_STYLE, 0); m_window_width = r.right - r.left; m_window_height = r.bottom - r.top; SetWindowPos(m_hwnd,HWND_NOTOPMOST, m_monitor_work_rect.left+32, m_monitor_work_rect.top+32, m_window_width, m_window_height, SWP_SHOWWINDOW); } } } m_frame_delay = 1; // set this to 2 if you use triple buffering! { m_current_mode.display_mode.Width = m_client_width; m_current_mode.display_mode.Height = m_client_height; // set up m_d3dpp (presentation parameters): ZeroMemory(&m_d3dpp,sizeof(m_d3dpp)); m_d3dpp.Windowed = (m_current_mode.screenmode==FULLSCREEN) ? 0 : 1; m_d3dpp.BackBufferFormat = m_current_mode.display_mode.Format; m_d3dpp.BackBufferWidth = m_client_width; m_d3dpp.BackBufferHeight = m_client_height; m_d3dpp.BackBufferCount = m_current_mode.nbackbuf; if (m_current_mode.screenmode==FULLSCREEN) m_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;//D3DSWAPEFFECT_FLIP; else // windowed or fake FS m_d3dpp.SwapEffect = (m_current_mode.allow_page_tearing) ? D3DSWAPEFFECT_DISCARD : D3DSWAPEFFECT_COPY;//D3DSWAPEFFECT_DISCARD;//D3DSWAPEFFECT_FLIP; // note: multisampling is only allowed if swapeffect is DISCARD! m_d3dpp.MultiSampleType = (m_d3dpp.SwapEffect==D3DSWAPEFFECT_DISCARD) ? m_current_mode.multisamp : D3DMULTISAMPLE_NONE; //m_d3dpp.hDeviceWindow = m_hwnd; if (m_current_mode.screenmode==FULLSCREEN) { m_d3dpp.FullScreen_RefreshRateInHz = m_current_mode.display_mode.RefreshRate;//D3DPRESENT_RATE_DEFAULT; m_d3dpp.PresentationInterval = m_current_mode.allow_page_tearing ? D3DPRESENT_INTERVAL_IMMEDIATE : D3DPRESENT_INTERVAL_ONE;//D3DPRESENT_INTERVAL_IMMEDIATE;//D3DPRESENT_INTERVAL_ONE; } if (m_zFormat != D3DFMT_UNKNOWN) { m_d3dpp.EnableAutoDepthStencil=TRUE; m_d3dpp.AutoDepthStencilFormat=m_zFormat; } // finally, create the device: HRESULT hRes; if (FAILED(hRes = m_lpD3D->CreateDevice( m_ordinal_adapter, D3DDEVTYPE_HAL, m_hwnd, (m_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) ? D3DCREATE_MIXED_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING, &m_d3dpp, &m_lpDevice))) { int code = LOWORD(hRes); wchar_t str[1024]; if (code==2156) //D3DERR_NOTAVAILABLE { m_lastErr = DXC_ERR_CREATEDEV_NOT_AVAIL; wchar_t str[2048]; WASABI_API_LNGSTRINGW_BUF(IDS_UNABLE_TO_CREATE_DIRECTX_DEVICE, str, 2048); if (m_current_mode.screenmode == FULLSCREEN) StringCbCatW(str, sizeof(str), WASABI_API_LNGSTRINGW(IDS_OLDER_DISPLAY_ADAPTER_CATENATION)); else StringCbCatW(str, sizeof(str), WASABI_API_LNGSTRINGW(IDS_OLDER_DISPLAY_ADAPTER_CATENATION_2)); MessageBoxW(m_hwnd,str, WASABI_API_LNGSTRINGW(IDS_MILKDROP_ERROR), MB_OK|MB_SETFOREGROUND|MB_TOPMOST); return FALSE; } else if (m_current_mode.screenmode==WINDOWED && m_client_width>64) { // DO NOTHING; try again w/smaller window } else if (m_current_mode.screenmode != WINDOWED || m_client_width <= 64) { // usually, code==2154 here, which is D3DERR_OUTOFVIDEOMEMORY m_lastErr = DXC_ERR_CREATEDEV_PROBABLY_OUTOFVIDEOMEMORY; StringCbPrintfW(str, sizeof(str), WASABI_API_LNGSTRINGW(IDS_DIRECTX_INIT_FAILED_X), LOWORD(hRes)); // NOTE: *A 'SUGGESTION' SCREEN SHOULD APPEAR NEXT, PROVIDED BY THE CALLER* MessageBoxW(m_hwnd, str, WASABI_API_LNGSTRINGW(IDS_MILKDROP_ERROR), MB_OK|MB_SETFOREGROUND|MB_TOPMOST); return FALSE; } } else { device_ok = 1; } } iteration++; } while (!device_ok); // set initial viewport SetViewport(); // for desktop mode, push window to back again: if (m_current_mode.screenmode==DESKTOP) SetWindowPos(m_hwnd,HWND_BOTTOM,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); if (m_current_mode.m_skin) { if (GetWinampVersion(mod1.hwndParent) < 0x5051) SetFocus(m_current_mode.parent_window); else PostMessage(m_current_mode.parent_window, WM_USER+103, 0, 0); //SetActiveWindow(m_current_mode.parent_window); //SetForegroundWindow(m_current_mode.parent_window); } /*if (m_current_mode.screenmode == WINDOWED) SaveWindow();*/ // return success m_ready = TRUE; // benski> a little hack to get the window size correct. it seems to work if (m_current_mode.screenmode==WINDOWED) PostMessage(m_hwnd, WM_USER+555, 0, 0); return TRUE; }
void RestoreWindowRect(int& left, int& top, int& width, int& height, int& showCmd) { // Start with Registry data GetRegistryInt(PREF_WINPOS_FOLDER, PREF_LEFT, NULL, left); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_TOP, NULL, top); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_WIDTH, NULL, width); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_HEIGHT, NULL, height); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_SHOWSTATE, NULL, showCmd); // If window size has changed, we may need to alter window size HMONITOR hMonitor; MONITORINFO mi; RECT rcOrig, rcMax; // Get the nearest monitor to the passed rect rcOrig.left = left; rcOrig.top = top; rcOrig.right = left + width; rcOrig.bottom = top + height; hMonitor = MonitorFromRect(&rcOrig, MONITOR_DEFAULTTONEAREST); // Get the monitor rect mi.cbSize = sizeof(mi); GetMonitorInfo(hMonitor, &mi); rcMax = mi.rcMonitor; if (showCmd == SW_MAXIMIZE) { // For maximized case, just use monitor dimensions left = rcMax.left; top = rcMax.top; width = rcMax.right - rcMax.left; height = rcMax.bottom - rcMax.top; } else { // For non-maximized case, adjust window to fit on screen // make sure width fits int rcMaxWidth = static_cast<int>(rcMax.right - rcMax.left); if (width > rcMaxWidth) width = rcMaxWidth; // make sure left is on screen if (left < rcMax.left) left = static_cast<int>(rcMax.left); // make sure right is on screen if ((left + width) > rcMax.right) left = static_cast<int>(rcMax.right) - width; // make sure height fits int rcMaxHeight = static_cast<int>(rcMax.bottom - rcMax.top); if (height > rcMaxHeight) height = rcMaxHeight; // make sure top is on screen if (top < rcMax.top) top = static_cast<int>(rcMax.top); // make sure bottom is on screen if ((top + height) > rcMax.bottom) top = static_cast<int>(rcMax.bottom) - height; } }
GHOST_WindowWin32::GHOST_WindowWin32(GHOST_SystemWin32 *system, const STR_String &title, GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height, GHOST_TWindowState state, GHOST_TDrawingContextType type, bool wantStereoVisual, GHOST_TUns16 wantNumOfAASamples, GHOST_TEmbedderWindowID parentwindowhwnd, bool is_debug) : GHOST_Window(width, height, state, wantStereoVisual, false, wantNumOfAASamples), m_inLiveResize(false), m_system(system), m_hDC(0), m_hasMouseCaptured(false), m_hasGrabMouse(false), m_nPressedButtons(0), m_customCursor(0), m_wintab(NULL), m_tabletData(NULL), m_tablet(0), m_maxPressure(0), m_normal_state(GHOST_kWindowStateNormal), m_parentWindowHwnd(parentwindowhwnd), m_debug_context(is_debug) { OSVERSIONINFOEX versionInfo; bool hasMinVersionForTaskbar = false; ZeroMemory(&versionInfo, sizeof(OSVERSIONINFOEX)); versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if (!GetVersionEx((OSVERSIONINFO *)&versionInfo)) { versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (GetVersionEx((OSVERSIONINFO *)&versionInfo)) { if ((versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion >= 1) || (versionInfo.dwMajorVersion >= 7)) { hasMinVersionForTaskbar = true; } } } else { if ((versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion >= 1) || (versionInfo.dwMajorVersion >= 7)) { hasMinVersionForTaskbar = true; } } if (state != GHOST_kWindowStateFullScreen) { RECT rect; MONITORINFO monitor; GHOST_TUns32 tw, th; #ifndef _MSC_VER int cxsizeframe = GetSystemMetrics(SM_CXSIZEFRAME); int cysizeframe = GetSystemMetrics(SM_CYSIZEFRAME); #else // MSVC 2012+ returns bogus values from GetSystemMetrics, bug in Windows // http://connect.microsoft.com/VisualStudio/feedback/details/753224/regression-getsystemmetrics-delivers-different-values RECT cxrect = {0, 0, 0, 0}; AdjustWindowRectEx(&cxrect, WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_THICKFRAME | WS_DLGFRAME, FALSE, 0); int cxsizeframe = abs(cxrect.bottom); int cysizeframe = abs(cxrect.left); #endif width += cxsizeframe * 2; height += cysizeframe * 2 + GetSystemMetrics(SM_CYCAPTION); rect.left = left; rect.right = left + width; rect.top = top; rect.bottom = top + height; monitor.cbSize = sizeof(monitor); monitor.dwFlags = 0; // take taskbar into account GetMonitorInfo(MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST), &monitor); th = monitor.rcWork.bottom - monitor.rcWork.top; tw = monitor.rcWork.right - monitor.rcWork.left; if (tw < width) { width = tw; left = monitor.rcWork.left; } else if (monitor.rcWork.right < left + (int)width) left = monitor.rcWork.right - width; else if (left < monitor.rcWork.left) left = monitor.rcWork.left; if (th < height) { height = th; top = monitor.rcWork.top; } else if (monitor.rcWork.bottom < top + (int)height) top = monitor.rcWork.bottom - height; else if (top < monitor.rcWork.top) top = monitor.rcWork.top; int wintype = WS_OVERLAPPEDWINDOW; if (m_parentWindowHwnd != 0) { wintype = WS_CHILD; GetWindowRect((HWND)m_parentWindowHwnd, &rect); left = 0; top = 0; width = rect.right - rect.left; height = rect.bottom - rect.top; } wchar_t *title_16 = alloc_utf16_from_8((char *)(const char *)title, 0); m_hWnd = ::CreateWindowW( s_windowClassName, // pointer to registered class name title_16, // pointer to window name wintype, // window style left, // horizontal position of window top, // vertical position of window width, // window width height, // window height (HWND) m_parentWindowHwnd, // handle to parent or owner window 0, // handle to menu or child-window identifier ::GetModuleHandle(0), // handle to application instance 0); // pointer to window-creation data free(title_16); } else { wchar_t *title_16 = alloc_utf16_from_8((char *)(const char *)title, 0); m_hWnd = ::CreateWindowW( s_windowClassName, // pointer to registered class name title_16, // pointer to window name WS_POPUP | WS_MAXIMIZE, // window style left, // horizontal position of window top, // vertical position of window width, // window width height, // window height HWND_DESKTOP, // handle to parent or owner window 0, // handle to menu or child-window identifier ::GetModuleHandle(0), // handle to application instance 0); // pointer to window-creation data free(title_16); } if (m_hWnd) { // Register this window as a droptarget. Requires m_hWnd to be valid. // Note that OleInitialize(0) has to be called prior to this. Done in GHOST_SystemWin32. m_dropTarget = new GHOST_DropTargetWin32(this, m_system); if (m_dropTarget) { ::RegisterDragDrop(m_hWnd, m_dropTarget); } // Store a pointer to this class in the window structure ::SetWindowLongPtr(m_hWnd, GWLP_USERDATA, (LONG_PTR) this); // Store the device context m_hDC = ::GetDC(m_hWnd); GHOST_TSuccess success = setDrawingContextType(type); if (success) { // Show the window int nCmdShow; switch (state) { case GHOST_kWindowStateMaximized: nCmdShow = SW_SHOWMAXIMIZED; break; case GHOST_kWindowStateMinimized: nCmdShow = SW_SHOWMINIMIZED; break; case GHOST_kWindowStateNormal: default: nCmdShow = SW_SHOWNORMAL; break; } ::ShowWindow(m_hWnd, nCmdShow); // Force an initial paint of the window ::UpdateWindow(m_hWnd); } else { //invalidate the window ::DestroyWindow(m_hWnd); m_hWnd = NULL; } } if (parentwindowhwnd != 0) { RAWINPUTDEVICE device = {0}; device.usUsagePage = 0x01; /* usUsagePage & usUsage for keyboard*/ device.usUsage = 0x06; /* http://msdn.microsoft.com/en-us/windows/hardware/gg487473.aspx */ device.dwFlags |= RIDEV_INPUTSINK; // makes WM_INPUT is visible for ghost when has parent window device.hwndTarget = m_hWnd; RegisterRawInputDevices(&device, 1, sizeof(device)); } m_wintab = ::LoadLibrary("Wintab32.dll"); if (m_wintab) { GHOST_WIN32_WTInfo fpWTInfo = (GHOST_WIN32_WTInfo) ::GetProcAddress(m_wintab, "WTInfoA"); GHOST_WIN32_WTOpen fpWTOpen = (GHOST_WIN32_WTOpen) ::GetProcAddress(m_wintab, "WTOpenA"); // let's see if we can initialize tablet here /* check if WinTab available. */ if (fpWTInfo && fpWTInfo(0, 0, NULL)) { // Now init the tablet LOGCONTEXT lc; /* The maximum tablet size, pressure and orientation (tilt) */ AXIS TabletX, TabletY, Pressure, Orientation[3]; // Open a Wintab context // Get default context information fpWTInfo(WTI_DEFCONTEXT, 0, &lc); // Open the context lc.lcPktData = PACKETDATA; lc.lcPktMode = PACKETMODE; lc.lcOptions |= CXO_MESSAGES | CXO_SYSTEM; /* Set the entire tablet as active */ fpWTInfo(WTI_DEVICES, DVC_X, &TabletX); fpWTInfo(WTI_DEVICES, DVC_Y, &TabletY); /* get the max pressure, to divide into a float */ BOOL pressureSupport = fpWTInfo(WTI_DEVICES, DVC_NPRESSURE, &Pressure); if (pressureSupport) m_maxPressure = Pressure.axMax; else m_maxPressure = 0; /* get the max tilt axes, to divide into floats */ BOOL tiltSupport = fpWTInfo(WTI_DEVICES, DVC_ORIENTATION, &Orientation); if (tiltSupport) { /* does the tablet support azimuth ([0]) and altitude ([1]) */ if (Orientation[0].axResolution && Orientation[1].axResolution) { /* all this assumes the minimum is 0 */ m_maxAzimuth = Orientation[0].axMax; m_maxAltitude = Orientation[1].axMax; } else { /* no so dont do tilt stuff */ m_maxAzimuth = m_maxAltitude = 0; } } if (fpWTOpen) { m_tablet = fpWTOpen(m_hWnd, &lc, TRUE); if (m_tablet) { m_tabletData = new GHOST_TabletData(); m_tabletData->Active = GHOST_kTabletModeNone; } } } } if (hasMinVersionForTaskbar) CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList, (LPVOID *)&m_Bar); else m_Bar = NULL; }
void SetUserFriendlyFont(HWND hConWnd, int newFontY = 0, int newFontX = 0) { // Соответствующие функции появились только в API Vista // Win2k & WinXP - доступны только хаки, что не подходит _ASSERTE(_WIN32_WINNT_VISTA==0x600); OSVERSIONINFOEXW osvi = {sizeof(osvi), HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA)}; DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL); if (!VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask)) return; HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); COORD crVisibleSize = {}; CONSOLE_SCREEN_BUFFER_INFO csbi = {}; if (GetConsoleScreenBufferInfo(hOutput, &csbi)) { crVisibleSize.X = csbi.srWindow.Right - csbi.srWindow.Left + 1; crVisibleSize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; } if ((crVisibleSize.X <= 0) || (crVisibleSize.Y <= 0)) { _ASSERTE((crVisibleSize.X > 0) && (crVisibleSize.Y > 0)); return; } int curSizeY = 0, curSizeX = 0; wchar_t sFontName[LF_FACESIZE] = L""; if (apiGetConsoleFontSize(hOutput, curSizeY, curSizeX, sFontName) && curSizeY && curSizeX) { if (newFontY <= 0 || newFontX <= 0) { DEBUGTEST(COORD crLargest = MyGetLargestConsoleWindowSize(hOutput)); HMONITOR hMon = MonitorFromWindow(hConWnd, MONITOR_DEFAULTTOPRIMARY); MONITORINFO mi = {sizeof(mi)}; int nMaxX = 0, nMaxY = 0; if (GetMonitorInfo(hMon, &mi)) { nMaxX = mi.rcWork.right - mi.rcWork.left - 2*GetSystemMetrics(SM_CXSIZEFRAME) - GetSystemMetrics(SM_CYCAPTION); nMaxY = mi.rcWork.bottom - mi.rcWork.top - 2*GetSystemMetrics(SM_CYSIZEFRAME); } if ((nMaxX > 0) && (nMaxY > 0)) { int nFontX = nMaxX / crVisibleSize.X; int nFontY = nMaxY / crVisibleSize.Y; // Too large height? if (nFontY > 28) { nFontX = 28 * nFontX / nFontY; nFontY = 28; } // Evaluate default width for the font int nEvalX = EvaluateDefaultFontWidth(nFontY, sFontName); if (nEvalX > 0) { if ((nEvalX > nFontX) && (nFontX > 0)) nFontY = nFontX * nFontY / nEvalX; else nFontX = nEvalX; } // Look in the registry? HKEY hk; DWORD nRegSize = 0, nLen; if (!RegOpenKeyEx(HKEY_CURRENT_USER, L"Console", 0, KEY_READ, &hk)) { if (RegQueryValueEx(hk, L"FontSize", NULL, NULL, (LPBYTE)&nRegSize, &(nLen=sizeof(nRegSize))) || nLen!=sizeof(nRegSize)) nRegSize = 0; RegCloseKey(hk); } if (!nRegSize && !RegOpenKeyEx(HKEY_CURRENT_USER, L"Console\\%SystemRoot%_system32_cmd.exe", 0, KEY_READ, &hk)) { if (RegQueryValueEx(hk, L"FontSize", NULL, NULL, (LPBYTE)&nRegSize, &(nLen=sizeof(nRegSize))) || nLen!=sizeof(nRegSize)) nRegSize = 0; RegCloseKey(hk); } if ((HIWORD(nRegSize) > curSizeY) && (HIWORD(nRegSize) < nFontY) && (LOWORD(nRegSize) > curSizeX) && (LOWORD(nRegSize) < nFontX)) { nFontY = HIWORD(nRegSize); nFontX = LOWORD(nRegSize); } if ((nFontX > curSizeX) || (nFontY > curSizeY)) { newFontY = nFontY; newFontX = nFontX; } } } } if ((newFontY > 0) && (newFontX > 0)) { if (!*sFontName) lstrcpyn(sFontName, L"Lucida Console", countof(sFontName)); apiSetConsoleFontSize(hOutput, newFontY, newFontX, sFontName); } }
bool Win32Factory::init() { const char* vlc_name = "VLC Media Player"; const char* vlc_icon = "VLC_ICON"; const char* vlc_class = "SkinWindowClass"; // Get instance handle m_hInst = GetModuleHandle( NULL ); if( m_hInst == NULL ) { msg_Err( getIntf(), "Cannot get module handle" ); } // Create window class WNDCLASS skinWindowClass; skinWindowClass.style = CS_DBLCLKS; skinWindowClass.lpfnWndProc = (WNDPROC)Win32Factory::Win32Proc; skinWindowClass.lpszClassName = _T(vlc_class); skinWindowClass.lpszMenuName = NULL; skinWindowClass.cbClsExtra = 0; skinWindowClass.cbWndExtra = 0; skinWindowClass.hbrBackground = NULL; skinWindowClass.hCursor = LoadCursor( NULL, IDC_ARROW ); skinWindowClass.hIcon = LoadIcon( m_hInst, _T(vlc_icon) ); skinWindowClass.hInstance = m_hInst; // Register class and check it if( !RegisterClass( &skinWindowClass ) ) { WNDCLASS wndclass; // Check why it failed. If it's because the class already exists // then fine, otherwise return with an error. if( !GetClassInfo( m_hInst, _T(vlc_class), &wndclass ) ) { msg_Err( getIntf(), "cannot register window class" ); return false; } } // Create Window m_hParentWindow = CreateWindowEx( WS_EX_TOOLWINDOW, _T(vlc_class), _T(vlc_name), WS_POPUP | WS_SYSMENU | WS_MINIMIZEBOX, -200, -200, 0, 0, 0, 0, m_hInst, 0 ); if( m_hParentWindow == NULL ) { msg_Err( getIntf(), "cannot create parent window" ); return false; } // Store with it a pointer to the interface thread SetWindowLongPtr( m_hParentWindow, GWLP_USERDATA, (LONG_PTR)getIntf() ); // We do it this way otherwise CreateWindowEx will fail // if WS_EX_LAYERED is not supported SetWindowLongPtr( m_hParentWindow, GWL_EXSTYLE, GetWindowLongPtr( m_hParentWindow, GWL_EXSTYLE ) | WS_EX_LAYERED ); ShowWindow( m_hParentWindow, SW_SHOW ); // Initialize the systray icon m_trayIcon.cbSize = sizeof( NOTIFYICONDATA ); m_trayIcon.hWnd = m_hParentWindow; m_trayIcon.uID = 42; m_trayIcon.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE; m_trayIcon.uCallbackMessage = MY_WM_TRAYACTION; m_trayIcon.hIcon = LoadIcon( m_hInst, _T(vlc_icon) ); strcpy( m_trayIcon.szTip, vlc_name ); // Show the systray icon if needed if( var_InheritBool( getIntf(), "skins2-systray" ) ) { addInTray(); } // Show the task in the task bar if needed if( var_InheritBool( getIntf(), "skins2-taskbar" ) ) { addInTaskBar(); } // Initialize the OLE library (for drag & drop) OleInitialize( NULL ); // Initialize the resource path char *datadir = config_GetUserDir( VLC_DATA_DIR ); m_resourcePath.push_back( (string)datadir + "\\skins" ); free( datadir ); datadir = config_GetDataDir( getIntf() ); m_resourcePath.push_back( (string)datadir + "\\skins" ); m_resourcePath.push_back( (string)datadir + "\\skins2" ); m_resourcePath.push_back( (string)datadir + "\\share\\skins" ); m_resourcePath.push_back( (string)datadir + "\\share\\skins2" ); free( datadir ); // Enumerate all monitors available EnumDisplayMonitors( NULL, NULL, MonitorEnumProc, (LPARAM)&m_monitorList ); int num = 0; for( list<HMONITOR>::iterator it = m_monitorList.begin(); it != m_monitorList.end(); ++it, num++ ) { MONITORINFO mi; mi.cbSize = sizeof( MONITORINFO ); if( GetMonitorInfo( *it, &mi ) ) { msg_Dbg( getIntf(), "monitor #%i, %ldx%ld at +%ld+%ld", num, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, mi.rcMonitor.left, mi.rcMonitor.top ); } } // All went well return true; }
/** Toggle native window between fullscreen and normal mode */ void FWindowsWindow::SetWindowMode( EWindowMode::Type NewWindowMode ) { EWindowMode::Type InNewWindowMode = NewWindowMode; if (InNewWindowMode == EWindowMode::WindowedMirror) { // treat WindowedMirror as a regular Windowed mode here InNewWindowMode = EWindowMode::Windowed; } if( InNewWindowMode != WindowMode ) { bool bTrueFullscreen = NewWindowMode == EWindowMode::Fullscreen; // Setup Win32 Flags to be used for Fullscreen mode LONG WindowFlags = GetWindowLong(HWnd, GWL_STYLE); const LONG FullscreenFlags = WS_POPUP; const LONG RestoredFlags = WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU | WS_OVERLAPPED | WS_BORDER; // If we're not in fullscreen, make it so if( NewWindowMode == EWindowMode::WindowedFullscreen || NewWindowMode == EWindowMode::Fullscreen) { ::GetWindowPlacement(HWnd, &PreFullscreenWindowPlacement); // Setup Win32 flags for fullscreen window WindowFlags &= ~RestoredFlags; WindowFlags |= FullscreenFlags; SetWindowLong(HWnd, GWL_STYLE, WindowFlags); ::SetWindowPos(HWnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); if (!bTrueFullscreen) { // Ensure the window is restored if we are going for WindowedFullscreen ShowWindow(HWnd, SW_RESTORE); } // Get the current window position. RECT ClientRect; GetClientRect(HWnd, &ClientRect); // Grab current monitor data for sizing HMONITOR Monitor = MonitorFromWindow( HWnd, bTrueFullscreen ? MONITOR_DEFAULTTOPRIMARY : MONITOR_DEFAULTTONEAREST ); MONITORINFO MonitorInfo; MonitorInfo.cbSize = sizeof(MONITORINFO); GetMonitorInfo( Monitor, &MonitorInfo ); // Get the target client width to send to ReshapeWindow. // Preserve the current res if going to true fullscreen and the monitor supports it and allow the calling code // to resize if required. // Else, use the monitor's res for windowed fullscreen. LONG MonitorWidth = MonitorInfo.rcMonitor.right - MonitorInfo.rcMonitor.left; LONG TargetClientWidth = bTrueFullscreen ? FMath::Min(MonitorWidth, ClientRect.right - ClientRect.left) : MonitorWidth; LONG MonitorHeight = MonitorInfo.rcMonitor.bottom - MonitorInfo.rcMonitor.top; LONG TargetClientHeight = bTrueFullscreen ? FMath::Min(MonitorHeight, ClientRect.bottom - ClientRect.top) : MonitorHeight; // Resize and position fullscreen window ReshapeWindow( MonitorInfo.rcMonitor.left, MonitorInfo.rcMonitor.top, TargetClientWidth, TargetClientHeight); } else { // Windowed: // Setup Win32 flags for restored window WindowFlags &= ~FullscreenFlags; WindowFlags |= RestoredFlags; SetWindowLong(HWnd, GWL_STYLE, WindowFlags); ::SetWindowPos(HWnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); ::SetWindowPlacement(HWnd, &PreFullscreenWindowPlacement); } WindowMode = NewWindowMode; } }
D3D11VideoOutputInfo::D3D11VideoOutputInfo(IDXGIOutput* output, UINT32 outputIdx) :mDXGIOutput(output) { DXGI_OUTPUT_DESC outputDesc; output->GetDesc(&outputDesc); mName = UTF8::fromWide(WString(outputDesc.DeviceName)); UINT32 numModes = 0; HRESULT hr = output->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, nullptr); if (FAILED(hr)) { SAFE_RELEASE(output); BS_EXCEPT(InternalErrorException, "Error while enumerating adapter output video modes."); } DXGI_MODE_DESC* modeDesc = bs_newN<DXGI_MODE_DESC>(numModes); hr = output->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, modeDesc); if (FAILED(hr)) { bs_deleteN(modeDesc, numModes); SAFE_RELEASE(output); BS_EXCEPT(InternalErrorException, "Error while enumerating adapter output video modes."); } for (UINT32 i = 0; i < numModes; i++) { DXGI_MODE_DESC displayMode = modeDesc[i]; bool foundVideoMode = false; for (auto videoMode : mVideoModes) { D3D11VideoMode* d3d11videoMode = static_cast<D3D11VideoMode*>(videoMode); if (d3d11videoMode->mWidth == displayMode.Width && d3d11videoMode->mHeight == displayMode.Height && d3d11videoMode->mRefreshRateNumerator == displayMode.RefreshRate.Numerator && d3d11videoMode->mRefreshRateDenominator == displayMode.RefreshRate.Denominator) { foundVideoMode = true; break; } } if (!foundVideoMode) { float refreshRate = displayMode.RefreshRate.Numerator / (float)displayMode.RefreshRate.Denominator; D3D11VideoMode* videoMode = bs_new<D3D11VideoMode>(displayMode.Width, displayMode.Height, refreshRate, outputIdx, displayMode.RefreshRate.Numerator, displayMode.RefreshRate.Denominator, displayMode); mVideoModes.push_back(videoMode); } } bs_deleteN(modeDesc, numModes); // Get desktop display mode HMONITOR hMonitor = outputDesc.Monitor; MONITORINFOEX monitorInfo; monitorInfo.cbSize = sizeof(MONITORINFOEX); GetMonitorInfo(hMonitor, &monitorInfo); DEVMODE devMode; devMode.dmSize = sizeof(DEVMODE); devMode.dmDriverExtra = 0; EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode); DXGI_MODE_DESC currentMode; currentMode.Width = devMode.dmPelsWidth; currentMode.Height = devMode.dmPelsHeight; bool useDefaultRefreshRate = 1 == devMode.dmDisplayFrequency || 0 == devMode.dmDisplayFrequency; currentMode.RefreshRate.Numerator = useDefaultRefreshRate ? 0 : devMode.dmDisplayFrequency; currentMode.RefreshRate.Denominator = useDefaultRefreshRate ? 0 : 1; currentMode.Format = DXGI_FORMAT_R8G8B8A8_UNORM; currentMode.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; currentMode.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; DXGI_MODE_DESC nearestMode; ZeroMemory(&nearestMode, sizeof(nearestMode)); output->FindClosestMatchingMode(¤tMode, &nearestMode, nullptr); float refreshRate = nearestMode.RefreshRate.Numerator / (float)nearestMode.RefreshRate.Denominator; mDesktopVideoMode = bs_new<D3D11VideoMode>(nearestMode.Width, nearestMode.Height, refreshRate, outputIdx, nearestMode.RefreshRate.Numerator, nearestMode.RefreshRate.Denominator, nearestMode); }
/*****************************Private*Routine******************************\ * GetAMDDrawMonitorInfo * * * * History: * Tue 08/17/1999 - StEstrop - Created * \**************************************************************************/ BOOL CMonitorArray::GetAMDDrawMonitorInfo( UINT uDevID, _Out_ CAMDDrawMonitorInfo* lpmi, _In_ HMONITOR hm ) { MONITORINFOEX miInfoEx; miInfoEx.cbSize = sizeof(miInfoEx); lpmi->hMon = NULL; lpmi->uDevID = 0; lpmi->physMonDim.cx = 0; lpmi->physMonDim.cy = 0; lpmi->dwRefreshRate = DEFAULT_DENSITY_LIMIT; if (GetMonitorInfo(hm, &miInfoEx)) { HRESULT hr = StringCchCopy(lpmi->szDevice, sizeof(lpmi->szDevice)/sizeof(lpmi->szDevice[0]), miInfoEx.szDevice); if ( FAILED( hr ) ) { return FALSE; } lpmi->hMon = hm; lpmi->uDevID = uDevID; lpmi->physMonDim.cx = WIDTH(&miInfoEx.rcMonitor); lpmi->physMonDim.cy = HEIGHT(&miInfoEx.rcMonitor); int j = 0; DISPLAY_DEVICE ddMonitor; ddMonitor.cb = sizeof(ddMonitor); while (EnumDisplayDevices(lpmi->szDevice, j, &ddMonitor, 0)) { if (ddMonitor.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) { DEVMODE dm; ZeroMemory(&dm, sizeof(dm)); dm.dmSize = sizeof(dm); if (EnumDisplaySettings(lpmi->szDevice, ENUM_CURRENT_SETTINGS, &dm)) { lpmi->dwRefreshRate = dm.dmDisplayFrequency == 0 ? lpmi->dwRefreshRate : dm.dmDisplayFrequency; } // Remove registry snooping for monitor dimensions, as this is not supported by LDDM. // if (!FindMonitorDimensions(ddMonitor.DeviceID, &lpmi->physMonDim.cx, &lpmi->physMonDim.cy)) { lpmi->physMonDim.cx = WIDTH(&miInfoEx.rcMonitor); lpmi->physMonDim.cy = HEIGHT(&miInfoEx.rcMonitor); } } j++; } return TRUE; } return FALSE; }