{
HDC dc;
PAINTSTRUCT ps;
RECT rect;
if (GetUpdateRect(window, &rect, FALSE))
{
dc = BeginPaint(window, &ps);
BitBlt(hDC2, 0, 0, 255, 255,
hDC, 0, 0, SRCCOPY);
EndPaint(window, &ps);
}
}
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!
No light on the end of tunnel.
I found out, that I overlooked your code you gave me to test capturing was two parts. However when I run it now again with the second part implemented in "Learning WinAPI" still not correct size. I would appreciate some correction to the code
Since I am never sure about the title. I still change between programs and doing mistakes in case while retyping. Is it possible to find window case insensitive and beginning just "learn"? But I wonder that the last bitmap was made when I have incorrect case. Should be "Learning WinAPI".
Since I am never sure about the title. I still change between programs and doing mistakes in case while retyping. Is it possible to find window case insensitive and beginning just "learn"?
Yes, but it's not as simple as just using FindWindow(). You need to enumerate the top level windows which will give a handle to the next desktop window and then obtain the window title and then see if the title matches using the required criteria. It uses a callback function that is called for each top level window.
I'll knock something up along these lines and post.
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!
This will use the first window found that contains the text set for wndtitle irrespective of case. If more than one window would match wndtitle, the first one found is used.
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!
Yes it was originally, but see my post #82 and #85. I moved away from any changes to the program producing the window to be captured. The code in #96 doesn't require any changes to the window producing program. The other program was simply a test program to produce a window containg an eclipse that could be captured This had a title of wintest - hence the use of wintest in the FindWindow().
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!
Originally Posted by crazy boy;2154787 I would appreciate some correction to the code
[code
HWND HCapture = FindWindow(NULL, _T("Learning WInAPI"));[/code]
... Is it possible to find window case insensitive and beginning just "learn"? But I wonder that the last bitmap was made when I have incorrect case. Should be "Learning WinAPI".
You should never trust the FindWindow in your attempts to find out the correct window handle.
There may be a lot of the windows with the same title. Note that the handle of the first found window is returned!
There may be a lot of the windows with the same title and the same class name. Note that the handle of the first found window is returned!
There may be nothing found in some localized Windows OS if one looks for a some predefined English string
More info you will find here in the section Why FindWindow doesn't work.
If you are launching the process that contains the target window, look into filtering by pid (process id) when using EnumWindows.
That way, you are sure to find the window in the process you care about.
I have a class with a FindWindowTimeout method that I wrote about 12 years ago. It allows you to do a partial title and partial class search (with or without a pid) to find a window.
Let me know if you would like me to take the time to prep it to post.
I'll have to recheck tomorrow. But now I cannot make working your code:
error C2664: 'GetWindowTextW' : cannot convert parameter 2 from 'char [201]' to 'LPWSTR'
Why I got this message? I use Unicode, not ANSI.
Originally Posted by Arjay
Let me know if you would like me to take the time to prep it to post.
Of sure you're welcome if you wanna help.
PS: Does this forum support sending notifications of new post in thread on email? Asking because I am used to edit my post often while they are fresh.
Last edited by crazy boy; May 12th, 2014 at 03:57 PM.
I'll have to recheck tomorrow. But now I cannot make working your code:
error C2664: 'GetWindowTextW' : cannot convert parameter 2 from 'char [201]' to 'LPWSTR'
Why I got this message? I use Unicode, not ANSI.
I use ANSI. Change GetWindowText( to GetWindowTextA(
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!
Yes it was originally, but see my post #82 and #85. I moved away from any changes to the program producing the window to be captured. The code in #96 doesn't require any changes to the window producing program. The other program was simply a test program to produce a window containg an eclipse that could be captured This had a title of wintest - hence the use of wintest in the FindWindow().
See the attached 2013 VC++ project. I wrote the original code about 12 years ago. This was part of a COM test automation engine which used Active Accessibility to automate the testing of applications.
It has a funky mix of ComBSTR and Tstring (which is a typedef of std::string or std::wstring). Back then CString wasn't available outside of MFC (which it is now). ComBSTR was used for the COM interface level (and Tstring was used internally).
If you actually use this code, clean it up by stripping out the ComBSTR, OLE_HANDLE (just use HWND), and Tstring (just use CString).
Code:
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = S_OK;
OLE_HANDLE hWnd = NULL;
LONG lPid = 13296; // Open up a few instances of Notepad and put one of the pids here
CWindow window;
if(SUCCEEDED(hr = window.FindWindowTimeout(
lPid, // Restrict by Process id
NULL, // Parent hwnd
CComBSTR("Notepad"), // Window class
CComBSTR("Untitled"), // Window title (partial title - full title is 'Untitled - Notepad')
30, // Find for 30 seconds
// Flags - look for visible window that exists with a partial title match and restrict by process id
FW_EXISTS | FW_PARTIAL_TITLE_MATCH | FW_USEPID | FW_VISIBLE,
&hWnd)))
{
// Valid hWnd
}
return 0;
}
Which function to use to detect if menu is present in the app? It's nonsense to recompile every time I change app. You also could help me if you would approve the code to support more titles. I am debugging 4 apps as target window: Learning WinAPI , Dialog App, AOK Trigger Studio and Map Viewer.
To prevent using more files derived from capture3.cpp I want to change system of my tests. So I define
Code:
#define CODE 81
where number is number of your post. So now I need directive which will be used to determine if the
CODE == 81 or if CODE >= 81 ...
OK, so I have this code now, but when I debug it and no target window prepared it looks like it freeze. I looks that the while loop is infinite, which is not ideal. I'd suggest to test it just for second. So now I am at code 81 and I will do my way through all your codes. http://paste.ofcode.org/HpxJ3cbzkNUQL7zmqwUNrN
Last edited by crazy boy; May 13th, 2014 at 05:37 AM.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.