get HWND from existing opengl window

Rob Ramirez's icon

well it's deja vu all over again.

i'm porting jit-ogre to windows and have spent the past couple of hours trying to figure out how to retrieve the HWND window handle of the automatically created window associated with my t_jit_gl_context.

basically i need the windows equivalent of this:
OpaqueWindowPtr* myWindow = (OpaqueWindowPtr*)jit_context->drawable;
ControlRef theContentView;
GetRootControl(myWindow, &theContentView);

I believe HWND is the windows version of ControlRef.

the only thing i came up with is by somehow retrieving the t_wind struct of the jit.window, but i'm not sure how to do that from the t_jit_gl_context.

any help much appreciated.

-rob

Wesley Smith's icon

An HWND is basically equivalent to a WindowRef I believe. Have you
looked at the typedefs in jit.gl.context.h? Perhaps you can get what
you want from t_jit_gl_native_context or t_jit_gl_native_drawable.

wes

On Jan 8, 2008 10:23 PM, Robert Ramirez wrote:
>
> well it's deja vu all over again.
>
> i'm porting jit-ogre to windows and have spent the past couple of hours trying to figure out how to retrieve the HWND window handle of the automatically created window associated with my t_jit_gl_context.
>
> basically i need the windows equivalent of this:
> OpaqueWindowPtr* myWindow = (OpaqueWindowPtr*)jit_context->drawable;
> ControlRef theContentView;
> GetRootControl(myWindow, &theContentView);
>
> I believe HWND is the windows version of ControlRef.
>
> the only thing i came up with is by somehow retrieving the t_wind struct of the jit.window, but i'm not sure how to do that from the t_jit_gl_context.
>
> any help much appreciated.
>
> -rob
>
>

Rob Ramirez's icon

right, that's what i'm trying to do. i retrieve the native_drawable (and HDC) from the current context.

however, the only os calls that i have found go in the wrong direction, ie. retrieve a HDC from an existing HWND. i need to retrieve an HWND from a HDC.

i had a much easier time finding the correct os calls to do this on os x then on windows. go figure.

any ideas?

Rob Ramirez's icon

[edit] should be:
"i retrieve the native_drawable (a HDC) from the current context."

Joshua Kit Clayton's icon

On Jan 9, 2008, at 7:33 AM, Robert Ramirez wrote:

>
> right, that's what i'm trying to do. i retrieve the
> native_drawable (and HDC) from the current context.
>
> however, the only os calls that i have found go in the wrong
> direction, ie. retrieve a HDC from an existing HWND. i need to
> retrieve an HWND from a HDC.

Can't guarantee that this will always work in the future, but for
now, you can code something like the following. Warning: email client
code:

HWND show_me_some_hwnd_love(t_jit_gl_context *jctx)
{
    t_wind *w;

    switch (jctx->targettype)
    {
    case JIT_GL_TARGET_MATRIX:
        // I don't have an HWND, but I have a HBITMAP in jctx->auxdata
        return NULL;
    case JIT_GL_TARGET_PWINDOW:
        return jctx->auxdata;
    case JIT_GL_TARGET_WINDOW, we have
        w = (t_wind *) t_jit_gl_context->target;
        return wind_gethwnd(w);
    default:
        return NULL;
    }
}

Hope this helps.

-Joshua

Rob Ramirez's icon

hey josh, thanks for the code.
that's good to know.

however i just found the windows function i needed:

//drawable is a HDC
HWND win = WindowFromDC(drawable);

i knew(hoped) it would be something simple.

now i gotta get these f'n path issues worked out ...