Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: retrieve HWND from HDC

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2008
    Location
    brooklyn, ny
    Posts
    2

    retrieve HWND from HDC

    hello forum.
    i am currently porting an application from mac to windows. the app uses a library which creates a window and an opengl context on initialization. i can retrieve the opengl context (HGLRC) and drawable (HDC) from the library methods, but i also need to retrieve the HWND window handle associated with that drawable.

    on the mac, it was a a few lines of code to achieve this from an existing drawable (HDC on win, AGLDrawable on mac):
    OpaqueWindowPtr* myWindow = (OpaqueWindowPtr*)drawable;
    ControlRef theContentView;
    GetRootControl(myWindow, &theContentView);
    the windows version of ControlRef (HWND) is what i'm trying to retrieve.

    does anyone have any ideas how i can achieve this on windows?
    many thanks for any tips.
    -rob

  2. #2
    Junior Member Regular Contributor
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    128

    Re: retrieve HWND from HDC

    On Windows platform, you can acquire device context (HDC) of a window (HWND) by calling GetDC WinAPI function, but AFAIK you can't do this the other way around. Your library should have created window before getting a DC, by using CreateWindow or CreateWindowEx. Check your library documentation if it contains a function to retrieve its handle.
    Henri H.

  3. #3
    Intern Contributor
    Join Date
    Feb 2003
    Posts
    85

    Re: retrieve HWND from HDC

    HWND WindowFromDC(HDC hdc) should do the trick.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    128

    Re: retrieve HWND from HDC

    Ah! That function I didn't know it existed!
    Henri H.

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2008
    Location
    brooklyn, ny
    Posts
    2

    Re: retrieve HWND from HDC

    AHA! don't know why i couldn't find that function.
    many thanks.

    -rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •