|
-
April 12th, 2013, 07:47 PM
#9
Re: Capture a window
Ok, the last post in this thread is already one month ago and the thread is [RESOLVED], but I think it's worth noting that this leaks memory:
 Originally Posted by RogerD
Code:
System::Drawing::Rectangle^ Win32::GetWindowRect(Point pt)
{
POINT ptNative = {pt.X, pt.Y};
HWND hwnd = ::WindowFromPoint(ptNative);
LPRECT rect = new RECT;
::GetWindowRect(hwnd,rect);
return System::Drawing::Rectangle(rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top);
}
The dynamically allocated rect is never released. Actually, there's no need to dynamically allocate it anyway. The reason why I dynamically allocated lpNativeText in Win32::GetWindowText_() was that I couldn'd know its size in advance, which is not the case with the fixed-size RECT structure. Here's a fixed version:
Code:
Drawing::Rectangle^ Win32::GetWindowRect(Point pt)
{
POINT ptNative = {pt.X, pt.Y};
HWND hwnd = ::WindowFromPoint(ptNative);
RECT rect;
::GetWindowRect(hwnd, &rect);
return Drawing::Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
}
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
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
|