Way to get Active Window Handle?

BlitzMax Forums/BlitzMax Programming/Way to get Active Window Handle?

Grey Alien(Posted 2008) [#1]
Is there a way to get a Window Handle for the window created with Graphics()? Does the application know the handle of it's own window? It must do somehow. If we could get that, we wouldn't need GetActiveWindow() or the Mac equivalent which may be unreliable if another window has become active. Thx.


GfK(Posted 2008) [#2]
[edit] Never mind - didn't read all of your post.

I'm sure there's a native way of doing it - will have a look.

(although - if you call GetActiveWindow immediately after creating the graphics object, there's [virtually] zero chance of it being wrong).


GfK(Posted 2008) [#3]
http://www.blitzbasic.com/Community/posts.php?topic=58568

This thread says that PrimaryDevice.hWnd returns the window handle. You're in that thread so I guess you forgot.

However, the thread is two years old and if that solution ever worked, it doesn't seem to in 1.30.


Grey Alien(Posted 2008) [#4]
Yeah I think that PrimaryDevice was removed in 1.28 or something along with the other DirectX changes.

(although - if you call GetActiveWindow immediately after creating the graphics object, there's [virtually] zero chance of it being wrong).
I guess so (which is what I'm doing anyway) but someone said that due to OS delays that's not always the case. Also I know for a fact that my equivalent Mac code definitely fails sometimes!


Brucey(Posted 2008) [#5]
For GL on Windows, the handle is stored in the BBGLContext object.

Probably just a case of adding a function somewhere to request the handle.


tonyg(Posted 2008) [#6]
Graphics 800,600
Local my_driver:TD3D7Graphicsdriver=D3D7GraphicsDriver()
Local my_graphics:TD3D7Graphics=my_driver.Graphics()
Local my_hWnd:Int = my_graphics._hwnd
Print my_hwnd

I think


Grey Alien(Posted 2008) [#7]
Yay TonyG, that works! Thanks.

So now my question is how to obtain the same info from OpenGL on Windows using Brucey's info and also how to obtain that info on Macs... :-)


Grey Alien(Posted 2008) [#8]
Hi Does anyone know the answer to my question in the post above? Thx!


tonyg(Posted 2008) [#9]
For OGL the information is kept at C++ level and the glgraphics getsettings method calling bbGLGraphicsGetSettings doesn't return the hwnd. I think you'd have to change the C++ code and the glgraphics module but could be wrong.


Grey Alien(Posted 2008) [#10]
OK thanks for the info Tony, sounds like a bit of a pain. Having the correct Window Handle is pretty useful you see...Maybe I can ask BRL to add it as a global variable or something. What's the best way to make a request do you think?


tonyg(Posted 2008) [#11]
Think email would be best.


Grey Alien(Posted 2008) [#12]
OK thanks. Will try. ... DONE.