GetWindowRgn API returns ERROR
-
In My application, I have used the following code to get the region of a dialog.
HRGN hRgn = CreateRectRgn( 0, 0, 0, 0 );
int nRet = GetWindowRgn( hRgn );
if(ERROR == nRet)
{
DWORD dw= GetLastError();
//Log
}The problem is that, sometimes "GetWindowRgn" returns error "invalid handle" even if CreateRectRgn returns a non-null handle which is used for GetWindowRgn. I have set the region in onSize(). So dialog have region.Also after GetWindowRgn returns error, when i call GetWindowRgn() again, second call is working fine !!! Issue is reproduced only sometimes in a Windows 7 machine. Anyone already faced similar issue? Thanks, Arun
-
In My application, I have used the following code to get the region of a dialog.
HRGN hRgn = CreateRectRgn( 0, 0, 0, 0 );
int nRet = GetWindowRgn( hRgn );
if(ERROR == nRet)
{
DWORD dw= GetLastError();
//Log
}The problem is that, sometimes "GetWindowRgn" returns error "invalid handle" even if CreateRectRgn returns a non-null handle which is used for GetWindowRgn. I have set the region in onSize(). So dialog have region.Also after GetWindowRgn returns error, when i call GetWindowRgn() again, second call is working fine !!! Issue is reproduced only sometimes in a Windows 7 machine. Anyone already faced similar issue? Thanks, Arun
Try putting an
IsWindow
check before callingGetWindowRgn
.if (::IsWindow(m_hWnd))
GetWindowRgn(hRgn);«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
In My application, I have used the following code to get the region of a dialog.
HRGN hRgn = CreateRectRgn( 0, 0, 0, 0 );
int nRet = GetWindowRgn( hRgn );
if(ERROR == nRet)
{
DWORD dw= GetLastError();
//Log
}The problem is that, sometimes "GetWindowRgn" returns error "invalid handle" even if CreateRectRgn returns a non-null handle which is used for GetWindowRgn. I have set the region in onSize(). So dialog have region.Also after GetWindowRgn returns error, when i call GetWindowRgn() again, second call is working fine !!! Issue is reproduced only sometimes in a Windows 7 machine. Anyone already faced similar issue? Thanks, Arun
-
hi, GetLastError shows 6, ie. invalid handle. But when i call method again after failure occurs, its works fine :( I have workarounds for the problem. But I am curious to know the reason. why its happened only some times even if dialog have region. Thanks in advance Arun
-
hi, GetLastError shows 6, ie. invalid handle. But when i call method again after failure occurs, its works fine :( I have workarounds for the problem. But I am curious to know the reason. why its happened only some times even if dialog have region. Thanks in advance Arun