Jump to content


Photo

Help with detecting input in a different window


  • Please log in to reply
11 replies to this topic

#1 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 02 September 2010 - 07:51 AM

I'm using c++ to [try] to make a simple 3D engine for gamemaker. I have managed to create the window, however when I select it and press "Escape" it doesn't do anything. I have to select the gamemaker window and press escape to exit. This creates a problem, as all events/user input that the user does in gamemaker are not detected by my engine... So my question is how do you guys do it? Or is there a way to embed my window into/overtop of the gamemaker one?

A good example of what I want done is GMOgre or U3D, they both draw a separate window overtop of the gamemaker one. They both still run GM in the background and can detect user input.




Any help would be greatly appreciated.
Cheers
~~Brett14;

PS: If you have any questions about what I'm asking, just ask!

Edited by brett14, 02 September 2010 - 06:04 PM.

  • 0

#2 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 02 September 2010 - 08:24 AM

So my question is how do you guys do it?

Create a (named) pipe between the two programs ?

Or is there a way to embed my window into/overtop of the gamemaker one?

Look for something called "gmbed" (do a "site:gmc.yoyogames.com gmbed" google search).

Look here : http://gmc.yoyogames...howtopic=174619 (Embed DLL).

Thanks to "Medusar" for pointing out I had the wrong DLL. :mellow:

Edited by ragarnak, 02 September 2010 - 12:11 PM.

  • 0

#3 Medusar

Medusar

    GMC Member

  • GMC Member
  • 1228 posts
  • Version:GM:Studio

Posted 02 September 2010 - 11:55 AM

Look for something called "gmbed" (do a "site:gmc.yoyogames.com gmbed" google search).

GMBED is a Java applet for embedding GM games into a webpage. It cannot embed a window into another.

@brett14: If you want to detect key presses in your new window only, perhaps you could find an esc key pressed message that's sent to your window procedure. I don't know if it exists.
If it's the GM window you want to check, you could subclass the GM window (that's the technique that e.g. Max WinAPI uses to intercept messages), or even easier, use GMAPI to check for pressed keys and mouse clicks.

Couldn't you just draw directly to the GM window instead of making a new one? Or perhaps make your new window a child window of the GM window?

I don't really know anything about this, just spitting out ideas.
  • 0

#4 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 02 September 2010 - 01:55 PM

I've done this with my console DLL (link should be in sig), it used GMAPI to send input to a script. You could try the same approach, but it won't let you use events. Now, what you can do is pass the window handle to your DLL's initialization (for the engine) and store the WindowProc of GM. In your WindowProc, forward data to GM's WindowProc. This method should work better.

A few MSDN links:
- WindowProc
- GetWindowLong
- CallWindowProc
  • 0

#5 Medusar

Medusar

    GMC Member

  • GMC Member
  • 1228 posts
  • Version:GM:Studio

Posted 02 September 2010 - 02:15 PM

That's called window subclassing. In your window procedure, check for a WM_KEYDOWN message. The keycode is in the wparam, it's equal to VK_ESCAPE if the escape key was pressed. Don't forget to call GM's window procedure (not the default one) when you're finished or the GM window won't respond to any user input.

I searched a bit more about intercepting GM's events, but I couldn't find a way other than calling a DLL function in every event... that's not only ugly but you probably don't want that either. I suppose subclassing and checking for all events manually is the best option.
  • 0

#6 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 02 September 2010 - 04:56 PM

You should only be forwarding input to GM, unless there's required events for the engine.
  • 0

#7 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 02 September 2010 - 05:57 PM

You guys are along the lines of what I want, but not exactly.

In gamemaker lets say I create an object, and add event keyboard left
x-=1;
and keyboard right
x+=1;


This will not work because my window is selected and not the gamemaker one, so none of the user input will happen. How can I keep the input from gamemaker coming in and doing things in Gamemaker where my window is selected and drawn overtop of it?


[EDIT]
A good example of this is GMOgre3D. It draws a window overtop of gamemakers, but still detects and reacts to user input in the gamemaker window. Another example is U3D.
[/EDIT]

Edited by brett14, 02 September 2010 - 06:02 PM.

  • 0

#8 Medusar

Medusar

    GMC Member

  • GMC Member
  • 1228 posts
  • Version:GM:Studio

Posted 02 September 2010 - 07:38 PM

Oh right, sorry about my previous post and just do what TheMagicNumber said... Don't intercept the messages of GM's window in your window procedure, but simply forward the messages your window procedure gets to GM's window procedure. Do something like this...
WNDPROC GMWndProc;

//somewhere in init function... GMhWnd is set to GM's window handle (see window_handle() in the GM manual)
	//Get GM's window handle
	GMWndProc = (WNDPROC) GetWindowLong(GMhWnd, GWL_WNDPROC);

//your own window procedure
LRESULT CALLBACK OwnWndProc(HWND Hwnd, UINT  Message, WPARAM  wParam, LPARAM  lParam) {
	return CallWindowProc(GMWndProc, GMhWnd, Message, wParam, lParam);
}
Forgive any errors but that's what it should roughly look like.
  • 0

#9 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 02 September 2010 - 09:36 PM

This will not work because my window is selected and not the gamemaker one, so none of the user input will happen.

What I said is to forward messages, it will work.
  • 0

#10 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 02 September 2010 - 09:49 PM

deactivate the GM window, SetFocus and SetCapture to your window or control... reactivate gm's window ReleaseCapture and SetFocus back on GM's window when you hit escape.

Your main window proc should catch the keyboard messages and you should retun 0 (methinks) to tell the parent window (you should have called SetPArent or is it owner to set your window to be child or governed by GM' main window) the keyboard event was processed.


Oh, yeah, you have to have the right relationship with the sipling... is you window a child, is it a control (edit box) on gm's window?

deactivate would deactivate input to controls (edit box) and all children (like floating window on top of gm), so yeah, forget about setting the parent of your window, or forget about deactivating gm's window; setting the focus on your window should work

Edited by icuurd12b42, 02 September 2010 - 09:53 PM.

  • 0

#11 Houdini

Houdini

    GMC Member

  • New Member
  • 195 posts

Posted 11 October 2010 - 07:26 PM

Sorry for resurrecting a slightly older thread, but I did want to clarify how GMOgre3D takes care of this issue. I don't actually create a new window on top of GM's window. Instead I use the hwnd of the GM window and draw directly to that. You'll need to call set_automatic_draw(false) so you can use the window, though. Otherwise GM and your 3D engine will both be fighting over who is drawing to that window.

- Houdini
  • 0

#12 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 11 October 2010 - 08:12 PM

No problem, but that actually helps - although a little late.
I didn't know that you could have 2 D3D Objects on 1 window at the same time, good to know.


Thanks
~~Brett14;
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users