int setupPixelFormat(HDC hDC) { PIXELFORMATDESCRIPTOR pfd; int pixelFormat; memset(&pfd,0,sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; pixelFormat = ChoosePixelFormat(hDC, &pfd); if (pixelFormat == 0) { MessageBox(WindowFromDC(hDC), "ChoosePixelFormat failed.", "Error", MB_ICONERROR | MB_OK); exit(1); } if (SetPixelFormat(hDC, pixelFormat, &pfd) != TRUE) { MessageBox(WindowFromDC(hDC), "SetPixelFormat failed.", "Error", MB_ICONERROR | MB_OK); exit(1); } }
HOOKFUNC BOOL WINAPI MyStretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, DWORD dwRop) { bool isFrameBoundary = false; if (!usingSDLOrDD /*&& !inPauseHandler*/ && !redrawingScreen) { if (dwRop == SRCCOPY) { HWND hwnd = WindowFromDC(hdcDest); if (hwnd /*&& !hwndRespondingToPaintMessage[hwnd]*/) { if ((/*s_gdiPhaseDetector.AdvanceAndCheckCycleBoundary(MAKELONG(nXOriginDest,nYOriginDest)) ||*/ tls.peekedMessage) && VerifyIsTrustedCaller(!tls.callerisuntrusted)) { if ((nWidthSrc >= gdiFrameBigEnoughWidth && nHeightSrc >= gdiFrameBigEnoughHeight) || HDCSizeBigEnoughForFrameBoundary(hdcSrc)) { isFrameBoundary = true; } } } } } ENTER(); BOOL rv = TRUE; if (!ShouldSkipDrawing(false, WindowFromDC(hdcDest) != 0)) { if (s_gdiPendingRefresh && !redrawingScreen) { redrawingScreen = true; RedrawScreenGDI(); redrawingScreen = false; } rv = StretchBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, dwRop); } else s_gdiPendingRefresh = true; if (isFrameBoundary) { tls.peekedMessage = FALSE; if (!(tasflags.aviMode & 1)) FrameBoundary(NULL, CAPTUREINFO_TYPE_NONE); else FrameBoundaryHDCtoAVI(hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc); s_hdcSrcSaved = hdcSrc; s_hdcDstSaved = hdcDest; } return rv; }
void stubGetWindowGeometry(WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h ) { RECT rect; if (!window->drawable || !window->hWnd) { *w = *h = 0; return; } if (window->hWnd!=WindowFromDC(window->drawable)) { crWarning("Window(%i) DC is no longer valid", window->spuWindow); return; } if (!GetClientRect(window->hWnd, &rect)) { crWarning("GetClientRect failed for %p", window->hWnd); *w = *h = 0; return; } *w = rect.right - rect.left; *h = rect.bottom - rect.top; if (!ClientToScreen( window->hWnd, (LPPOINT) &rect )) { crWarning("ClientToScreen failed for %p", window->hWnd); *w = *h = 0; return; } *x = rect.left; *y = rect.top; }
static void gl_init(HDC hdc) { HWND window = WindowFromDC(hdc); bool success = false; RECT rc = {0}; GetClientRect(window, &rc); data.base_cx = rc.right; data.base_cy = rc.bottom; data.hdc = hdc; data.format = DXGI_FORMAT_B8G8R8A8_UNORM; data.using_scale = global_hook_info->use_scale; data.using_shtex = nv_capture_available && !global_hook_info->force_shmem; if (data.using_scale) { data.cx = global_hook_info->cx; data.cy = global_hook_info->cy; } else { data.cx = data.base_cx; data.cy = data.base_cy; } if (data.using_shtex) success = gl_shtex_init(window); else success = gl_shmem_init(window); if (!success) gl_free(); }
ClientHandler::ClientHandler() : m_bFocusOnEditableField(false) { sClientApp->addClientHandler(CefRefPtr<ClientHandler>(this)); //ofLogNotice() << (__FUNCTION__) << std::endl; CreateProcessMessageDelegates(process_message_delegates_); // Read command line settings. CefRefPtr<CefCommandLine> command_line = CefCommandLine::GetGlobalCommandLine(); if (command_line->HasSwitch(cefclient::kUrl)) m_StartupURL = command_line->GetSwitchValue(cefclient::kUrl); if (m_StartupURL.empty()) m_StartupURL = "http://www.google.com/"; // Also use external dev tools if off-screen rendering is enabled since we // disallow popup windows. m_bExternalDevTools = true; m_bMouseCursorChangeDisabled = command_line->HasSwitch(cefclient::kMouseCursorChangeDisabled); // Grab the openframeworks Window Handle ofxWindowHandle = WindowFromDC(wglGetCurrentDC()); }
int XDisplayHeight(Display *dpy, int scr) { RECT rc; HWND hwnd = WindowFromDC(dpy); GetWindowRect(hwnd, &rc); return rc.bottom - rc.top; }
int XDisplayWidth(Display *dpy, int scr) { RECT rc; HWND hwnd = WindowFromDC(dpy); GetWindowRect(hwnd, &rc); return rc.right - rc.left; }
void stubGetWindowGeometry( const WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h ) { RECT rect; HWND hwnd; if (!window->drawable) { *w = *h = 0; return; } hwnd = WindowFromDC( window->drawable ); if (!hwnd) { *w = 0; *h = 0; } else { GetClientRect( hwnd, &rect ); *x = rect.left; *y = rect.top; *w = rect.right - rect.left; *h = rect.bottom - rect.top; } }
// Utilities // // GLDXcompatible // bool spoutGLDXinterop::GLDXcompatible() { // // ======= Hardware compatibility test ======= // // Call LoadGLextensions for an initial hardware compatibilty check and // also load Glew for the Nvidia OpenGL/Directx interop extensions. // This will fail straight away for non Nvidia hardware but it needs // an additional check. It is possible that the extensions load OK, // but that initialization will still fail. This occurs when wglDXOpenDeviceNV // fails. This has been noted on dual graphics machines with the NVIDIA Optimus driver. // "GLDXcompatible" tests for this by initializing directx and calling wglDXOpenDeviceNV // If OK and the debug flag has not been set all the parameters are available // Otherwise it is limited to memory share // HDC hdc = wglGetCurrentDC(); // OpenGl device context is needed if(!hdc) { // MessageBoxA(NULL, "Spout compatibility test\nCannot get GL device context", "OpenSpout", MB_OK); return false; } HWND hWnd = WindowFromDC(hdc); // can be null though if(!bExtensionsLoaded) bExtensionsLoaded = LoadGLextensions(); if(bExtensionsLoaded) { // all OK and not debug memoryshare // try to set up directx and open the GL/DX interop if(OpenDirectX(hWnd, bUseDX9)) { // if it passes here all is well return true; } } // end hardware compatibility test return false; } // end GLDXcompatible
static bool stubSystemWindowExist(WindowInfo *pWindow) { #ifdef WINDOWS if (pWindow->hWnd!=WindowFromDC(pWindow->drawable)) { return false; } #else Window root; int x, y; unsigned int border, depth, w, h; Display *dpy; dpy = stubGetWindowDisplay(pWindow); XLOCK(dpy); if (!XGetGeometry(dpy, pWindow->drawable, &root, &x, &y, &w, &h, &border, &depth)) { XUNLOCK(dpy); return false; } XUNLOCK(dpy); #endif return true; }
HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, bool& Minimised, int& Width, int& Height, D3DFORMAT Format) { IDirect3DSurface9* RenderTarget = nullptr; IDirect3DSurface9* DestTarget = nullptr; HRESULT result = Device->GetRenderTarget(0, &RenderTarget); if (result == S_OK) { if (Width == 0 || Height == 0 || Format == D3DFMT_UNKNOWN) { D3DSURFACE_DESC descriptor = {}; RenderTarget->GetDesc(&descriptor); Width = descriptor.Width; Height = descriptor.Height; Format = descriptor.Format; } HDC DC = nullptr; RenderTarget->GetDC(&DC); Minimised = IsIconic(WindowFromDC(DC)); RenderTarget->ReleaseDC(DC); result = Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &DestTarget, nullptr); result = Device->GetRenderTargetData(RenderTarget, DestTarget); D3DLOCKED_RECT rect; DestTarget->LockRect(&rect, 0, D3DLOCK_READONLY); memcpy(Buffer, rect.pBits, Width * Height * 4); DestTarget->UnlockRect(); } SafeRelease(RenderTarget); SafeRelease(DestTarget); return result; }
//-------------------------------------------------------------- bool ofLVOpenProgram(string pathAbsFile) { #ifdef TARGET_OSX CFStringRef cfPathAbsFile = CFStringCreateWithCString(NULL,pathAbsFile.c_str(),CFStringGetSystemEncoding()); if (cfPathAbsFile != NULL) { CFURLRef cfUrl = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,cfPathAbsFile,kCFURLPOSIXPathStyle,false); if (cfUrl != NULL) { LSOpenCFURLRef(cfUrl, NULL); return true; } } return false; #endif #ifdef TARGET_WIN32 // http://msdn.microsoft.com/en-us/library/bb762153%28VS.85%29.aspx HWND hwnd = WindowFromDC(wglGetCurrentDC()); return ((int)ShellExecute(hwnd, "open", pathAbsFile.c_str(),0,0,SW_SHOWNORMAL))>32; #endif return false; }
HRESULT CVCamStream::OpenReceiver() { HDC GLhdc; glContext = wglGetCurrentContext(); // Once created it seems stable and retained if(glContext == NULL) { // You need to create a rendering context BEFORE calling glewInit() // First you need to create a valid OpenGL rendering context and call glewInit() // to initialize the extension entry points. int argc = 1; char *argv = (char*)"vCam"; char **vptr = &argv; glutInit(&argc, vptr); // In this case there is not be a rendering context. There is if an external window is present // but we don't know what it is. So create a window here but it will not show. glutCreateWindow("vCamGL"); GLhdc = wglGetCurrentDC(); GLhwnd = WindowFromDC(GLhdc); } // end no glcontext // This is a receiver so try to connect if(receiver.CreateReceiver(SharedMemoryName, senderWidth, senderHeight)) { return NO_ERROR; } return S_FALSE; } // end OpenReceiver
void TextureCreateEmpty (CCallParams& p) { CBaseOglControl* ctrl = CBaseOglControl::controls[WindowFromDC(wglGetCurrentDC())]; if (0 == ctrl || p.AsString(0) == "")return; ctrl->Collection().TextureList().Create(p.AsString(0)); CBaseTexture* tex = GetTexture(p.AsString(0)); if (tex != 0) tex->CreateEmpty(p.AsInt(1), p.AsInt(2)); }
int XClearWindow(Display *dpy, Window w) { RECT rc; HDC hdc = (HDC)dpy; HWND hwnd = WindowFromDC(hdc); GetClientRect(hwnd, &rc); return FillRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH)); }
void TextureCreate(CCallParams& p) //создание текстуры и загрузка картинки { CBaseOglControl* ctrl = CBaseOglControl::controls[WindowFromDC(wglGetCurrentDC())]; if (0 == ctrl || p.AsString(0) == "")return; ctrl->Collection().TextureList().Create(p.AsString(0)); CBaseTexture* tex = GetTexture(p.AsString(0)); if (tex != 0) tex->LoadTexture(p.AsString(1)); }
void CreateFont(CCallParams& p) { if (p.AsString(0) == "" || GetFont(p.AsString(0)) != 0)return; CBaseOglControl* ctrl = CBaseOglControl::controls[WindowFromDC(wglGetCurrentDC())]; if (ctrl == 0)return; CBaseFont *f = ctrl->Collection().FontsList().Create(p.AsString(0)); if (f == 0)return; f->SetSprite(ctrl->Collection().SpriteList().Get(p.AsString(1))); }
static void get_window_size(HDC hdc, uint32_t *cx, uint32_t *cy) { HWND hwnd = WindowFromDC(hdc); RECT rc = {0}; GetClientRect(hwnd, &rc); *cx = rc.right; *cy = rc.bottom; }
void setupPixelFormat(HDC hDC) { PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), /* size of this pfd */ 1, /* version num */ PFD_DRAW_TO_WINDOW | /* support window */ PFD_SUPPORT_OPENGL | /* support OpenGL */ PFD_DOUBLEBUFFER, /* support double-buffering */ PFD_TYPE_COLORINDEX, /* color index mode */ 8, /* 8-bit color depth */ 0, 0, 0, 0, 0, 0, /* color bits (ignored) */ 0, /* no alpha buffer */ 0, /* alpha bits (ignored) */ 0, /* no accumulation buffer */ 0, 0, 0, 0, /* accum bits (ignored) */ 16, /* depth buffer */ 0, /* no stencil buffer */ 0, /* no auxiliary buffers */ PFD_MAIN_PLANE, /* main layer */ 0, /* reserved */ 0, 0, 0, /* no layer, visible, damage masks */ }; int SelectedPixelFormat; BOOL retVal; SelectedPixelFormat = ChoosePixelFormat(hDC, &pfd); if (SelectedPixelFormat == 0) { MessageBox(WindowFromDC(hDC), "ChoosePixelFormat failed\n" "This application works best with an 8-bit\n" "(256 color) display mode\n", "Error", MB_ICONERROR | MB_OK); exit(1); } retVal = SetPixelFormat(hDC, SelectedPixelFormat, &pfd); if (retVal != TRUE) { MessageBox(WindowFromDC(hDC), "SetPixelFormat failed", "Error", MB_ICONERROR | MB_OK); exit(1); } }
static void GetCursorPosition( const WindowInfo *window, int pos[2] ) { RECT rect; POINT point; GLint size[2], x, y; unsigned int NativeHeight, NativeWidth, ChromiumHeight, ChromiumWidth; float WidthRatio, HeightRatio; static int DebugFlag = 0; // apparently the "window" parameter passed to this // function contains the native window information HWND NATIVEhwnd = WindowFromDC( window->drawable ); // get the native window's height and width stubGetWindowGeometry(window, &x, &y, &NativeWidth, &NativeHeight); // get the spu window's height and width stub.spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, window->spuWindow, GL_INT, 2, size); ChromiumWidth = size[0]; ChromiumHeight = size[1]; // get the ratio of the size of the native window to the cr window WidthRatio = (float)ChromiumWidth / (float)NativeWidth; HeightRatio = (float)ChromiumHeight / (float)NativeHeight; // output some debug information at the beginning if(DebugFlag) { DebugFlag = 0; crDebug("Native Window Handle = %d", NATIVEhwnd); crDebug("Native Width = %i", NativeWidth); crDebug("Native Height = %i", NativeHeight); crDebug("Chromium Width = %i", ChromiumWidth); crDebug("Chromium Height = %i", ChromiumHeight); } if (NATIVEhwnd) { GetClientRect( NATIVEhwnd, &rect ); GetCursorPos (&point); // make sure these coordinates are relative to the native window, // not the whole desktop ScreenToClient(NATIVEhwnd, &point); // calculate the new position of the virtual cursor pos[0] = (int)(point.x * WidthRatio); pos[1] = (int)((NativeHeight - point.y) * HeightRatio); } else { pos[0] = 0; pos[1] = 0; } }
void SpriteCreate(CCallParams& p) { CBaseOglControl* ctrl = CBaseOglControl::controls[WindowFromDC(wglGetCurrentDC())]; if (0 == ctrl || p.AsString(0) == "" || p.AsString(1) == "")return; ctrl->Collection().SpriteList().Create(p.AsString(0)); CBaseSprite* spr = GetSprite(p.AsString(0)); if (spr == 0)return; CBaseTexture* tex = ctrl->Collection().TextureList().Get(p.AsString(1)); spr->SetTexture(tex); }
void clipper_t::fill() { HWND h = WindowFromDC(hdc); window_rect_t r(h); temp_object_t reg( CreateRectRgn(r.l, r.t, r.r, r.b)); SelectClipRgn(hdc, (HRGN)reg.handle); }
//-------------------------------------- static void fixCloseWindowOnWin32(){ //get the HWND handle = WindowFromDC(wglGetCurrentDC()); //store the current message event handler for the window currentWndProc = (WNDPROC)GetWindowLongPtr(handle, GWL_WNDPROC); //tell the window to now use our event handler! SetWindowLongPtr(handle, GWL_WNDPROC, (long)winProc); }
static void GetWindowTitle( const WindowInfo *window, char *title ) { HWND hwnd; /* XXX - we don't handle recurseUp */ hwnd = WindowFromDC( window->drawable ); if (hwnd) GetWindowText(hwnd, title, 100); else title[0] = 0; }
//--------------------------------------------------------------------------------- int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { int argc = 0; char* argv = ""; // Exit handler to check memory on exit. const int result_1 = std::atexit(CheckMemCallback); std::wstring commandLine(lpCmdLine); gEditorMode = commandLine.find(L"-Editor") != std::string::npos; // Setup glut. glutInit(&argc, &argv); glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); glutInitWindowPosition(100, 100); int glutWind = glutCreateWindow(APP_WINDOW_TITLE); HDC dc = wglGetCurrentDC(); MAIN_WINDOW_HANDLE = WindowFromDC(dc); glutIdleFunc(Idle); glutDisplayFunc(Display); // Register callback handler for window re-paint event glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); InitGL(); // Our own OpenGL initialization // Init sounds system. CSimpleSound::GetInstance().Initialize(MAIN_WINDOW_HANDLE); // Call user defined init. if (gEditorMode) { EditorInit(); } else { Init(); } // Enter glut the event-processing loop glutMainLoop(); // Call user shutdown. if (gEditorMode) { EditorShutdown(); } else { Shutdown(); } // Shutdown sound system. CSimpleSound::GetInstance().Shutdown(); // And we are done. return 0; }
/** * Given an hdc, return the corresponding stw_framebuffer. * The returned stw_framebuffer will have its mutex locked. */ static struct stw_framebuffer * stw_framebuffer_from_hdc_locked(HDC hdc) { HWND hwnd; hwnd = WindowFromDC(hdc); if (!hwnd) { return NULL; } return stw_framebuffer_from_hwnd_locked(hwnd); }
void CBaseOglCamera::GetViewPort(RECT& vp) { if (viewPort[0] != 0 || viewPort[1] != 0 || viewPort[2] != 0 || viewPort[3] != 0) { vp.left = viewPort[0]; vp.top = viewPort[1]; vp.right = viewPort[2]; vp.bottom = viewPort[3]; } else GetClientRect(WindowFromDC(wglGetCurrentDC()), &vp); }
WINGDIAPI BOOL WINAPI wglMakeCurrent(HDC hdc, DHGLRC hglrc) { if (!gCurrentContextSet) { gCurrentContext = gContexts.end(); gCurrentContextSet = true; } if (!hdc || !hglrc) { gCurrentContext = gContexts.end(); return 1; } int rc = (int)hglrc; if (gContexts.find(rc) == gCurrentContext) { return 1; } gCurrentContext = gContexts.find(rc); auto &xCtxt = gContexts[rc]; OGL::State *pState = xCtxt.pState; HWND hWnd = WindowFromDC(hdc); RECT rect; GetClientRect(hWnd, &rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; SetOGL(pState); OGL::GetDDProcTable().pfnBindContext(OGL::GetDDHandle(), NULL, hWnd, NULL, width, height); // according to spec, only set current viewport to draw buffer dimensions if the context hasn't // been initialized if (!xCtxt.initialized) { pState->mViewport.x = 0; pState->mViewport.y = 0; pState->mViewport.width = width; pState->mViewport.height = height; pState->mScissor.x = 0; pState->mScissor.y = 0; pState->mScissor.width = width; pState->mScissor.height = height; xCtxt.initialized = true; } return 1; }
static void lbmSetupPixelFormat(HDC dc) { PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), /* size */ 1, /* version */ PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER, /* support double-buffering */ PFD_TYPE_RGBA, /* color type */ 16, /* prefered color depth */ 0, 0, 0, 0, 0, 0, /* color bits (ignored) */ 0, /* no alpha buffer */ 0, /* alpha bits (ignored) */ 0, /* no accumulation buffer */ 0, 0, 0, 0, /* accum bits (ignored) */ 16, /* depth buffer */ 0, /* no stencil buffer */ 0, /* no auxiliary buffers */ PFD_MAIN_PLANE, /* main layer */ 0, /* reserved */ 0, 0, 0, /* no layer, visible, damage masks */ }; int pixelFormat; pixelFormat = ChoosePixelFormat(dc, &pfd); if (pixelFormat == 0) { MessageBox(WindowFromDC(dc), "ChoosePixelFormat failed.", "Error", MB_ICONERROR | MB_OK); exit(1); } if (SetPixelFormat(dc, pixelFormat, &pfd) != TRUE) { MessageBox(WindowFromDC(dc), "SetPixelFormat failed.", "Error", MB_ICONERROR | MB_OK); exit(1); } }
/*********************************************************************** * UserRealizePalette (USER32.@) */ UINT WINAPI UserRealizePalette( HDC hDC ) { UINT realized = pfnGDIRealizePalette( hDC ); /* do not send anything if no colors were changed */ if (realized && GetCurrentObject( hDC, OBJ_PAL ) == hPrimaryPalette) { /* send palette change notification */ HWND hWnd = WindowFromDC( hDC ); if (hWnd) SendMessageTimeoutW( HWND_BROADCAST, WM_PALETTECHANGED, (WPARAM)hWnd, 0, SMTO_ABORTIFHUNG, 2000, NULL ); } return realized; }