Capture of Window - Page 6
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 6 of 9 FirstFirst ... 3456789 LastLast
Results 76 to 90 of 130

Thread: Capture of Window

  1. #76
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,381

    Re: Capture of Window

    So does that mean that WM_PAINT does the same thing as WM_PRINT and WM_PRINTCLIENT?
    If the routines are coded as expected, the only difference between painting (WM_PAINT) and printing client area (WM_PRINTCLIENT) is the DC to be used - with painting requiring begin/end pair.

    The issue you can encouter is when the client area is updated outside of the WM_PAINT message (ie by updating a control etc) - but the client area shouldn't be directly written outside of the WM_PAINT message.
    Last edited by 2kaud; May 11th, 2014 at 11:54 AM.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  2. #77
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,381

    Re: Capture of Window

    Quote Originally Posted by crazy boy View Post
    Your statements are absurd. Should I read every book what everybody brings to mind? Are you mad? Are saying that I don't read responses? I did read all the references which were suggested to me on MSDN. You think that I will read all this stuff within few hours? Are you mad? I need time for this. Also I did my best to make my post or codes readable.




    Even if I would read those books, I would come here again and ask about how to make that example codes working.

    I don't learn from forums! I learn from MSDN and other internet sources! Don't say that I learn here. I needed to explain some little pieces which I read or have found when I tried to make some codes working or better to understand. The stuff which I learned could not be written on 1000 pages of this forum! So your statement is not true. I just need some clue and that is all.



    Why you waste your time reading my posts and writing? Are you bored? You must be very much bored! If I would want a book to read, I would find some. I don't need you to tell me which book to buy. I did not ask you "What book is best for learning C++?" If I would want to buy a book I can go to internet or to go to bookshop rather. Conclusion: your post are useless, have not bring anything good for me. But the other guys who written here did some good. They helped me to fix some bug, which I appreciate and they can have good feeling of help others. Whilst you are bored and teasing and really wasting your time. You even spent much more time than you would do if you would answer my simple question. This is just clear unwillingness to help. My final word to this is that I already have found a big benefit of what I learned during last week! But am not planning to buy book because I don't have so much time to read it. My time is limited. It really priceless trying to make me to read book.
    Yes I use books but only when I look for something in the moment, I don't reed them completley. I would not have time for this it would taken years for me to complete. PLS don't waste your time in this topic. Don't slam your head against wall of bricks, you cannot break it.
    Loose the attitude. Members replying to your request for guidance are trying to provide the best advice they can based upon their extensive knowledge and years of experience.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #78
    Join Date
    May 2014
    Posts
    149

    Re: Capture of Window

    I debuged the code mention on the other thread referenced before. I tried to copy window from the application which I called Learning WinAPI. It uses WindowProc and it is just very basic window containing yellow ellipse on the client area. I use to send every message on Output. When I start the program which copies the Window Learning WinAPI, then I got the bitmap and these messages:
    15 ... WM_PAINT
    133 ... WM_NCPAINT
    13 ... WM_GETTEXT
    But No WM_PRINTCLIENT ...

    One more test (messages going through the WindowProc when I call PrintWindow from external app):
    ... 15 WM_PAINT hWnd:0x004304d8 {unused=??? } WPARAM:0, LPARAM 0
    ... 133 WM_NCPAINT hWnd:0x004304d8 {unused=??? } WPARAM:1, LPARAM 0
    ... 13 WM_GETTEXT hWnd:0x004304d8 {unused=??? } WPARAM:255, LPARAM 1241800
    ... 20 WM_INPUT hWnd:0x004304d8 {unused=??? } WPARAM:16842836, LPARAM 0
    ... 136 WM_SYNCPAINT hWnd:0x004304d8 {unused=??? } WPARAM:4, LPARAM 0

    The code WindowProc is according this article:
    http://www.fengyuan.com/article/wmprint.html
    More about my testing project is in the thread here:
    http://forums.codeguru.com/showthrea..._PRINT-Message
    Last edited by crazy boy; May 11th, 2014 at 02:00 PM.

  4. #79
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,295

    Re: Capture of Window

    For folks that answer questions, we often run across posters where it's like pulling teeth to extract information from them or to get them to try things. Sometimes it seems like we're talking to a wall.
    Quote Originally Posted by crazy boy View Post
    Don't slam your head against wall of bricks, you cannot break it.
    Wouldn't you know, my suspicions are confirmed.

  5. #80
    Join Date
    May 2014
    Posts
    149

    Re: Capture of Window

    Quote Originally Posted by Arjay View Post
    For folks that answer questions, we often run across posters where it's like pulling teeth to extract information from them or to get them to try things.
    Though your best will to sell me books I still prefer this MSDN article about Windows messages:
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

  6. #81
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,381

    Re: Capture of Window

    Quote Originally Posted by 2kaud View Post
    See http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx for info about the PrintWindow() api. It simply sends either a WM_PAINT or a WM_PRINTCLIENT message to the specified window.

    From Remarks
    "The application that owns the window referenced by hWnd processes the PrintWindow call and renders the image in the device context that is referenced by hdcBlt. The application receives a WM_PRINT message or, if the PW_CLIENTONLY flag is specified, a WM_PRINTCLIENT message. For more information, see WM_PRINT and WM_PRINTCLIENT".

    So what PrintWindow() actually does is controlled entirely by how the target program handles the WM_PRINTCLIENT message. The target proram might just treat WM_PRINTCLIENT message the same as the WM_PRINT message.
    MSDN speaks with forked tongue! I've run some tests and the window referenced by PrintWindow doesn't receive either WM_PRINT or WM_PRINTCLIENT! It receives WM_PAINT, WM_NCPAINT and WM_ERASEBACKGROUND in that order. Doh!!!! So if you don't want to capture the non-client areas you need to process the WM_NCPAINT message and ignore if doing a client capture. So in WM_PRINTCLIENT I simply toggle a bool and test in WM_NCPAINT. In the capture program send a WM_PRINTCLIENT message before and after PrintWindow(). I know it's a bit of kludge but I think it will give you something near what you want. Unless any other guru knows better?

    This is a revised client capture code
    Code:
    #include <windows.h>
    #include <cstdio>
    #include <fstream>
    #include <iostream>
    
    using namespace std;
    
    const int fudgey = GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYSIZEFRAME);
    const int fudgex = 0;
    
    int main()
    {
    HWND HCapture = FindWindow(NULL, "wintest"); // get window handle
    //HWND HCapture = GetForegroundWindow();
    
    	if (!IsWindow(HCapture)) {
    		cout << "Cannot find window\n";
    		return 1;
    	}
    
    RECT rect; 
    
    	GetClientRect(HCapture, &rect);
    
    LONG dx = rect.right - rect.left;
    LONG dy = rect.bottom - rect.top;
    
    // create BITMAPINFO structure
    // used by CreateDIBSection
    BITMAPINFO info = {0};
    
    	info.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
    	info.bmiHeader.biWidth         = dx + fudgex;
    	info.bmiHeader.biHeight        = dy + fudgey;
    	info.bmiHeader.biPlanes        = 1;
    	info.bmiHeader.biBitCount      = 24;
    	info.bmiHeader.biCompression   = BI_RGB;
    
    HDC	HDevice = CreateCompatibleDC(NULL);
    //HDC HDevice = GetDC(HCapture);
     
    BYTE*	memory = 0;
     
    HBITMAP	HBitmap = CreateDIBSection(HDevice, &info, DIB_RGB_COLORS, (void**)&memory, NULL, NULL);
    
    	SelectObject(HDevice, HBitmap);
     
    	SendMessage(HCapture, WM_PRINTCLIENT, 0, 0);
    	if (!PrintWindow(HCapture, HDevice, /*PW_CLIENTONLY*/0))
    		return 2;
    
    	SendMessage(HCapture, WM_PRINTCLIENT, 0, 0);
    
    	ReleaseDC(HCapture, HDevice);
    
    char *buffer = new char[50];
    
    	sprintf(buffer, "capture%d%d.bmp", dx, dy);
    
    ofstream file(buffer, ios::binary);
    
    	if (!file) {
    		DeleteObject(HBitmap);
    		return 1;
    	}
    
    // initialize bitmap file headers
    BITMAPFILEHEADER fileHeader = {0};
    BITMAPINFOHEADER infoHeader = {0};
    
    	fileHeader.bfType      = 0x4d42;
    	fileHeader.bfSize      = 0; //????
    	fileHeader.bfOffBits   = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
    
    	infoHeader.biSize          = sizeof(infoHeader);
    	infoHeader.biWidth         = dx + fudgex;
    	infoHeader.biHeight        = dy;
    	infoHeader.biPlanes        = 1;
    	infoHeader.biBitCount      = 24;
    	infoHeader.biCompression   = BI_RGB;
    
    	// save file headers
    	file.write((char*)&fileHeader, sizeof(fileHeader));
    	file.write((char*)&infoHeader, sizeof(infoHeader));
    
    // save 24-bit bitmap data
    int wbytes = (((24 * (dx) + 31) & (~31)) / 8);
    int tbytes = wbytes * dy;
    
    	file.write((char*)(memory), tbytes);
    	file.close();
    
    	// delete bitmap
    	DeleteObject(HBitmap);
    	return 0;
    }
    PrintWindow() produces a band across the top of the image if WM_NCPAINT is not called which is what fuedgey and fudgex are used for - to try to get rid of this unwanted band across the top.

    And this is revised kludge code for the window that is to be captured
    Code:
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    static bool client = false;
    ....
    	switch (message) {
    ....
    		case WM_PAINT:
    			{
    				HDC hDC = BeginPaint(hWnd, &ps);
    				RECT rt;
    				GetClientRect(hWnd, &rt);
    				SelectObject(hDC, GetSysColorBrush(COLOR_INFOBK));
    				Ellipse(hDC, rt.left+5, rt.top+5, rt.right-3, rt.bottom-5);
    				EndPaint(hWnd, &ps);
    			}
    			break;
    
    		case WM_PRINTCLIENT:
    			client = !client;
    			break;
    
    		case WM_NCPAINT:
    			return (client) ? 0 : DefWindowProc(hWnd, message, wParam, lParam);
    This seems to work on my system using the ellipse draw as a test.

    Have fun!
    Last edited by 2kaud; May 11th, 2014 at 04:23 PM.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  7. #82
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,381

    Re: Capture of Window

    Doh! There's no need to fudge the referenced window. Just alter the capture window program to get rid of so much of the top of the image as required.

    Code:
    #include <windows.h>
    #include <cstdio>
    #include <fstream>
    #include <iostream>
    
    using namespace std;
    
    //Uncomment this line if the window to be captured has a menu
    #define GOT_MENU
    
    //For a normal window that has a menu
    #ifdef GOT_MENU
    const int fudgey = GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYMENU);
    #else
    //For a window that doesn't have a menu
    const int fudgey = GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYSIZEFRAME);
    #endif
    
    
    const int fudgex = 0;
    
    int main()
    {
    
    HWND HCapture = FindWindow(NULL, "wintest"); // get window handle
    //HWND HCapture = GetForegroundWindow();   //captures cmd window
    
    	if (!IsWindow(HCapture)) {
    		cout << "Cannot find window\n";
    		return 1;
    	}
    
    RECT rect; 
    
    	GetClientRect(HCapture, &rect);
    
    LONG dx = rect.right - rect.left;
    LONG dy = rect.bottom - rect.top;
    
    // create BITMAPINFO structure
    // used by CreateDIBSection
    BITMAPINFO info = {0};
    
    	info.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
    	info.bmiHeader.biWidth         = dx + fudgex;
    	info.bmiHeader.biHeight        = dy + fudgey;
    	info.bmiHeader.biPlanes        = 1;
    	info.bmiHeader.biBitCount      = 24;
    	info.bmiHeader.biCompression   = BI_RGB;
    
    HDC	HDevice = CreateCompatibleDC(NULL);
     
    BYTE*	memory = 0;
     
    HBITMAP	HBitmap = CreateDIBSection(HDevice, &info, DIB_RGB_COLORS, (void**)&memory, NULL, NULL);
    
    	SelectObject(HDevice, HBitmap);
     
    	if (!PrintWindow(HCapture, HDevice, /*PW_CLIENTONLY*/0))
    		return 2;
    
    	ReleaseDC(HCapture, HDevice);
    
    char *buffer = new char[50];
    
    	sprintf(buffer, "capture%d%d.bmp", dx, dy);
    
    ofstream file(buffer, ios::binary);
    
    	if (!file) {
    		DeleteObject(HBitmap);
    		return 1;
    	}
    
    // initialize bitmap file headers
    BITMAPFILEHEADER fileHeader = {0};
    BITMAPINFOHEADER infoHeader = {0};
    
    	fileHeader.bfType      = 0x4d42;
    	fileHeader.bfSize      = 0; //????
    	fileHeader.bfOffBits   = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
    
    	infoHeader.biSize          = sizeof(infoHeader);
    	infoHeader.biWidth         = dx + fudgex;
    	infoHeader.biHeight        = dy;
    	infoHeader.biPlanes        = 1;
    	infoHeader.biBitCount      = 24;
    	infoHeader.biCompression   = BI_RGB;
    
    	// save file headers
    	file.write((char*)&fileHeader, sizeof(fileHeader));
    	file.write((char*)&infoHeader, sizeof(infoHeader));
    
    // save 24-bit bitmap data
    int wbytes = (((24 * (dx) + 31) & (~31)) / 8);
    int tbytes = wbytes * dy;
    
    	file.write((char*)(memory), tbytes);
    	file.close();
    
    	// delete bitmap
    	DeleteObject(HBitmap);
    	return 0;
    }
    Have a play with this and see how it goes.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  8. #83
    Join Date
    May 2014
    Posts
    149

    Re: Capture of Window

    THX. MSDN: WM_NCPAINT:
    "An application can intercept the WM_NCPAINT message and paint its own custom window frame. The clipping region for a window is always rectangular, even if the shape of the frame is altered."
    What they mean by the word frame? Do they mean in general? Or do they mean complete window or client area?
    Last edited by crazy boy; May 12th, 2014 at 03:31 AM.

  9. #84
    Join Date
    May 2014
    Posts
    149

    Re: Capture of Window

    I tested your program with AOK Trigger Studio (no scenario loaded) and this look like it could fit (not sure if exactly).
    But then I have tested Map Viewer destination and there is mistake for top edge y=+3 pixels. So y needs to reduce for 3px. I need to have correct calculation for the top and left edge of the client area to capture. If there would be one pixel mistake, then I cannot do correct calculation of size of the map.

    Note: there is no menu in Map Viewer, while in AOK Trigger Studio window, there is.

    According MSDN:
    SM_CYSIZE ... 31: The height of a button in a window caption or title bar, in pixels.
    Which button? The "x" button?



    GetClientRect returns exact coords, so why do you calculate:
    Code:
    LONG dx = rect.right - rect.left;
    LONG dy = rect.bottom - rect.top;
    which is
    Code:
    LONG dx = 335 - 0;
    LONG dy = 352 - 0;
    Looks like non sense.

    How do you tell to system where it should get the top y and left x? How does it know where to start?
    I thought it knows only where is the top left coord of client Area (GetClientRect) but it does not know where to start to capture. info.bmiHeader contains only size not the begining top left corner ...
    What I did in the following test is to change your calculation in the directive block. And I partially succeeded to change the starting position / top left corner. But I have no idea how this is possible and works for y only.

    * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


    When I correct:
    Code:
    const int fudgey = GetSystemMetrics(SM_CYSIZE) ;
    So I have better result y top edge =-1px . But maybe this is it ... the 1px line at top may be in client area (I dont know if is it Client area). The left side is not OK. It seems to have +4 px bigger (are those 4 px the SM_CYSIZEFRAME?)



    Bottom and Right edge is approximately OK.

    * * * *
    I have also found where the map data are saved in the application AOK Trigger Studio, in mapview.cpp module:

    There is height of map and handle of status bar. So could I make some changes to the program to send information to my capture program? I unfortunately don't know yet how do realize such communication between two windows. What kind of message could I send to MapViewer to handle it to send the map information? If this is realizable, it would be great because I could get exact info how to clip it.

    Or another possibility is to send message which will ask MapViewer to copy pixels to the context of capture.exe.
    That seems to me as the most simple and 100% accurate solution. Of sure in the case that I would know what kind of message to send to MapViewer. Would it be possible to call something like
    SendMessage(HCapture, SC_MINIMIZE, HDevice, 0); without retrieving error cannot convert parameter 3 from 'HDC' to 'WPARAM' ? Since the window doe not have Minimize nor Maximize buttons it would be message to copy bitmap.

    Last edited by crazy boy; May 12th, 2014 at 07:07 AM.

  10. #85
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,381

    Re: Capture of Window

    PrintWindow() is not going to provide the output you're looking for (unless some other guru knows different?). Therefore to get something like what you are after, the image produced by PrintWindow() will need to be adjusted. This adjustment are the 'fudge' variables I introduced into the capture code to 'manipulate' the data provided by PrintWindow() to try to get the required output. If the output is not exactly as required, then try adjusting the values of these variables (and also look at where dx and dy are used throughout the code) to see if the output can be adjusted further to what is requried. This will largely be a 'try it and see' ie a fudge. I don't like this but unless some other guru knows better I don't know of another way of doing this with PrintWindow().

    I've slightly changed the code that gives the fudegy value so that you don't have to re-compile depending upon whether the target has a menu or not - it trys to compute the fudge factor based upon the overall window and client sizes.

    Have even more fun!

    Code:
    #include <windows.h>
    #include <cstdio>
    #include <fstream>
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    HWND HCapture = FindWindow(NULL, "wintest"); // get window handle
    //HWND HCapture = GetForegroundWindow();   //captures cmd window
    
    	if (!IsWindow(HCapture)) {
    		cout << "Cannot find window\n";
    		return 1;
    	}
    
    RECT rect, rectw; 
    
    	GetClientRect(HCapture, &rect);
    	GetWindowRect(HCapture, &rectw);
    
    LONG dx = rect.right - rect.left;
    LONG dy = rect.bottom - rect.top;
    
    const int fudgey = (rectw.bottom - rectw.top) - dy - 2 * GetSystemMetrics(SM_CYSIZEFRAME);
    const int fudgex = 0;
    
    // create BITMAPINFO structure
    // used by CreateDIBSection
    BITMAPINFO info = {0};
    
    	info.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
    	info.bmiHeader.biWidth         = dx + fudgex;
    	info.bmiHeader.biHeight        = dy + fudgey;
    	info.bmiHeader.biPlanes        = 1;
    	info.bmiHeader.biBitCount      = 24;
    	info.bmiHeader.biCompression   = BI_RGB;
    
    HDC	HDevice = CreateCompatibleDC(NULL);
     
    BYTE*	memory = 0;
     
    HBITMAP	HBitmap = CreateDIBSection(HDevice, &info, DIB_RGB_COLORS, (void**)&memory, NULL, NULL);
    
    	SelectObject(HDevice, HBitmap);
     
    	if (!PrintWindow(HCapture, HDevice, /*PW_CLIENTONLY*/0))
    		return 2;
    
    	ReleaseDC(HCapture, HDevice);
    
    char *buffer = new char[50];
    
    	sprintf(buffer, "capture%d%d.bmp", dx, dy);
    
    ofstream file(buffer, ios::binary);
    
    	if (!file) {
    		DeleteObject(HBitmap);
    		return 1;
    	}
    
    // initialize bitmap file headers
    BITMAPFILEHEADER fileHeader = {0};
    BITMAPINFOHEADER infoHeader = {0};
    
    	fileHeader.bfType      = 0x4d42;
    	fileHeader.bfSize      = 0; //????
    	fileHeader.bfOffBits   = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
    
    	infoHeader.biSize          = sizeof(infoHeader);
    	infoHeader.biWidth         = dx + fudgex;
    	infoHeader.biHeight        = dy;
    	infoHeader.biPlanes        = 1;
    	infoHeader.biBitCount      = 24;
    	infoHeader.biCompression   = BI_RGB;
    
    	// save file headers
    	file.write((char*)&fileHeader, sizeof(fileHeader));
    	file.write((char*)&infoHeader, sizeof(infoHeader));
    
    // save 24-bit bitmap data
    int wbytes = (((24 * (dx) + 31) & (~31)) / 8);
    int tbytes = wbytes * dy;
    
    	file.write((char*)(memory), tbytes);
    	file.close();
    
    	// delete bitmap
    	DeleteObject(HBitmap);
    	return 0;
    }
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  11. #86
    Join Date
    May 2014
    Posts
    149

    Re: Capture of Window

    Anyway, I am in great temptation. I believe there must be much more simple and more accurate way using less code on the side of capturing program. All I need: which message can I use to send to the Map Viewer the handler of DC? I can receive SC_MINIMIZE but this one cannot bring the HDC handle in wparam or lparam. So I need to get the HDC into the message. Is that possible?
    Last edited by crazy boy; May 12th, 2014 at 07:47 AM.

  12. #87
    Join Date
    May 2014
    Posts
    149

    Re: Capture of Window

    Just for fun:
    Code:
    if (!PrintWindow(hWnd, (HDC) wParam, (UINT) lParam)) return 2;
    In the destination program. Produces black bitmap.
    Last edited by crazy boy; May 12th, 2014 at 11:19 AM.

  13. #88
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,381

    Re: Capture of Window

    lParam is not of type UINT and wparam is not of type HDC. To get it to compile try
    Code:
    case WM_PRINTCLIENT:
            if (!PrintWindow(hWnd, (HDC)wParam, (UINT)lParam)) return 2;
    		
    		// SendMessage(hWnd, WM_PAINT, wParam, lParam);
        break;
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  14. #89
    Join Date
    May 2014
    Posts
    149

    Re: Capture of Window

    I'm just trying if it were possible to capture the content of "Learnning WinAPI" by sending WM_PRINTCLIENT from capture.cpp. I created function based on the aokts:
    Code:
    void HandlePaint(HWND window, HDC hDC2)
    {
    	HDC dc;
    	PAINTSTRUCT ps;
    //	SCROLLINFO si;
    
    	if (GetUpdateRect(window, NULL, FALSE))
    	{
    		dc = BeginPaint(window, &ps);
    		//si.cbSize = sizeof(si);
    		//si.fMask = SIF_POS;
    
    		//GetScrollInfo(window, SB_HORZ, &si);
    		//data.offsetx = (data.scrollMaxX > 0) ? -si.nPos : 0;
    		//GetScrollInfo(window, SB_VERT, &si);
    		//data.offsety = (data.scrollMaxY > 0) ? -si.nPos : 0;
    
    		// SelectObject(dc, hDC);
    		BitBlt(hDC2, 0, 0, 255, 255,
    			hDC, 0, 0, SRCCOPY);
    		EndPaint(window, &ps);
    	}
    }
    Handling:
    Code:
        case WM_PRINTCLIENT:
            if (HandlePaint(hWnd,(HDC) wParam)) return 2;
      break;
    Produces error:
    error C2451: conditional expression of type 'void' is illegal
    Expressions of type void cannot be converted to other types

    ???

    I'd like to copy the client area.

    Note:
    hDC is global and should keep drawings.
    Last edited by crazy boy; May 12th, 2014 at 11:47 AM.

  15. #90
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,295

    Re: Capture of Window

    Quote Originally Posted by crazy boy View Post
    I'm just trying if it were possible to capture the content of "Learnning WinAPI" by sending WM_PRINTCLIENT from capture.cpp. I created function based on the aokts:
    Code:
    void HandlePaint(HWND window, HDC hDC2)
    {
    	HDC dc;
    	PAINTSTRUCT ps;
    //	SCROLLINFO si;
    
    	if (GetUpdateRect(window, NULL, FALSE))
    	{
    		dc = BeginPaint(window, &ps);
    		//si.cbSize = sizeof(si);
    		//si.fMask = SIF_POS;
    
    		//GetScrollInfo(window, SB_HORZ, &si);
    		//data.offsetx = (data.scrollMaxX > 0) ? -si.nPos : 0;
    		//GetScrollInfo(window, SB_VERT, &si);
    		//data.offsety = (data.scrollMaxY > 0) ? -si.nPos : 0;
    
    		// SelectObject(dc, hDC);
    		BitBlt(hDC2, 0, 0, 255, 255,
    			hDC, 0, 0, SRCCOPY);
    		EndPaint(window, &ps);
    	}
    }
    Handling:
    Code:
        case WM_PRINTCLIENT:
            if (HandlePaint(hWnd,(HDC) wParam)) return 2;
      break;
    Produces error:
    error C2451: conditional expression of type 'void' is illegal
    Expressions of type void cannot be converted to other types

    ???

    I'd like to copy the client area.
    See red highlight.

Page 6 of 9 FirstFirst ... 3456789 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center