c++ - Include mouse cursor in screen capture -
c++ - Include mouse cursor in screen capture -
i utilize createdc / bitblt / getdibits etc. capture screen, cursor not captured. there simple argument or have included?
further give-and-take occurred in comments, had chance farther investigate question. result, came next code grab current cursor's hbitmap , draw screen.
since cursor is hicon, comes mask. initially, did simple bitblt - however, got 32x32 black sqaure cursor in top left 1/4 or so.
i investigated using maskblt. depending on cursor when app started, either wait cursor, ns resize cursor, or standard pointer. guess start timer , add together wm_timer handler fire couple of times sec in order real-time update of cursor used in other windows in system. seemed mere curiosity didn't bother.
edit: did start timer in wm_initdialog , handle in wm_timer. can see image updated 10 times second. reason, i-beam cursor doesn't seem displayed @ - case farther investigation needed, guess.
here's finish listing (except resource.rc , resource.h - create dialog app , create sure dialog's resource id used within main in phone call dialogbox)
#include <windows.h> #include <commctrl.h> #include <stdio.h> #include "resource.h" hinstance hinst; hbitmap getcursorhbitmap(hbitmap *maskbmp) { cursorinfo pci; iconinfo iconinfo; hbitmap result; pci.cbsize = sizeof(pci); getcursorinfo(&pci); if (geticoninfo(pci.hcursor,&iconinfo)) { result = iconinfo.hbmcolor; if (maskbmp) *maskbmp = iconinfo.hbmmask; } else result = null; homecoming result; } bool callback dlgmain(hwnd hwnddlg, uint umsg, wparam wparam, lparam lparam) { switch(umsg) { case wm_initdialog: { settimer(hwnddlg, 1, 100, null); } homecoming true; case wm_timer: { invalidaterect(hwnddlg, null, true); } homecoming 0; case wm_erasebkgnd: { hdc hdc = (hdc)wparam; rect mrect; getclientrect(hwnddlg, &mrect); fillrect(hdc, &mrect, (hbrush)getstockobject(gray_brush)); } homecoming 1; case wm_paint: { hbitmap oldbm, cursorbmp, maskbmp; cursorbmp = getcursorhbitmap(&maskbmp); if (cursorbmp) { hdc hdc; paintstruct ps; hdc memdc; bitmap bm; hdc = beginpaint(hwnddlg, &ps); memdc = createcompatibledc(hdc); oldbm = (hbitmap) selectobject(memdc, cursorbmp); getobject(cursorbmp, sizeof(bm), &bm); // printf("cursor size: %d x %d\n", bm.bmwidth, bm.bmheight); // bitblt(hdc, 10,10, 32,32, memdc, 0,0, srccopy); maskblt(hdc, 10,10, bm.bmwidth, bm.bmheight, memdc, 0,0, maskbmp, 0,0, makerop4(srcpaint,srccopy) ); selectobject(memdc, oldbm); deletedc(memdc); endpaint(hwnddlg, &ps); } } homecoming 0; case wm_close: { enddialog(hwnddlg, 0); } homecoming true; case wm_command: { switch(loword(wparam)) { } } homecoming true; } homecoming false; } int apientry winmain(hinstance hinstance, hinstance hprevinstance, lpstr lpcmdline, int nshowcmd) { hinst=hinstance; initcommoncontrols(); homecoming dialogbox(hinst, makeintresource(dlg_main), null, (dlgproc)dlgmain); }
c++ c screenshot screen-capture
Comments
Post a Comment