Page 1 of 1

HWND Problems ... Embbeding Windows into others

Posted: Wed Mar 19, 2008 6:16 am
by Yourself
I'm using PB to make a dll for Game Maker by Mark Overmars.
I need to embed a PB created into the Game Maker window.
Game Maker provides the handle to the drawing window using the window_handle() function. I need to store this value in a variable of HWND type. Then I need to use the SetParent_() API to embed the PB window into the Game Maker one. This is not happening! As Pure Basic complains if I use gmhwnd.Hwnd i declared it as a long. I then used a MessageBox_() call to see
whether it would embed correctly into the Game Maker window. This does NOT happen. So how would I go on to make a variable of HWND type in PB so its value can be passed to API functions??
Please Help, and thanks in advance!

Posted: Wed Mar 19, 2008 9:10 am
by Fluid Byte
Code please.

Oh sure...

Posted: Wed Mar 19, 2008 11:02 am
by Yourself
This is the code of the MessageBox_() API problem as explained above.
The Message Box should embed on to the window with the specified HWND in the first argument. But when I run this as a dll from Game Maker , it does not!

Code: Select all

;Pure Basic code compiled as DLL
ProcedureDLL.l Message(gm_hwnd.l)
messageBox_(gm_hwnd,"Test","test",1)
ProcedureReturn 1
EndProcedure

Code: Select all

//Game Maker code which calls the dll 
f = external_define("Test.dll","Message",dll_stdcall,ty_real,1,ty_real)
external_call(f,window_handle())
The Message Box is displayed all right but its not displayed as part of the window ie, its got its own taskbar icon which it should not have!

Bump

Posted: Fri Mar 21, 2008 11:37 am
by Yourself
This is bump. C'mon please help me!

Posted: Fri Mar 21, 2008 12:39 pm
by ABBKlaus
Your game maker code doesn´t have a window :shock:

You could test it with this PB-Code :

Code: Select all

;Pure Basic code compiled as DLL 
ProcedureDLL.l Message(gm_hwnd.l) 
  MessageBox_(gm_hwnd,"Test","Window-Handle :"+Str(gm_hwnd),1) 
  ProcedureReturn 1 
EndProcedure 

Posted: Fri Mar 21, 2008 12:41 pm
by srod
Throw in a IsWindow_() into the message box to be absolutely certain.

Posted: Fri Mar 21, 2008 1:21 pm
by Yourself
ABBKlaus , there's no need for me to create a window in GM like in PB. A window is auto- created render the game graphics.
The Game Maker help manual States -

Code: Select all

In some rare cases your DLL might need to know the handle of the main graphics window for the game. This can be obtained with the following function and can then be passed to the DLL: 


window_handle() Returns the window handle for the main window.

That's from the GM- Help file.

srod - I'm trying it.

Its not working despite the fact that i set it up properly.
I just remembered that when ever GM returns the handle its a double. Any way to convert it into a HWND ?
Trond has used Game Maker , can you help me Trond ?

Posted: Fri Mar 21, 2008 1:28 pm
by srod
A double? You don't mean a 64-bit floating point value do you?

Do you mean a quad value?

Posted: Fri Mar 21, 2008 4:10 pm
by Yourself
Never mind! I found the Trunc() function which does this for me.

Posted: Mon Mar 24, 2008 8:02 pm
by Trond
PB doesn't have a Trunc().
How to do it:

Code: Select all

;Pure Basic code compiled as DLL 
ProcedureDLL.d Message(gm_hwnd_d.d)
  gm_hwnd_l.l = gm_hwnd_d
  messageBox_(gm_hwnd_d,"Test","test",1)
  ProcedureReturn 1
EndProcedure
All numbers in GM are type.d in PB.