mirror of
https://github.com/greenshot/greenshot
synced 2025-07-13 16:43:54 -07:00
Refactored code to use SafeHandle where possible, this should fix potential resource leaks and make the code more clear.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2429 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
9288fa8212
commit
201ee7082e
7 changed files with 365 additions and 233 deletions
|
@ -1224,15 +1224,15 @@ namespace GreenshotPlugin.Core {
|
|||
/// Get the region for a window
|
||||
/// </summary>
|
||||
private Region GetRegion() {
|
||||
IntPtr windowRegionPtr = GDI32.CreateRectRgn(0,0,0,0);
|
||||
RegionResult result = User32.GetWindowRgn(Handle, windowRegionPtr);
|
||||
Region returnRegion = null;
|
||||
if (result != RegionResult.REGION_ERROR && result != RegionResult.REGION_NULLREGION) {
|
||||
returnRegion = Region.FromHrgn(windowRegionPtr);
|
||||
using (SafeRegionHandle region = GDI32.CreateRectRgn(0, 0, 0, 0)) {
|
||||
if (!region.IsInvalid) {
|
||||
RegionResult result = User32.GetWindowRgn(Handle, region);
|
||||
if (result != RegionResult.REGION_ERROR && result != RegionResult.REGION_NULLREGION) {
|
||||
return Region.FromHrgn(region.DangerousGetHandle());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Free the region object
|
||||
GDI32.DeleteObject(windowRegionPtr);
|
||||
return returnRegion;
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool CanFreezeOrUnfreeze(string titleOrProcessname) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue