void poll() override { event_based_device::poll(); CURSORINFO cursor_info = {0}; cursor_info.cbSize = sizeof(CURSORINFO); GetCursorInfo(&cursor_info); // We only take over the mouse if the cursor isn't showing // This should happen anyway in mouse mode if (!(cursor_info.flags & CURSOR_SHOWING)) { // We measure the position change from the previously set center position mouse.lX = (cursor_info.ptScreenPos.x - win32_mouse.last_point.x) * INPUT_RELATIVE_PER_PIXEL; mouse.lY = (cursor_info.ptScreenPos.y - win32_mouse.last_point.y) * INPUT_RELATIVE_PER_PIXEL; RECT window_pos = {0}; GetWindowRect(osd_common_t::s_window_list.front()->platform_window<HWND>(), &window_pos); // We reset the cursor position to the middle of the window each frame win32_mouse.last_point.x = window_pos.left + (window_pos.right - window_pos.left) / 2; win32_mouse.last_point.y = window_pos.top + (window_pos.bottom - window_pos.top) / 2; SetCursorPos(win32_mouse.last_point.x, win32_mouse.last_point.y); } }
void dc_capture_capture(struct dc_capture *capture, HWND window) { HDC hdc_target; HDC hdc; if (capture->capture_cursor) { memset(&capture->ci, 0, sizeof(CURSORINFO)); capture->ci.cbSize = sizeof(CURSORINFO); capture->cursor_captured = GetCursorInfo(&capture->ci); } if (++capture->cur_tex == capture->num_textures) capture->cur_tex = 0; hdc = dc_capture_get_dc(capture); if (!hdc) { blog(LOG_WARNING, "[capture_screen] Failed to get " "texture DC"); return; } hdc_target = GetDC(window); BitBlt(hdc, 0, 0, capture->width, capture->height, hdc_target, capture->x, capture->y, SRCCOPY); ReleaseDC(NULL, hdc_target); if (capture->cursor_captured) draw_cursor(capture, hdc); dc_capture_release_dc(capture); capture->textures_written[capture->cur_tex] = true; }
static int Win32_GetCursorInfo(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) { Jim_Obj *a[8]; size_t n = 0; CURSORINFO ci; JIM_NOTUSED(objc); JIM_NOTUSED(objv); ci.cbSize = sizeof(ci); if (!GetCursorInfo(&ci)) { Jim_SetResult(interp, Win32ErrorObj(interp, "GetCursorInfo", GetLastError())); return JIM_ERR; } #define JIMADDN(name) a[n++] = Jim_NewStringObj(interp, #name, -1); #define JIMADDV(v) a[n++] = Jim_NewIntObj(interp, (v)); JIMADDN(flags); JIMADDV(ci.flags); JIMADDN(hCursor); JIMADDV((DWORD)ci.hCursor); JIMADDN(x); JIMADDV(ci.ptScreenPos.x); JIMADDN(y); JIMADDV(ci.ptScreenPos.y); #undef JIMADDN #undef JIMADDV Jim_SetResult(interp, Jim_NewListObj(interp, a, n)); return JIM_OK; }
Utilities::Point GetCursorPos() { Utilities::Point pos; CURSORINFO cursorInfo; cursorInfo.cbSize = sizeof(cursorInfo); if(GetCursorInfo(&cursorInfo) == FALSE) { SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, "GetCursorInfo == FALSE"); return pos; } ICONINFOEXA ii = { 0 }; ii.cbSize = sizeof(ii); if(GetIconInfoExA(cursorInfo.hCursor, &ii) == FALSE) { //this tends to fail on hyper-v enviornments generating alot of noise. so lower its level to Info.. SL_RAT_LOG(Utilities::Logging_Levels::INFO_log_level, "GetIconInfoEx == FALSE"); return pos; } auto colorbmp = RAIIHBITMAP(ii.hbmColor); // make sure this is cleaned up properly auto maskbmp = RAIIHBITMAP(ii.hbmMask); // make sure this is cleaned up properly pos.X = cursorInfo.ptScreenPos.x - ii.xHotspot; pos.Y = cursorInfo.ptScreenPos.y - ii.yHotspot; return pos; }
void CMouseControl::GetPointerLocation (long& x, long& y) { #if defined(WIN32) CURSORINFO pci; pci.cbSize= sizeof(CURSORINFO); pci.ptScreenPos.x= 0; pci.ptScreenPos.y= 0; GetCursorInfo(&pci); x= pci.ptScreenPos.x; y= pci.ptScreenPos.y; #else // Linux Window root, child; int rootX, rootY, winX, winY; unsigned int xstate; Window rootWin= RootWindow (static_cast<Display*>(m_pDisplay), DefaultScreen (static_cast<Display*>(m_pDisplay))); XQueryPointer( static_cast<Display*>(m_pDisplay), rootWin, &root, &child, &rootX, &rootY, &winX, &winY, &xstate ); x= winX; y= winY; #endif }
BOOL CScreenCapture::CaptureScreenRect( std::vector<CRect> arcCapture, CString sSaveDirName, int nIdStartFrom, SCREENSHOT_IMAGE_FORMAT fmt, int nJpegQuality, BOOL bGrayscale, std::vector<MonitorInfo>& monitor_list) { // Init output variables monitor_list.clear(); // Set internal variables m_nIdStartFrom = nIdStartFrom; m_sSaveDirName = sSaveDirName; m_fmt = fmt; m_nJpegQuality = nJpegQuality; m_bGrayscale = bGrayscale; m_arcCapture = arcCapture; m_monitor_list.clear(); // Get cursor information GetCursorPos(&m_ptCursorPos); m_CursorInfo.cbSize = sizeof(CURSORINFO); GetCursorInfo(&m_CursorInfo); // Perform actual capture task inside of EnumMonitorsProc EnumDisplayMonitors(NULL, NULL, EnumMonitorsProc, (LPARAM)this); // Return monitor_list = m_monitor_list; return TRUE; }
MyWindow::~MyWindow() { #ifdef WIN32 // CURSORINFO cursorInfo; cursorInfo.cbSize=sizeof(CURSORINFO); if(GetCursorInfo(&cursorInfo) && cursorInfo.flags==0) { ShowCursor(TRUE); } // wglMakeCurrent(NULL,NULL); wglDeleteContext(hglrc); CloseWindow(hWnd); HINSTANCE hInstance=GetModuleHandle(0); #ifdef UNICODE UnregisterClass(L"win32app",hInstance); #else UnregisterClass("win32app",hInstance); #endif #endif #ifdef LINUX glXMakeCurrent(display,0,0); glXDestroyContext(display,ctx); XDestroyWindow(display,win); XFreeColormap(display,cmap); XCloseDisplay(display); #endif }
////////////////////////////////////////////////////////////////////////// // setMouseLock void OsClientWindows::setMouseLock( BcBool Enabled ) { // Hide cursor too. CURSORINFO CursorInfo; CursorInfo.cbSize = sizeof(CursorInfo); GetCursorInfo( &CursorInfo ); if( Enabled ) { if( MouseLocked_ == BcFalse ) { POINT MousePosition; POINT WindowPosition; RECT Rect; // Get window rect in screen space. ::GetWindowRect( hWnd_, &Rect ); // Screen space cood of the client area. WindowPosition.x = 0; WindowPosition.y = 0; ::ClientToScreen( hWnd_, &WindowPosition ); // Get the cursor position ::GetCursorPos( &MousePosition ); const BcS32 WX = ( Rect.right - Rect.left ); const BcS32 WY = ( Rect.bottom - Rect.top ); // Reset delta. MouseDelta_ = MaVec2d( 0.0f, 0.0f ); MousePrevDelta_ = MaVec2d( 0.0f, 0.0f ); // Position in center of screen. ::SetCursorPos( Rect.left + ( WX / 2 ), Rect.top + ( WY / 2 ) ); if ( CursorInfo.flags == CURSOR_SHOWING ) { while ( ShowCursor( FALSE ) >= 0 ) { } } } } else { if ( CursorInfo.flags != CURSOR_SHOWING ) { while ( ShowCursor( TRUE ) < 0 ) { } } } MouseLocked_ = Enabled; }
HCURSOR WindowsCursorShapeGrabber::getHCursor() { CURSORINFO cursorInfo; cursorInfo.cbSize = sizeof(CURSORINFO); if (GetCursorInfo(&cursorInfo) == 0) { return false; } return cursorInfo.hCursor; }
void lock_cursor_win32(HWND hWnd,bool lock, bool *locked,int cursorX,int cursorY) { CURSORINFO cursorInfo; cursorInfo.cbSize=sizeof(CURSORINFO); GetCursorInfo(&cursorInfo); POINT pt; pt.x=cursorX; pt.y=cursorY; ClientToScreen(hWnd,&pt); if(lock) { if(!(*locked)) { RECT rcClip; GetClientRect(hWnd, &rcClip); POINT rc0,rc1; rc0.x=rcClip.left; rc0.y=rcClip.top; rc1.x=rcClip.right; rc1.y=rcClip.bottom; ClientToScreen(hWnd,&rc0); ClientToScreen(hWnd,&rc1); rcClip.left=rc0.x; rcClip.top=rc0.y; rcClip.right=rc1.x; rcClip.bottom=rc1.y; ClipCursor(&rcClip); } *locked=true; if(cursorInfo.flags==CURSOR_SHOWING) { // pt=cursorInfo.ptScreenPos; ShowCursor(FALSE); } SetCursorPos(pt.x,pt.y); } else { if(cursorInfo.flags==0) { ShowCursor(TRUE); } if(*locked) { ClipCursor(0); } *locked=false; } }
BOOL CScreenCapture::CaptureScreenRect(RECT rcCapture, CString sSaveDirName, int nIdStartFrom, std::vector<CString>& out_file_list) { // Get cursor information GetCursorPos(&m_ptCursorPos); m_CursorInfo.cbSize = sizeof(CURSORINFO); GetCursorInfo(&m_CursorInfo); m_nIdStartFrom = nIdStartFrom; m_sSaveDirName = sSaveDirName; EnumDisplayMonitors(NULL, &rcCapture, EnumMonitorsProc, (LPARAM)this); out_file_list = m_out_file_list; return TRUE; }
static gboolean gst_gdiscreencapsrc_screen_capture (GstGDIScreenCapSrc * src, GstBuffer * buf) { HWND capture; HDC winDC; gint height, width; GstMapInfo map; if (G_UNLIKELY (!src->hBitmap || !src->dibMem)) return FALSE; width = src->info.bmiHeader.biWidth; height = -src->info.bmiHeader.biHeight; /* Capture screen */ capture = GetDesktopWindow (); winDC = GetWindowDC (capture); BitBlt (src->memDC, 0, 0, width, height, winDC, src->src_rect.left, src->src_rect.top, SRCCOPY); ReleaseDC (capture, winDC); /* Capture mouse cursor */ if (src->show_cursor) { CURSORINFO ci; ci.cbSize = sizeof (CURSORINFO); GetCursorInfo (&ci); if (ci.flags & CURSOR_SHOWING) { ICONINFO ii; GetIconInfo (ci.hCursor, &ii); DrawIconEx (src->memDC, ci.ptScreenPos.x - src->src_rect.left - ii.xHotspot, ci.ptScreenPos.y - src->src_rect.top - ii.yHotspot, ci.hCursor, 0, 0, 0, NULL, DI_DEFAULTSIZE | DI_NORMAL | DI_COMPAT); DeleteObject (ii.hbmColor); DeleteObject (ii.hbmMask); } } /* Copy DC bits to GST buffer */ gst_buffer_map (buf, &map, GST_MAP_WRITE); memcpy (map.data, src->dibMem, map.size); gst_buffer_unmap (buf, &map); return TRUE; }
bool Win32CursorController::isCursorVisible() { CURSORINFO rCursorInfo; rCursorInfo.cbSize = sizeof(CURSORINFO); if( !GetCursorInfo( &rCursorInfo ) ) { //DWORD error = GetLastError(); return false; } // rCursorInfo.flags values : // 0 == Cursor is hidden // CURSOR_SHOWING == cursor is visible return (bool)(rCursorInfo.flags == CURSOR_SHOWING); }
QWindowsCursor::CursorState QWindowsCursor::cursorState() { #ifndef Q_OS_WINCE enum { cursorShowing = 0x1, cursorSuppressed = 0x2 }; // Windows 8: CURSOR_SUPPRESSED CURSORINFO cursorInfo; cursorInfo.cbSize = sizeof(CURSORINFO); if (GetCursorInfo(&cursorInfo)) { if (cursorInfo.flags & CursorShowing) return CursorShowing; if (cursorInfo.flags & cursorSuppressed) return CursorSuppressed; } #endif // !Q_OS_WINCE return CursorHidden; }
bool CGestures::IsGesturesEnabled() { if (!_isTabletPC || !_isGestures) return false; // Финт ушами - считаем, что событие от мыши, если мышиный курсор // видим на экране. Если НЕ видим - то событие от тачскрина. Актуально // для того, чтобы различать правый клик от мышки и от тачскрина. CURSORINFO ci = {sizeof(ci)}; if (!GetCursorInfo(&ci)) return false; // 0 - курсор скрыт, а 2 - похоже недокументировано (тачскрин) if (ci.flags == 0 || ci.flags == 2) return true; _ASSERTE(ci.flags == CURSOR_SHOWING); return false; }
void cursor_pos_win32(HWND hWnd,int *x,int *y) { CURSORINFO cursorInfo; cursorInfo.cbSize=sizeof(CURSORINFO); GetCursorInfo(&cursorInfo); ScreenToClient(hWnd,&cursorInfo.ptScreenPos); RECT clientRect; GetClientRect(GetActiveWindow(),&clientRect); if(cursorInfo.ptScreenPos.x>clientRect.right || cursorInfo.ptScreenPos.y>clientRect.bottom) { *x=-1; *y=-1; } else { *x=(int)cursorInfo.ptScreenPos.x; *y=(int)cursorInfo.ptScreenPos.y; } }
BOOL CheckForHookCursor(HDC dc) { CURSORINFO cursorInfo = { 0 }; int i, j, b = WF_CursorHookBlack, w = WF_CursorHookWhite; cursorInfo.cbSize = sizeof(cursorInfo); if (GetCursorInfo(&cursorInfo)) { byte* bits[1000]; ICONINFO ii = {0}; POINT pp = cursorInfo.ptScreenPos; int p = GetIconInfo(cursorInfo.hCursor, &ii); int counter = 0, rv; HDC memDC = CreateCompatibleDC(dc); BITMAPINFO bmi; memset(&bmi, 0, sizeof(BITMAPINFO)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = 16; bmi.bmiHeader.biHeight = 16; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 0; bmi.bmiHeader.biXPelsPerMeter = 0; bmi.bmiHeader.biYPelsPerMeter = 0; bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biClrImportant = 0; GetDIBits(memDC, ii.hbmMask, 0, bmi.bmiHeader.biHeight, (void**)&bits, &bmi, DIB_RGB_COLORS); for (i=0;i<16;i++) for (j=0;j<16;j++) { DWORD c = (DWORD)BITMAPPixel(bmi, i, j, 16); if (c == 0x00) b--; else if (c = 0xFF) w--; } DeleteDC(memDC); if (w == 0 && b == 0) return TRUE; } return FALSE; }
//cursor display is reference counted (i.e. cursor is displayed if value >= 0) //so this function will only change the cursor state if required, avoiding //adding or removing extra references. void enableCursor(bool enable) { #ifdef _WIN32 CURSORINFO ci; ci.cbSize = sizeof(CURSORINFO); ci.flags = 0; ci.hCursor = 0; ci.ptScreenPos.x = 0; ci.ptScreenPos.y = 0; if ( GetCursorInfo(&ci) ) { const bool cursorShowing = (ci.flags&CURSOR_SHOWING)!=0; if (cursorShowing != enable) { ShowCursor(enable); } } #endif }
void MouseInputDevice::updateCurrValues_() { // Check if mouse is installed CURSORINFO info; info.cbSize = sizeof(CURSORINFO); if (!GetCursorInfo(&info)) return; updatePos_(); updateButtons_(); currAKeys_[MAB_WHEEL] = 0; if (Engine::getInstance()->GetIsEditorMode() && Input::GetTriggered(0, "ToggleMouse") == 1.0f) { Lock(false); Visible(true); } updateLock_(); updateVisiblility_(); }
QPixmap BleWindowsCaptureSource::cursorPixmap() { static HCURSOR cursor = NULL; static QPixmap cachedCursor = QPixmap(); QPixmap cursorPixmap; HICON icon; CURSORINFO cursorInfo; ICONINFO iconInfo; cursorInfo.cbSize = sizeof(CURSORINFO); if(GetCursorInfo(&cursorInfo)) { if (cursor == cursorInfo.hCursor) return cachedCursor; if (cursorInfo.flags == CURSOR_SHOWING) { icon = CopyIcon(cursorInfo.hCursor); if (GetIconInfo(icon, &iconInfo)) { if (iconInfo.hbmColor != NULL) { cursorPixmap = QtWin::fromHBITMAP(iconInfo.hbmColor, QtWin::HBitmapAlpha); } else if (iconInfo.hbmMask != NULL){//if the cursor hasn't color image (for example, Ibeam cursor) cursorPixmap = QtWin::fromHBITMAP(iconInfo.hbmMask, QtWin::HBitmapAlpha).mask(); //replace white color with transparent QImage cursorImage = cursorPixmap.copy(0, cursorPixmap.height() / 2, cursorPixmap.width(), cursorPixmap.height() / 2).toImage(); cursorImage.setColor(0, Qt::transparent); cursorPixmap = QPixmap::fromImage(cursorImage); } } } } cursor = cursorInfo.hCursor; cachedCursor = cursorPixmap; return cursorPixmap; }
void Win32Grabber::grabCursor(const Rect& rect, HDC hdc) { CURSORINFO cursorInfo = { 0 }; cursorInfo.cbSize = sizeof(CURSORINFO); if (GetCursorInfo(&cursorInfo)) { if (cursorInfo.flags == CURSOR_SHOWING) { ICONINFO iconInfo = { 0 }; GetIconInfo(cursorInfo.hCursor, &iconInfo); POINT pos; GetCursorPos(&pos); int x = pos.x - rect.x - iconInfo.xHotspot; int y = pos.y - rect.y - iconInfo.yHotspot; DrawIconEx(hdc, x, y, cursorInfo.hCursor, 0, 0, 0, NULL, DI_NORMAL | DI_DEFAULTSIZE); DeleteObject(iconInfo.hbmColor); DeleteObject(iconInfo.hbmMask); } } }
HBITMAP CopyScreenToBitmap(LPRECT lpRect, BYTE *pData, BITMAPINFO *pHeader, BOOL writeCursor) { HDC hScrDC, hMemDC; // screen DC and memory DC HBITMAP hBitmap, hOldBitmap; // handles to deice-dependent bitmaps int nX, nY, nX2, nY2; // coordinates of rectangle to grab int nWidth, nHeight; // DIB width and height int xScrn, yScrn; // screen resolution // check for an empty rectangle if (IsRectEmpty(lpRect)) return NULL; // create a DC for the screen and create // a memory DC compatible to screen DC hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); hMemDC = CreateCompatibleDC(hScrDC); // get points of rectangle to grab nX = lpRect->left; nY = lpRect->top; nX2 = lpRect->right; nY2 = lpRect->bottom; // get screen resolution xScrn = GetDeviceCaps(hScrDC, HORZRES); yScrn = GetDeviceCaps(hScrDC, VERTRES); //make sure bitmap rectangle is visible if (nX < 0) nX = 0; if (nY < 0) nY = 0; if (nX2 > xScrn) nX2 = xScrn; if (nY2 > yScrn) nY2 = yScrn; nWidth = nX2 - nX; nHeight = nY2 - nY; // create a bitmap compatible with the screen DC hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight); // select new bitmap into memory DC hOldBitmap = (HBITMAP) SelectObject(hMemDC, hBitmap); // bitblt screen DC to memory DC BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY); // write cursor to output bitmap if (writeCursor) { CURSORINFO pci; pci.cbSize = sizeof(CURSORINFO); if(GetCursorInfo(&pci)) { POINT point = pci.ptScreenPos; DrawIconEx(hMemDC, point.x, point.y, pci.hCursor, 0, 0, 0, NULL, DI_NORMAL); } } // select old bitmap back into memory DC and get handle to // bitmap of the screen hBitmap = (HBITMAP) SelectObject(hMemDC, hOldBitmap); // Copy the bitmap data into the provided BYTE buffer GetDIBits(hScrDC, hBitmap, 0, nHeight, pData, pHeader, DIB_RGB_COLORS); // clean up DeleteDC(hScrDC); DeleteDC(hMemDC); // return handle to the bitmap return hBitmap; }
void PollActivity() { #ifdef WIN32 LASTINPUTINFO lii; static POINT previous_pos = { 0, 0 }; static DWORD previous_input_tick = 0; lii.cbSize = sizeof(LASTINPUTINFO); lii.dwTime = 0; if ( !GetLastInputInfo(&lii) ) { dprintf(D_ALWAYS, "PollActivity: GetLastInputInfo()" " failed with err=%d\n", GetLastError()); } else { //Check if there has been new keyboard input since the last check. if(lii.dwTime > previous_input_tick) { previous_input_tick = lii.dwTime; update_startd(); } return; } //If no change to keyboard input, check if mouse has been moved. CURSORINFO cursor_inf; cursor_inf.cbSize = sizeof(CURSORINFO); if (!GetCursorInfo(&cursor_inf)) { dprintf(D_ALWAYS,"GetCursorInfo() failed (err=%li)\n", GetLastError()); } else { if ((cursor_inf.ptScreenPos.x != previous_pos.x) || (cursor_inf.ptScreenPos.y != previous_pos.y)) { // the mouse has moved! // stash new position previous_pos.x = cursor_inf.ptScreenPos.x; previous_pos.y = cursor_inf.ptScreenPos.y; previous_input_tick = GetTickCount(); update_startd(); } } return; #else if(xinter != NULL) { if(xinter->CheckActivity()) { update_startd(); } } #endif }
// Returns if the mouse cursor is showing. static bool IsMouseShowing() { CURSORINFO cursorInfo = {0}; cursorInfo.cbSize = sizeof(cursorInfo); GetCursorInfo(&cursorInfo); return cursorInfo.flags == CURSOR_SHOWING; }
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hDC; HICON hIcon; HGDIOBJ hOld; HDC hMemDC; CURSORINFO cursorinfo; ICONINFO iconinfo; BITMAP bmp; RECT rc; CHAR str[20]; switch(msg) { case WM_PAINT: hDC = BeginPaint(hWnd, &ps); SelectObject(hDC, tf); SetBkMode(hDC, TRANSPARENT); TextOut(hDC, 160, 10, file, strlen(file)); TextOut(hDC, 15, 85, titleDrwIco, strlen(titleDrwIco)); TextOut(hDC, 160, 85, titleMask, strlen(titleMask)); TextOut(hDC, 300, 85, titleXor, strlen(titleXor)); hIcon = LoadImage(NULL, "icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE); DrawIcon(hDC,50,50,hIcon); hMemDC = CreateCompatibleDC(hDC); GetIconInfo(hIcon, &iconinfo); DestroyIcon(hIcon); hOld = SelectObject(hMemDC, iconinfo.hbmMask); BitBlt(hDC, 200, 50, 32, 32, hMemDC, 0, 0, SRCCOPY); SelectObject(hMemDC, iconinfo.hbmColor); BitBlt(hDC, 350, 50, 32, 32, hMemDC, 0, 0, SRCCOPY); DeleteObject(iconinfo.hbmMask); DeleteObject(iconinfo.hbmColor); TextOut(hDC, 145, 150, res, strlen(res)); TextOut(hDC, 15, 225, titleDrwIco, strlen(titleDrwIco)); TextOut(hDC, 160, 225, titleMask, strlen(titleMask)); TextOut(hDC, 300, 225, titleXor, strlen(titleXor)); hIcon = LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE); DrawIcon(hDC,50,190,hIcon); GetIconInfo(hIcon, &iconinfo); DestroyIcon(hIcon); SelectObject(hMemDC, iconinfo.hbmMask); BitBlt(hDC, 200, 190, 32, 32, hMemDC, 0, 0, SRCCOPY); SelectObject(hMemDC, iconinfo.hbmColor); BitBlt(hDC, 350, 190, 32, 32, hMemDC, 0, 0, SRCCOPY); DeleteObject(iconinfo.hbmMask); DeleteObject(iconinfo.hbmColor); cursorinfo.cbSize = sizeof(CURSORINFO); if(GetCursorInfo(&cursorinfo)) { if(cursorinfo.hCursor && cursorinfo.flags) { TextOut(hDC, 160, 290, cursor, strlen(cursor)); DrawIcon(hDC, 50, 330, cursorinfo.hCursor); GetIconInfo(cursorinfo.hCursor, &iconinfo); TextOut(hDC, 15, 365, titleDrwIco, strlen(titleDrwIco)); sprintf(str, "Hotspot: %ld; %ld", iconinfo.xHotspot, iconinfo.yHotspot); TextOut(hDC, 15, 380, str, strlen(str)); if(iconinfo.hbmMask) { GetObjectW(iconinfo.hbmMask, sizeof(BITMAP), &bmp); SelectObject(hMemDC, iconinfo.hbmMask); BitBlt(hDC, 200, 330, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY); DeleteObject(iconinfo.hbmMask); TextOut(hDC, 160, 365 - 32 + bmp.bmHeight, cursormask, strlen(cursormask)); sprintf(str, "%dBPP", bmp.bmBitsPixel); TextOut(hDC, 160, 380 - 32 + bmp.bmHeight, str, strlen(str)); } if(iconinfo.hbmColor) { GetObjectW(iconinfo.hbmColor, sizeof(BITMAP), &bmp); SelectObject(hMemDC, iconinfo.hbmColor); BitBlt(hDC, 350, 330, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY); DeleteObject(iconinfo.hbmColor); TextOut(hDC, 300, 365 - 32 + bmp.bmHeight, cursorcolor, strlen(cursorcolor)); sprintf(str, "%dBPP", bmp.bmBitsPixel); TextOut(hDC, 300, 380 - 32 + bmp.bmHeight, str, strlen(str)); } } } SelectObject(hMemDC, hOld); DeleteObject(hMemDC); EndPaint(hWnd, &ps); break; case WM_TIMER: rc.left = 0; rc.top = 330; rc.right = 480; rc.bottom = 480; InvalidateRect(hWnd, &rc, TRUE); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0; }
void Draw(HDC aDc) { HDC desktopHdc = NULL; RECT sourceRect, intersectedRect; RECT targetRect, appRect; DWORD rop = SRCCOPY; CURSORINFO cinfo; ICONINFO iinfo; int AppWidth, AppHeight; if (bInvertColors) rop = NOTSRCCOPY; desktopHdc = GetDC(0); GetClientRect(hMainWnd, &appRect); AppWidth = (appRect.right - appRect.left); AppHeight = (appRect.bottom - appRect.top); ZeroMemory(&cinfo, sizeof(cinfo)); ZeroMemory(&iinfo, sizeof(iinfo)); cinfo.cbSize = sizeof(cinfo); GetCursorInfo(&cinfo); GetIconInfo(cinfo.hCursor, &iinfo); targetRect = appRect; ClientToScreen(hMainWnd, (POINT*)&targetRect.left); ClientToScreen(hMainWnd, (POINT*)&targetRect.right); if (bRecreateOffscreenDC || !hdcOffscreen) { bRecreateOffscreenDC = FALSE; if(hdcOffscreen) { SelectObject(hdcOffscreen, hbmpOld); DeleteObject (hbmpOffscreen); DeleteDC(hdcOffscreen); } sourceWidth = AppWidth / iZoom; sourceHeight = AppHeight / iZoom; /* Create a memory DC compatible with client area DC */ hdcOffscreen = CreateCompatibleDC(desktopHdc); /* Create a bitmap compatible with the client area DC */ hbmpOffscreen = CreateCompatibleBitmap( desktopHdc, sourceWidth, sourceHeight); /* Select our bitmap in memory DC and save the old one */ hbmpOld = SelectObject(hdcOffscreen , hbmpOffscreen); } GetWindowRect(hDesktopWindow, &sourceRect); sourceRect.left = (cp.x) - (sourceWidth /2); sourceRect.top = (cp.y) - (sourceHeight /2); sourceRect.right = sourceRect.left + sourceWidth; sourceRect.bottom = sourceRect.top + sourceHeight; GetBestOverlapWithMonitors(&sourceRect); /* Paint the screen bitmap to our in memory DC */ BitBlt( hdcOffscreen, 0, 0, sourceWidth, sourceHeight, desktopHdc, sourceRect.left, sourceRect.top, rop); if (IntersectRect(&intersectedRect, &sourceRect, &targetRect)) { OffsetRect(&intersectedRect, -sourceRect.left, -sourceRect.top); FillRect(hdcOffscreen, &intersectedRect, GetStockObject(DC_BRUSH)); } /* Draw the mouse pointer in the right position */ DrawIcon( hdcOffscreen , pMouse.x - iinfo.xHotspot - sourceRect.left, // - 10, pMouse.y - iinfo.yHotspot - sourceRect.top, // - 10, cinfo.hCursor); /* Blast the stretched image from memory DC to window DC */ StretchBlt( aDc, 0, 0, AppWidth, AppHeight, hdcOffscreen, 0, 0, sourceWidth, sourceHeight, SRCCOPY | NOMIRRORBITMAP); /* Cleanup */ if (iinfo.hbmMask) DeleteObject(iinfo.hbmMask); if (iinfo.hbmColor) DeleteObject(iinfo.hbmColor); ReleaseDC(hDesktopWindow, desktopHdc); }
void ScreenCapture::CustomFrame() { //nbase::NAutoLock auto_lock(&lock_); if (IsWindow(capture_hwnd_)) { // 把屏幕设备描述表拷贝到内存设备描述表中 HDC w_dc = GetDC(capture_hwnd_); if (w_dc) { RECT rcDlg; if (cut_screen_) { rcDlg = cut_rect_; } else { ::GetClientRect(capture_hwnd_, &rcDlg); } int width = rcDlg.right - rcDlg.left; int height = rcDlg.bottom - rcDlg.top; InitHBitmap(width, height); if (capture_bitmap_ == nullptr) { return; } HDC mem_dc = CreateCompatibleDC(w_dc); HBITMAP old_hbitmap = (HBITMAP)SelectObject(mem_dc, capture_bitmap_); //__int64 time0 = get_time_ms(); if (cut_screen_) { BitBlt(mem_dc, 0, 0, capture_width_, capture_height_, w_dc, cut_rect_.left, cut_rect_.top, SRCCOPY /*| CAPTUREBLT*/); } else { BitBlt(mem_dc, 0, 0, capture_width_, capture_height_, w_dc, 0, 0, SRCCOPY /*| CAPTUREBLT*/); } //__int64 time1 = get_time_ms(); //鼠标 if (1) { CURSORINFO pci; pci.cbSize = sizeof(CURSORINFO); GetCursorInfo(&pci); POINT ptCursor = pci.ptScreenPos; ICONINFO IconInfo = { 0 }; if (GetIconInfo(pci.hCursor, &IconInfo)) { ptCursor.x -= IconInfo.xHotspot; ptCursor.y -= IconInfo.yHotspot; if (NULL != IconInfo.hbmMask) DeleteObject(IconInfo.hbmMask); if (NULL != IconInfo.hbmColor) DeleteObject(IconInfo.hbmColor); } if (capture_hwnd_ != nullptr) { //RECT rcDlg; //::GetWindowRect(capture_hwnd_, &rcDlg); //ptCursor.x -= rcDlg.left; //ptCursor.y -= rcDlg.top; ScreenToClient(capture_hwnd_, &ptCursor); } if (cut_screen_) { ptCursor.x -= cut_rect_.left; ptCursor.y -= cut_rect_.top; } DrawIconEx(mem_dc, ptCursor.x, ptCursor.y, pci.hCursor, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT); } SelectObject(mem_dc, old_hbitmap); DeleteDC(mem_dc); ReleaseDC(capture_hwnd_, w_dc); timeb time_now; ftime(&time_now); // 秒数 __int64 cur_timestamp = time_now.time * 1000 + time_now.millitm; // 毫秒 int wxh = capture_width_ * capture_height_; frame_.AddVideoFrame(true, cur_timestamp, (const char*)capture_data_, wxh * 4, \ capture_width_, capture_height_, "", nim_comp::VideoFrameMng::Ft_ARGB_r); //VideoCaptureData(0, capture_data_, wxh * 4, capture_width_, capture_height_, "", nullptr); //static __int64 time_custom = get_time_ms(); //static int num_video = 0; //static __int64 time_bitblt = 0; //time_bitblt += time1 - time0; //num_video++; //__int64 time_cur = get_time_ms(); //if (time_cur > time_custom + 1000) //{ // time_custom += 1000; // if (time_cur > time_custom + 2000) // { // time_custom = time_cur; // } // _PRINT("custom video fps %d time %lld", num_video, time_bitblt/num_video); // num_video = 0; // time_bitblt = 0; //} } } }
bool MyWindow::run() { if(!justCreated) { sized=false; } justCreated=false; #ifdef WIN32 while(PeekMessage(&msg,NULL,0,0,PM_REMOVE) && msg.message!=WM_QUIT) { TranslateMessage(&msg); DispatchMessage(&msg); } if(msg.message==WM_QUIT) { //(int)msg.wParam; return false; } #endif #ifdef LINUX while(XPending(display)) { // Watch for new X events XNextEvent(display,&newEvent); switch(newEvent.type) { case UnmapNotify: break; case MapNotify: case ConfigureNotify: XGetWindowAttributes(display,win,&winData); clientHeight = winData.height; clientWidth = winData.width; sized=true; break; case MotionNotify: //rcx.nMousePosX = newEvent.xmotion.x; //rcx.nMousePosY = newEvent.xmotion.y; break; case KeyPress: if(newEvent.xkey.keycode==0x09) { return false; } break; case DestroyNotify: return false; } } #endif #ifdef WIN32 foreground=GetForegroundWindow()==hWnd; #endif if(!isFocused()) { inputCodeDown.clear(); } if(lockCursor && isFocused()) { #ifdef WIN32 RECT rect; GetWindowRect(hWnd,&rect); SetCursorPos((rect.right-rect.left)/2+rect.left,(rect.bottom-rect.top)/2+rect.top); // CURSORINFO cursorInfo; cursorInfo.cbSize=sizeof(CURSORINFO); if(GetCursorInfo(&cursorInfo) && cursorInfo.flags!=0) { ShowCursor(FALSE); } #endif #ifdef LINUX #endif } else { #ifdef WIN32 // CURSORINFO cursorInfo; cursorInfo.cbSize=sizeof(CURSORINFO); if(GetCursorInfo(&cursorInfo) && cursorInfo.flags==0) { ShowCursor(TRUE); } #endif #ifdef LINUX #endif } return true; }
void GraphicsCaptureSource::Render(const Vect2 &pos, const Vect2 &size) { if(capture) { Shader *lastShader = GetCurrentPixelShader(); float fGamma = float(-(gamma-100) + 100) * 0.01f; LoadPixelShader(drawShader); HANDLE hGamma = drawShader->GetParameterByName(TEXT("gamma")); if(hGamma) drawShader->SetFloat(hGamma, fGamma); //---------------------------------------------------------- // capture mouse bMouseCaptured = false; if(bCaptureMouse) { CURSORINFO ci; zero(&ci, sizeof(ci)); ci.cbSize = sizeof(ci); if(GetCursorInfo(&ci) && hwndCapture) { mcpy(&cursorPos, &ci.ptScreenPos, sizeof(cursorPos)); ScreenToClient(hwndCapture, &cursorPos); if(ci.flags & CURSOR_SHOWING) { if(ci.hCursor == hCurrentCursor) bMouseCaptured = true; else { HICON hIcon = CopyIcon(ci.hCursor); hCurrentCursor = ci.hCursor; delete cursorTexture; cursorTexture = NULL; if(hIcon) { ICONINFO ii; if(GetIconInfo(hIcon, &ii)) { xHotspot = int(ii.xHotspot); yHotspot = int(ii.yHotspot); UINT width, height; LPBYTE lpData = GetCursorData(hIcon, ii, width, height); if(lpData) { cursorTexture = CreateTexture(width, height, GS_BGRA, lpData, FALSE); if(cursorTexture) bMouseCaptured = true; Free(lpData); } DeleteObject(ii.hbmColor); DeleteObject(ii.hbmMask); } DestroyIcon(hIcon); } } } } } //---------------------------------------------------------- // game texture Texture *tex = capture->LockTexture(); Vect2 texPos = Vect2(0.0f, 0.0f); Vect2 texStretch = Vect2(1.0f, 1.0f); if(tex) { Vect2 texSize = Vect2(float(tex->Width()), float(tex->Height())); Vect2 totalSize = API->GetBaseSize(); Vect2 center = totalSize*0.5f; BlendFunction(GS_BLEND_ONE, GS_BLEND_ZERO); if(bStretch) { if(bIgnoreAspect) texStretch *= totalSize; else { float multiplyVal = (texSize.y * (totalSize.x / texSize.x) > totalSize.y) ? totalSize.y / texSize.y : multiplyVal = totalSize.x / texSize.x; texStretch *= texSize*multiplyVal; texPos = center-(texStretch*0.5f); } } else { texStretch *= texSize; texPos = center-(texStretch*0.5f); } Vect2 sizeAdjust = size/totalSize; texPos *= sizeAdjust; texPos += pos; texStretch *= sizeAdjust; RoundVect2(texPos); RoundVect2(texSize); if(bFlip) DrawSprite(tex, 0xFFFFFFFF, texPos.x, texPos.y+texStretch.y, texPos.x+texStretch.x, texPos.y); else DrawSprite(tex, 0xFFFFFFFF, texPos.x, texPos.y, texPos.x+texStretch.x, texPos.y+texStretch.y); capture->UnlockTexture(); BlendFunction(GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA); //---------------------------------------------------------- // draw mouse if(bMouseCaptured && cursorTexture && GetForegroundWindow() == hwndCapture) { Vect2 newCursorPos = Vect2(float(cursorPos.x-xHotspot), float(cursorPos.y-xHotspot)); Vect2 newCursorSize = Vect2(float(cursorTexture->Width()), float(cursorTexture->Height())); newCursorPos /= texSize; newCursorSize /= texSize; newCursorPos *= texStretch; newCursorPos += texPos; newCursorSize *= texStretch; bool bInvertCursor = false; if(invertShader) { if(bInvertCursor = ((GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0 || (GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0)) LoadPixelShader(invertShader); } DrawSprite(cursorTexture, 0xFFFFFFFF, newCursorPos.x, newCursorPos.y, newCursorPos.x+newCursorSize.x, newCursorPos.y+newCursorSize.y); } } if(lastShader) LoadPixelShader(lastShader); } }
static GstFlowReturn gst_dx9screencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf) { GstDX9ScreenCapSrc *src = GST_DX9SCREENCAPSRC (push_src); GstBuffer *new_buf; gint new_buf_size, i; gint width, height, stride; GstClock *clock; GstClockTime buf_time, buf_dur; D3DLOCKED_RECT locked_rect; LPBYTE p_dst, p_src; HRESULT hres; GstMapInfo map; guint64 frame_number; if (G_UNLIKELY (!src->d3d9_device)) { GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL), ("format wasn't negotiated before create function")); return GST_FLOW_NOT_NEGOTIATED; } clock = gst_element_get_clock (GST_ELEMENT (src)); if (clock != NULL) { GstClockTime time, base_time; /* Calculate sync time. */ time = gst_clock_get_time (clock); base_time = gst_element_get_base_time (GST_ELEMENT (src)); buf_time = time - base_time; if (src->rate_numerator) { frame_number = gst_util_uint64_scale (buf_time, src->rate_numerator, GST_SECOND * src->rate_denominator); } else { frame_number = -1; } } else { buf_time = GST_CLOCK_TIME_NONE; frame_number = -1; } if (frame_number != -1 && frame_number == src->frame_number) { GstClockID id; GstClockReturn ret; /* Need to wait for the next frame */ frame_number += 1; /* Figure out what the next frame time is */ buf_time = gst_util_uint64_scale (frame_number, src->rate_denominator * GST_SECOND, src->rate_numerator); id = gst_clock_new_single_shot_id (clock, buf_time + gst_element_get_base_time (GST_ELEMENT (src))); GST_OBJECT_LOCK (src); src->clock_id = id; GST_OBJECT_UNLOCK (src); GST_DEBUG_OBJECT (src, "Waiting for next frame time %" G_GUINT64_FORMAT, buf_time); ret = gst_clock_id_wait (id, NULL); GST_OBJECT_LOCK (src); gst_clock_id_unref (id); src->clock_id = NULL; if (ret == GST_CLOCK_UNSCHEDULED) { /* Got woken up by the unlock function */ GST_OBJECT_UNLOCK (src); return GST_FLOW_FLUSHING; } GST_OBJECT_UNLOCK (src); /* Duration is a complete 1/fps frame duration */ buf_dur = gst_util_uint64_scale_int (GST_SECOND, src->rate_denominator, src->rate_numerator); } else if (frame_number != -1) { GstClockTime next_buf_time; GST_DEBUG_OBJECT (src, "No need to wait for next frame time %" G_GUINT64_FORMAT " next frame = %" G_GINT64_FORMAT " prev = %" G_GINT64_FORMAT, buf_time, frame_number, src->frame_number); next_buf_time = gst_util_uint64_scale (frame_number + 1, src->rate_denominator * GST_SECOND, src->rate_numerator); /* Frame duration is from now until the next expected capture time */ buf_dur = next_buf_time - buf_time; } else { buf_dur = GST_CLOCK_TIME_NONE; } src->frame_number = frame_number; height = (src->src_rect.bottom - src->src_rect.top); width = (src->src_rect.right - src->src_rect.left); new_buf_size = width * 4 * height; GST_LOG_OBJECT (src, "creating buffer of %d bytes with %dx%d image", new_buf_size, width, height); /* Do screen capture and put it into buffer... * Aquire front buffer, and lock it */ hres = IDirect3DDevice9_GetFrontBufferData (src->d3d9_device, 0, src->surface); if (FAILED (hres)) { GST_DEBUG_OBJECT (src, "DirectX::GetBackBuffer failed."); return GST_FLOW_ERROR; } if (src->show_cursor) { CURSORINFO ci; ci.cbSize = sizeof (CURSORINFO); GetCursorInfo (&ci); if (ci.flags & CURSOR_SHOWING) { ICONINFO ii; HDC memDC; GetIconInfo (ci.hCursor, &ii); if (SUCCEEDED (IDirect3DSurface9_GetDC (src->surface, &memDC))) { HCURSOR cursor = CopyImage (ci.hCursor, IMAGE_CURSOR, 0, 0, LR_MONOCHROME | LR_DEFAULTSIZE); DrawIcon (memDC, ci.ptScreenPos.x - ii.xHotspot - src->monitor_info.rcMonitor.left, ci.ptScreenPos.y - ii.yHotspot - src->monitor_info.rcMonitor.top, cursor); DestroyCursor (cursor); IDirect3DSurface9_ReleaseDC (src->surface, memDC); } DeleteObject (ii.hbmColor); DeleteObject (ii.hbmMask); } } hres = IDirect3DSurface9_LockRect (src->surface, &locked_rect, &(src->src_rect), D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY); if (FAILED (hres)) { GST_DEBUG_OBJECT (src, "DirectX::LockRect failed."); return GST_FLOW_ERROR; } new_buf = gst_buffer_new_and_alloc (new_buf_size); gst_buffer_map (new_buf, &map, GST_MAP_WRITE); p_dst = (LPBYTE) map.data; p_src = (LPBYTE) locked_rect.pBits; stride = width * 4; for (i = 0; i < height; ++i) { memcpy (p_dst, p_src, stride); p_dst += stride; p_src += locked_rect.Pitch; } gst_buffer_unmap (new_buf, &map); /* Unlock copy of front buffer */ IDirect3DSurface9_UnlockRect (src->surface); GST_BUFFER_TIMESTAMP (new_buf) = buf_time; GST_BUFFER_DURATION (new_buf) = buf_dur; if (clock != NULL) gst_object_unref (clock); *buf = new_buf; return GST_FLOW_OK; }