Forums > Dev

Getting a window handle

August 30, 2006 | 1:00 pm

We are trying to get an HWND for a t_wind as part of the OpenGL windowing technique at http://www.cycling74.com/forums/index.php?t=msg&goto=38969 presented in the archives. When we run the following code, Max posts a correct value of 60 for the right edge, suggesting that we are successfully creating a t_wind. Nonetheless, our call to wind_gethwnd returns null. Does anyone have any advice on resolving this problem?

t_wind *w = NULL;
w = wind_new (x, 10, 10, 60, 60, 0);
if (!w)
post ("w is still null");
else
post ("right is %ld", (long)w->w_x2);
x->iWindowRef = wind_gethwnd(w);
if (!x->iWindowRef)
post ("Can’t gethwnd.");


August 30, 2006 | 1:18 pm

Probably unrelated, but I was trying to do a similar operation with the
TEHandle member of the "ed" structure and Jeremy said that the internal
Cycling code wasn’t using that struct member any longer. Since you’re
creating your own wind I don’t think this would be the problem.

I’d be interested in what you find out, though.

brad

http://music.columbia.edu/~brad

On Wed, 30 Aug 2006, Fred Collopy wrote:

>
> We are trying to get an HWND for a t_wind as part of the OpenGL
> windowing technique at
> http://www.cycling74.com/forums/index.php?t=msg&goto=38969 presented in
> the archives. When we run the following code, Max posts a correct value
> of 60 for the right edge, suggesting that we are successfully creating a
> t_wind. Nonetheless, our call to wind_gethwnd returns null. Does anyone
> have any advice on resolving this problem?
>
> t_wind *w = NULL;
> w = wind_new (x, 10, 10, 60, 60, 0);
> if (!w)
> post ("w is still null");
> else
> post ("right is %ld", (long)w->w_x2);
> x->iWindowRef = wind_gethwnd(w);
> if (!x->iWindowRef)
> post ("Can’t gethwnd.");
>


August 30, 2006 | 3:48 pm

I don’t think wind_gethwnd() returns anything before the window has
been made visible. If you pass the WVIS flag to the wind_new()
function, or call wind_vis() on the t_wind *, the window will really
be created and a platform-specific window (HWND in this case)
associated with it.

jb

Am 30.08.2006 um 15:00 schrieb Fred Collopy:

>
> We are trying to get an HWND for a t_wind as part of the OpenGL
> windowing technique at http://www.cycling74.com/forums/index.php?
> t=msg&goto=38969 presented in the archives. When we run the
> following code, Max posts a correct value of 60 for the right edge,
> suggesting that we are successfully creating a t_wind. Nonetheless,
> our call to wind_gethwnd returns null. Does anyone have any advice
> on resolving this problem?
>
> t_wind *w = NULL;
> w = wind_new (x, 10, 10, 60, 60, 0);
> if (!w)
> post ("w is still null");
> else
> post ("right is %ld", (long)w->w_x2);
> x->iWindowRef = wind_gethwnd(w);
> if (!x->iWindowRef)
> post ("Can’t gethwnd.");


August 30, 2006 | 11:28 pm

This may be some help. It is a function to set up and opengl window in
a max external under windows. It’s a while since I’ve looked at it, so
I forget the details, but it does work.

Best,

Aengus.

void InitGLWindow(t_object *x)
{
BOOL ok = false;
int PixelFormat;

PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | // Draw to window (not bitmap)
PFD_SUPPORT_OPENGL | // Support OpenGL calls
PFD_DOUBLEBUFFER, // Double -buffered mode
PFD_TYPE_RGBA, // RGBA Color mode
24, // Want 24bit color
0,0,0,0,0,0, // Not used to select mode
0,0, // Not used to select mode
0,0,0,0,0, // Not used to select mode
32, // Size of depth buffer
0, // Not used to select mode
0, // Not used to select mode
PFD_MAIN_PLANE, // Draw in main plane
0, // Not used to select mode
0,0,0 // Not used to select mode
};

wind_vis(x->wind); // must be called before PixelFormat is set
x->hWnd = wind_gethwnd(x->wind); // Max SDK function to get hWnd for
windows programming

// subclassing stuff
x->oldproc = (WNDPROC)SetWindowLong(x->hWnd, GWL_WNDPROC, (LONG)MyOwnWndProc);

x->hDC=GetDC(x->hWnd);
PixelFormat=ChoosePixelFormat(x->hDC,&pfd);
SetPixelFormat(x->hDC,PixelFormat,&pfd);
x->hRC=wglCreateContext(x->hDC);
if(x->hRC == NULL) post("InitGLWindow: wglCreateContext failed – %d",
GetLastError());
x->window_is_visible = true;

SelectClipRgn(x->hDC,NULL);
ok = wglMakeCurrent(x->hDC,x->hRC);
if(!ok) post("InitGLWindow: wglMakeCurrent(x->hDC,x->hRC) failed -
%d", GetLastError());

// set viewport to window dimensions
glViewport(0,0,x->win_width, x->win_height);
}

The relevant variables in the object’s struct are :
long win_width;
long win_height;
t_wind *wind; // pointer to our object’s own window
HWND hWnd;
WNDPROC oldproc;
HDC hDC;
HGLRC hRC;
void *qelem;
BOOL window_is_visible;

On 8/31/06, Jeremy Bernstein wrote:
> I don’t think wind_gethwnd() returns anything before the window has
> been made visible. If you pass the WVIS flag to the wind_new()
> function, or call wind_vis() on the t_wind *, the window will really
> be created and a platform-specific window (HWND in this case)
> associated with it.
>
> jb
>
> Am 30.08.2006 um 15:00 schrieb Fred Collopy:
>
> >
> > We are trying to get an HWND for a t_wind as part of the OpenGL
> > windowing technique at http://www.cycling74.com/forums/index.php?
> > t=msg&goto=38969 presented in the archives. When we run the
> > following code, Max posts a correct value of 60 for the right edge,
> > suggesting that we are successfully creating a t_wind. Nonetheless,
> > our call to wind_gethwnd returns null. Does anyone have any advice
> > on resolving this problem?
> >
> > t_wind *w = NULL;
> > w = wind_new (x, 10, 10, 60, 60, 0);
> > if (!w)
> > post ("w is still null");
> > else
> > post ("right is %ld", (long)w->w_x2);
> > x->iWindowRef = wind_gethwnd(w);
> > if (!x->iWindowRef)
> > post ("Can’t gethwnd.");
>
>


____________________
http://www.am-process.org


Viewing 4 posts - 1 through 4 (of 4 total)