Api SetWindowPos and style

BlitzPlus Forums/BlitzPlus Programming/Api SetWindowPos and style

I'm having problems getting windows api SetWindowPos() to work with windows that have a menu and status bar (ex: CreateWindow("Test",0,400,400,100,0,7+8) ). I have included this in the user32.decal , SetWindowPos% (hwnd%, hWndInsertAfter%, x%, y%, cx%, cy%, wFlags%) : "SetWindowPos" .

Any ideas?

L8r,

Never had an issue with menu'd windows that I know of. Here's the code I used to make a window fullscreen, see if it works for you.

;.lib "user32.dll"
;SetWindowPos%(hWnd%,hAfter%,x%,y%,cx%,cy%,flags%)

SetWindowPos QueryObject(Window(0), 1), -1, 0, 0, ClientWidth(Desktop()), ClientHeight(Desktop()), 0
* edit * Just tested it and it's giving me problems with the status bar too. Seeing if I can come up with a fix...

* edit 2 *
Found a fix:
;.lib "user32.dll"
;GetActiveWindow%()
;SetWindowPos%(hWnd%,hAfter%,x%,y%,cx%,cy%,flags%)

test = CreateWindow("Test",0,400,400,100,0,7 + 8)
hwnd = GetActiveWindow()

Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = 1
Const SWP_NOMOVE = 2
Const SWP_NOACTIVATE = 16
Const SWP_SHOWWINDOW = 64

SetWindowPos hwnd, HWND_TOPMOST, 0, 0, ClientWidth(Desktop()), ClientHeight(Desktop()), 0

Repeat: Until WaitEvent() = $803
Looks like QueryObject doesn't return a proper hWnd on status windows.

* edit 3 *
You're welcome, Richard :)

Very Nice!!

Thanks alot Eikon!


L8r,

One more thing :)

How would I keep the "TopMost" window active all the time? I've tried SetActiveWindow(), ShowWindow() (win api) and alike, with no help.

I've also tried catching event $2001 and using ActivateWindow(), also no luck.

Ideas?

L8r,

I tried every API function in the book and I can't get a modal window working. I also searched the forums and no one else seems to have figured it out either.

I will look into it more tommorow at work. Would a DLL be ok?

Would a DLL be ok

Sure:)

What I'm up to is working on an IDE. So, when I launch/run the compiler app. I set the IDE window to "TopMost" and then set foucus to that window. I next use FindWindow() to look for a specific compiler window and then when it's gone continue to run the compiled app. This is the only way I could get it all to work. FindWindow() seems not to work unless I set the window to "TopMost" and SetFocus().

Getting the window to stay active would be nice. But getting ShowWindow() to work right would be even better. ShowWindow() seems to work oddly with B+. I tried minimizing and then restoring the IDE window, which worked, but it for some reason stays inactive when it's restored (huh..what). In fact after doing this no windows are active on the desktop. Soooo.. I hope this add s some light to at least what I'm doing.

BTW.. These are the ShowWindow() flags I'm using:

;#define SW_HIDE 0
;#define SW_SHOWNORMAL 1
;#define SW_NORMAL 1
;#define SW_SHOWMINIMIZED 2
;#define SW_SHOWMAXIMIZED 3
;#define SW_MAXIMIZE 3
;#define SW_SHOWNOACTIVATE 4
;#define SW_SHOW 5
;#define SW_MINIMIZE 6
;#define SW_SHOWMINNOACTIVE 7
;#define SW_SHOWNA 8
;#define SW_RESTORE 9
;#define SW_SHOWDEFAULT 10
;#define SW_FORCEMINIMIZE 11
;#define SW_MAX 11


-- EDIT --
Well.. I still need a "TopMost" window but it's not needed to get FindWindow() to work correctly. If I use WaitEvent(0) (notice the zero) instead of WaitEvent() FindWindow() seems to work fine. It's polling all the time that way but I guess it makes sence. ShowWindow() was unaffected (still not working) by zero polling.

Thanks for the help :)
L8r,

Always on top (mixed in with other code) (note that this is code for B3D and may need some messing around with):
AppTitle "testStyle"
Graphics3D 800,600,0,2

SetBuffer BackBuffer()


Type tRect
    Field iLeft
    Field iTop
    Field iRight
    Field iBottom
End Type

Const  GWL_WNDPROC = -4
Const  GWL_HINSTANCE = -6
Const  GWL_HWNDPARENT = -8
Const  GWL_STYLE = -16
Const  GWL_EXSTYLE = -20
Const  GWL_USERDATA = -21
Const  GWL_ID = -12

Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1

Const SWP_SHOWWINDOW = $40

Const WS_OVERLAPPED = 0
Const WS_POPUP = $80000000
Const WS_CHILD = $40000000
Const WS_MINIMIZE = $20000000
Const WS_VISIBLE = $10000000
Const WS_DISABLED = $8000000
Const WS_CLIPSIBLINGS = $4000000
Const WS_CLIPCHILDREN = $2000000
Const WS_MAXIMIZE = $1000000

Const WS_CAPTION = $C00000
Const WS_BORDER = $800000
Const WS_THICKFRAME = $40000

Const HWND_TOPMOST = -1

Global hwndHandle%
Global hMenuHandle%
Global CurrentWindowStyle%
Global sw = api_GetSystemMetrics(SM_CXSCREEN)
Global sh = api_GetSystemMetrics(SM_CYSCREEN)
Global rct.tRect = New tRect
rct\iLeft = 0
rct\iTop = 0
rct\iRight = sw
rct\iBottom = sh

hwndHandle= api_FindWindow("Blitz Runtime Class", "testStyle")

CurrentWindowStyle = api_GetWindowLong(hwndHandle, GWL_STYLE)

;CurrentWindowStyle% = CurrentWindowStyle% - WS_VISIBLE
;api_SetWindowLong(hwndHandle, GWL_STYLE, CurrentWindowStyle )
;api_InvalidateRect(0,rct,True);
 
 
;For t = 1 To 10000
;Print "test"
;Next

api_SetWindowPos(hwndhandle, HWND_TOPMOST, 50,50, 320, 480 ,SWP_SHOWWINDOW)

;CurrentWindowStyle = api_GetWindowLong(hwndHandle, GWL_STYLE)

;api_SetWindowLong(hwndHandle, GWL_STYLE, CurrentWindowStyle - WS_THICKFRAME  - WS_BORDER - WS_CAPTION)

;api_InvalidateRect(hwndHandle,rct,True)
Print "done... press a key to exit"

WaitKey()

End


Cool Information Eikon!

Thanks