CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 4 of 9 FirstFirst 1234567 ... LastLast
Results 46 to 60 of 132
  1. #46
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: Capture of Window

    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.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  2. #47
    Join Date
    May 2014
    Posts
    205

    Re: Capture of Window

    Would you be willing to help to fix the window of the program from which I need to copy pixels to react to the WM_CLIENTONLY message?

    header - mapview.h:
    http://paste.ofcode.org/ca4ENgugKLS8sRfTnc8G5K
    mapview.cpp:
    http://paste.ofcode.org/AfJ6RKdZEpUw7X262SMJRA

    On line 580 there is
    Code:
    LRESULT CALLBACK MapWndProc
    if this is the part where I should to look for.

    I could create new revision if you help me. I believe it should not be hard now when I have found the block of messages.
    Last edited by crazy boy; May 7th, 2014 at 01:39 PM.

  3. #48
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,397

    Re: Capture of Window

    Quote Originally Posted by crazy boy View Post
    Would you be willing to help to fix the window of the program from which I need to copy pixels to react to the WM_CLIENTONLY message?

    header - mapview.h:
    http://paste.ofcode.org/ca4ENgugKLS8sRfTnc8G5K
    mapview.cpp:
    http://paste.ofcode.org/AfJ6RKdZEpUw7X262SMJRA
    It would be better if you created a small test project reproducing your problem and posted it in a zip archive as an attachment.
    Victor Nijegorodov

  4. #49
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: Capture of Window

    On looking through your code, there is an awful lot of redundant code that is not required - ie you don't need the gdi library as you aren't doing anything with the result. The cut down version which does the same (with the same problem unfortunately) is
    Code:
    #include <windows.h>
    #include <cstdio>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
    //HWND HCapture = FindWindow(NULL, _T("Map Viewer") ); // get window handle
    HWND HCapture = GetForegroundWindow();
    
    	if (!IsWindow(HCapture))
    		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;
    	info.bmiHeader.biHeight        = dy;
    	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;
    	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;
    }
    Last edited by 2kaud; May 7th, 2014 at 02:21 PM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #50
    Join Date
    May 2014
    Posts
    205

    Re: Capture of Window

    Quote Originally Posted by VictorN View Post
    It would be better if you created a small test project reproducing your problem and posted it in a zip archive as an attachment.
    If you mean to take the AOKTS application and reduce it to the basic code, so no, I cannot do it, the project is too complex and hardly to separate one or two files. I can send you link to complete program but I guess this is not what you want and I don't think it is necessary. I think I need to add short code.

    Function
    Code:
    void HandleRefresh(HWND window, BOOL erase)
    Contains:
    Code:
    PaintMap(dc);
    maybe I could use it to draw to different window if I send message from another app? Hmm. Maybe not so simple. Inside, there is PaintUnits(data.copydc); which will draw units but not the terrain..

    But there must be some simple way how to fix the message to copy pixel from client area.

  6. #51
    Join Date
    May 2014
    Posts
    205

    Re: Capture of Window

    2kaud:
    Nice but I must check if the window exist or exist. Now for me is important to fix the application which should receive the message. I finished tonight. See you later. Thanks

  7. #52
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: Capture of Window

    Quote Originally Posted by VictorN View Post
    It would be better if you created a small test project reproducing your problem and posted it in a zip archive as an attachment.
    The code in my post #49 shows the problem when run from cmd. The expected image in the produced file shouldn't show the cmd title etc as PW_CLIENTONLY is specified for PrintWindow but does show.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #53
    Join Date
    May 2014
    Posts
    205

    Re: Receiving of messages

    What Window Process should I concentrate in?
    There is also CallWindowProc in main file aokts.cpp (application AOKTS itself). But I cannot find WindowProc() in the project. It mostlikely is not there. Create such process? In which code AOKTS of mapviewer?

  9. #54
    Join Date
    May 2014
    Posts
    205

    Re: Capture of Window

    Here is AOKTS 1.0.1 rev70 source code. Working for me on XP SP3
    http://sourceforge.net/projects/auto...g.zip/download
    I don't expect you will execute it but if you will, you need not to be worries. No harmful software, just application to edit game scenarios.

  10. #55
    Join Date
    May 2014
    Posts
    205

    Re: Capture of Window

    I'm reading GREAT article which explains how to do what I need. But I would like if you explain me few things. First he uses WndProc instead WindowProc. Are these fnc the same or is WindowProc just alias to WndProc?

    Then, when I will create WindowProc in the app where I want to receive the bitmap data, should I create it (or edit the existing one) in main source code aokts.cpp or in the module?

  11. #56
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: Capture of Window

    Quote Originally Posted by crazy boy View Post
    I'm reading GREAT article which explains how to do what I need. But I would like if you explain me few things. First he uses WndProc instead WindowProc. Are these fnc the same or is WindowProc just alias to WndProc?

    Then, when I will create WindowProc in the app where I want to receive the bitmap data, should I create it (or edit the existing one) in main source code aokts.cpp or in the module?
    Just post a link to the article so we can see the code.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  12. #57
    Join Date
    May 2014
    Posts
    205

    Re: Capture of Window

    It'll take time for me to read it and try it. But I have problem to make it working because it misses dome declarations. Will you help me to make the code working? I will create new thread for it.

  13. #58
    Join Date
    May 2014
    Posts
    205

    Re: Capture of Window

    I have created new tread devoting to the article and the program its author created. I have one or two question there because I don't understand how he processed the bitmap into Clipboard. I just see he sent the WM_PRINT message.
    http://forums.codeguru.com/showthrea..._PRINT-Message

  14. #59
    Join Date
    May 2014
    Posts
    205

    Re: Capture of Window

    I've tried to add WM_PRINT and WM_PRINTCLIENT into the AOKTS wndproc routine - in both rutines. One of aokts.cpp and one of mapview.cpp (the second should be right). I have added break points while debuging in VS C++ so if called by external app it should be paused just there. Then I called the program which I created in this thread as described on previous page. The image which I retrieve is still the same, but worse is that the VS did not break on the WNDPROC routine while the WM_PRINT should be called. What do I do wrong? I have no so much experience with debug yet. I wish I were on the right place in mapview.cpp, that would be much more simple if it were working

  15. #60
    Join Date
    May 2014
    Posts
    205

    Re: Capture of Window

    .............
    Last edited by crazy boy; May 9th, 2014 at 02:36 PM.

Page 4 of 9 FirstFirst 1234567 ... 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
  •  





Click Here to Expand Forum to Full Width

Featured