Reposition Window
BlitzMax Forums/BlitzMax Programming/Reposition Window
| ||
I want to be able to reposition a window (without using MaxGUI). At the moment, I've got :PostEvent(CreateEvent(EVENT_WINDOWMOVE,Null,Null,Null,100,100,Null),True) but unfortunately, it doesn't seem to be doing much... How do you use the PostEvent to allow the window to be repositioned ? |
| ||
I use this. Can't remember where I got it:Function centreWindow(hWnd%) 'Centres the current graphics window on the desktop 'Pass a handle in ?Win32 Local desk[4] Local window[4] GetWindowRect(GetDesktopWindow(), desk) ' GetWindowRect(hWnd, window) 'Centre Window SetWindowPos(hWnd, HWND_NOTOPMOST, (desk[2] - (window[2] - window[1])) / 2, (desk[3] - (window[3] - window[0])) / 2, 0, 0, SWP_NOSIZE) ? End Function |
| ||
Normally, I would use that if I was developing just for Windows. But, alas, I'm not. |
| ||
Noob question - What is the "hWnd%" parameter value in that function? I tried calling the function with various values without success. How do you use it? I presume you only call it once, after you've opened a screen? |
| ||
Oops! Use hwnd% = GetActiveWindow() after creating a graphics object. |
| ||
Is it possible to reposition using EventWindow and EVENT_WINDOWMOVE ? |
| ||
No. EVENT_WINDOWMOVE is returned when the window has already been moved by the user. You can't use it (as far as I'm aware) to move the window manually. |
| ||
Thats a shame - any idea of how to reposition a MacOS window ? |
| ||
Thanks GfK |
| ||
It seems that in BlitzMax you can only set the window position when the window is created. According to the documentation, there are only functions to retrieve the position of a gadget, but not to set its X and Y coordinates. Looks like we need to request that feature. |
| ||
Indeed - it would be useful. At least, I can centre the Windows window at any rate :) |
| ||
Sure? Thought the _setPosition is just not documented and "exposed" to the user ... But does not mean that it is not there actually. |
| ||
Doesn't seem to be anything like that. |
| ||
Im sorry, it was SetGadgetShape |
| ||
Yeah, right, SetGadgetShape() does the trick... BUT: Who would have guessed that a function with that name would actually reposition a window?? You'd expect something like setX(), setY(), setPosition(), moveWindow() - something that lets you know is has something to do with coordinates. Anyway, again something new learned. ;-) Regarding your mentioning of undocumented features: How is one supposed to use or even know of a feature when it is not documented? Which is why I first said 'according to the documentation...' I general, I don't like or recommend using undocumented features, even if I know about them. Usually they are subject to change, might get dismissed entirely or do not function well. There usually are some good reasons why a feature is not documented. |
| ||
SetGadgetShape is part of MaxGUI - and I dont want to use that module... |
| ||
I'm afraid you cannot do it (easily) without MaxGUI; you'd have to implement that function yourself, and the time you'd waste on doing so is more expensive than the MaxGUI module. If you don't have MaxGUI yet, you should get it. It's very straightforward, easy to use and learn and uses native Cocoa widgets. The MaxIDE is proof that it works. ;-) I saw on your blog that you gave Unity a shot... and then have given up on it. Can you tell a bit more about it? |
| ||
I've got MaxGUI - unfortunately I would have to redo a fair bit of my game to make use of it - and then I would probably have trouble with the full screen part of it... It might be worth after its all completed. Unity has a very good 3D engine. Unfoturtunately the 2D part of it isn't so good - positioning is a real pain. Had no real problems getting to grips with Javascript. Unfortunately it has a few differences between the version in Unity and elsewhere. I did have regular crashes - worked out at once a week. A lot of things that should be simple are not - accessing variables and such from other scripts, and it got to be a pain. |
| ||
Why would you have to redo a fair bit? Its just a simple switch at the beginning :-) If fullscreen graphics ... else create Window Create Canvas Set Focus on Canvas enable polled input endif After that point you can work on as you intend to do with graphics unless I missed something very important ... And it allows you to reposition the window if in windowed mode :) |
| ||
Because a state machine would be needed to deal with title screen, name entry, music selection, game, post game stuff etc etc. A graphics hook would be needed otherwise things wont work properly... Its not pretty, its not quick, and its not something I want to do - yet, anyway. |