Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - iiingo

Pages: [1]
1
Window / Get win32 window handle (HWND) *SOLVED*
« on: October 14, 2007, 02:30:37 pm »
Quote from: "Laurent"
Your solution is the good one, except that you should return a sf::WindowHandle instead of HWND to keep portability.

I know some keys are missing, I'll fix it as soon as possible, that's not a problem ;)


I will edit my code and the post :D.

Great! Thanks for a very nice API btw, I will post my project in the projects section soon, it's a 4 player network coop shooter, the network code is almost done, the GUI system is almost done and the gameplay code is maby 40% done :D.

2
Window / Get win32 window handle (HWND) *SOLVED*
« on: October 13, 2007, 06:21:45 pm »
Quote from: "Laurent"
You have to dive a little bit into the sf::Window class, and then into the sf::WindowImpl class. But it should be very easy to get the OS-specific window identifier. Each sf::WindowImpl derived class (one for each OS) stores its window id, so you should be able to return it with a virtual function. There is even a portable type for it : sf::WindowHandle.

But, why do you need OIS ? If something in OIS is better than in SFML I should really think about adding it.


Thanks for the quick answer, you must have posted while I was writing my post :D.

Well.. the main reason is that i've been using OIS before and it's got all possible functionality i've ever needed besides for rumble for Xbox360 controllers but if i recall right only XInput handles that at the moment and that's probably not a concidence heh ;).

At first i didn't dig deep enough in SFML to notice that you're only missing a few defines to be able to use all keys either so i guess i could go with SFML's sf::Input too by only adding a few defs (i need all the keys on the keyboard for my network chat, the SHIFT keys for example) but now i've got OIS working anyways ^^.
Please add all the possible keys to:
Code: [Select]

Key::Code WindowImplWin32::VirtualKeyCodeToSF(WPARAM VirtualKey)

If you've got time :D.

Great design on the lib btw!

3
Window / Get win32 window handle (HWND) *SOLVED*
« on: October 13, 2007, 06:04:50 pm »
Ok I solved it, and here's the portable solution:

First make a getter for the window handle that is already stored in
sf::priv::WindowImplWin32 as myHandle:

FILE: src\SFML\Window\Win32\WindowImplWin32.hpp:
Code: [Select]

public:
WindowHandle GetWindowHandle( void ) const;


FILE: src\SFML\Window\Win32\WindowImplWin32.cpp:
Code: [Select]

WindowHandle WindowImplWin32::GetWindowHandle( void ) const {
return myHandle;
}


Now to not break the Linux/OSX portability we must add this functionallity to the other window creation methods as well:

WindowImplCarbon
FILE: src\SFML\Window\OSX\WindowImplCarbon.hpp:
Code: [Select]

public:
WindowHandle GetWindowHandle( void ) const;


FILE: src\SFML\Window\OSX\WindowImplCarbon.cpp:
Code: [Select]

WindowHandle WindowImplCarbon::GetWindowHandle( void ) const {
return myHandle;
}


WindowImplX11
FILE: src\SFML\Window\Linux\WindowImplX11.hpp:
Code: [Select]

public:
WindowHandle GetWindowHandle( void ) const;


FILE: src\SFML\Window\Linux\WindowImplX11.cpp:
Code: [Select]

WindowHandle WindowImplX11::GetWindowHandle( void ) const {
return NULL; // Or is there some kind of WindowHandle on Linux?
}


Then change the interface sf::priv::WindowImpl so that we can access the window handle from sf::Window later on.
FILE: src\SFML\Window\WindowImpl.hpp
Code: [Select]

public:
virtual WindowHandle GetWindowHandle( void ) const  = 0;


Now add the getter to sf::Window that just calls the other getters:
FILE: src\SFML\Window\Window.hpp
Code: [Select]

WindowHandle GetWindowHandle() const;


FILE: src\SFML\Window\Window.cpp
Code: [Select]

WindowHandle Window::GetWindowHandle() const {
return myWindow->GetWindowHandle();
}


Well.. now it's possible to access the window handle from a sf::Window, but probably you'll want to be able to do sf::RenderWindow->GetWindowHandle() so lets do our last hack:
( sf::RenderWindow uses private inheritance from sf::Window so it will not be possible to just call GetWindowHandle() from the base class ).

FILE: src\SFML\Graphics\RenderWindow.hpp
Code: [Select]

public:
WindowHandle GetWindowHandle(void);


FILE: \src\SFML\Graphics\RenderWindow.cpp
Code: [Select]

WindowHandle RenderWindow::GetWindowHandle( void ) const {
return Window::GetWindowHandle();
}


That's it! now recompile sfml, if you're on Linux or Mac you must add the GetWindowHandle() method to the other window creation methods to get this code to work.

/ iiingo

4
Window / Get win32 window handle (HWND) *SOLVED*
« on: October 13, 2007, 05:11:11 pm »
I've been hacking a bit in the code now but i can't seem to figure out a nice clean way to extract the window handle from a sf::RenderWindow, can someone recommend a good way to do this?

I need the HWND for OIS ( Object Oriented Input System ).

Cheers!

/ iiingo

Pages: [1]