Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GetWindowRgn API returns ERROR

GetWindowRgn API returns ERROR

Scheduled Pinned Locked Moved C / C++ / MFC
helpjsonquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    atm menon
    wrote on last edited by
    #1

    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

    _ L 2 Replies Last reply
    0
    • A atm menon

      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

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Try putting an IsWindow check before calling GetWindowRgn.

      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)

      Polymorphism in C

      1 Reply Last reply
      0
      • A atm menon

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        What does GetLastError tell you?

        A 1 Reply Last reply
        0
        • L Lost User

          What does GetLastError tell you?

          A Offline
          A Offline
          atm menon
          wrote on last edited by
          #4

          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

          L 1 Reply Last reply
          0
          • A atm menon

            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

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            atm.menon wrote:

            why its happened only some times

            Impossible to tell without a lot more diagnostic information.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups