|
-
December 20th, 2008, 05:10 PM
#1
[RESOLVED] STATIC control problems...
I am trying to create a screen shot of a window using C++ API.
I can capture the picture fine, i can save it, I can copy it to the clip board and paste it and it all works fine. But when I try to send it to a static control with SS_BITMAP style set it just shows a gray box.
I can also BitBlt it to the screen.
here is my code:
Code:
HWND wnd = FindWindow("Notepad", NULL);
char title[256];
GetWindowText(wnd, title, 256);
printf("Found window '%s'\n", title);
RECT wndRect;
GetClientRect(wnd, &wndRect);
HDC hSource = GetDC(wnd);
HDC hOut; HBITMAP bOut; //BITMAP iOut;
hOut = CreateCompatibleDC( GetDC(0) );
bOut = CreateCompatibleBitmap( GetDC(0), wndRect.right, wndRect.bottom);
//SelectObject(hOut, bOut);
typedef BOOL (_stdcall *tPrintWindow)( HWND, HDC,UINT);
tPrintWindow pPrintWindow =0;
HINSTANCE handle = ::GetModuleHandle("user32.dll");
if ( handle == 0 )
handle = ::LoadLibrary("User32.dll");
if (handle)
pPrintWindow = (tPrintWindow)::GetProcAddress(handle,"PrintWindow");
if( pPrintWindow)
pPrintWindow(wnd,hOut,0 );
SelectBitmap(hOut, bOut);
BitBlt(hOut, 0, 0, wndRect.right, wndRect.bottom, hSource, 0, 0, SRCCOPY);
HDC blah = GetDC(0);
BitBlt(blah, 0, 0, 100, 100, hOut, 0, 0, SRCCOPY);
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_BITMAP, bOut);
CloseClipboard();
CreateBMPFile((TCHAR*)"IHateWindows.bmp", CreateBitmapInfoStruct(bOut), bOut, hOut);
DeleteObject((HGDIOBJ)SendMessage(hPict,STM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)bOut));
printf("end");
Please, someone, Help.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|