Graphics window fix

BlitzPlus Forums/BlitzPlus Programming/Graphics window fix

Eikon(Posted 2004) [#1]
If you've ever wanted to have a Graphics window with a working minimize and close button, heres the fix:

Download bwin.dll

Userlib:
; bwin DLL by Eikon
.lib "bwin.dll"
win_Close%(hWnd%)

.lib "user32.dll"
GetActiveWindow%()
SetWindowLong%(hWnd%,Val%,Long%):"SetWindowLongA"
GetWindowLong%(hWnd%,Val%):"GetWindowLongA"
SetWindowPos%(hWnd%,hAfter%,x%,y%,cx%,cy%,flags%)

B+ Code:
AppTitle "Proper Graphics window by Eikon"
Graphics 640, 480, 16, 2
SetBuffer BackBuffer()

Const GWL_STYLE        = -16
Const WS_MINIMIZE      = $00020000
Const WS_SYSMENU       = $00080000
Const SWP_NOSIZE       = $0001
Const SWP_NOMOVE       = $0002
Const SWP_FRAMECHANGED = $0020

hWnd = GetActiveWindow()              
Style = GetWindowLong(hWnd, GWL_STYLE) 
SetWindowLong hWnd, GWL_STYLE, Style Or WS_MINIMIZE Or WS_SYSMENU
SetWindowPos hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_FRAMECHANGED

c_Time = MilliSecs()
Repeat

If MilliSecs() >= c_Time + 100 Then ; Poll the close
	If win_Close(hWnd) Then End
	c_Time = MilliSecs() 
EndIf

Until KeyDown(1)
End

Normally Graphics windows in B+ have no titlebar buttons at all.


Kuron(Posted 2004) [#2]
Eikon, this would be a life saver. Thanks a million.


Wiebo(Posted 2004) [#3]
aaaaaaaah, very nice. thanks Eikon.


Grisu(Posted 2004) [#4]
Great stuff!

Already said that at bc.com, but one can't say it often enough! :)


Eikon(Posted 2004) [#5]
Thanks for the support guys, good to know others can use this.

@Grisu: I did some win_Close testing and its accurate on 98/2k and even XP's luna theme. I think a small warning of "Avoid bulky themes in win mode" would suffice. Too bad I can't get an event for the button or it would be much easier. I'll be sharing CardWar impressions and sending you M+ in an email soon.


Grisu(Posted 2004) [#6]
Eikon, I had an idea with the maximise button, can you make a detection for this as well in your dll?
It must not be "working" (=streching screen), I only would need a detection flag.

So I could bind it to "Switch to fullscreen" in CW. That would be some good usage I guess.


Hotcakes(Posted 2004) [#7]
Just for future reference, try to remember to use 'doesn't have to be' instead of 'must not be'... must not tends to mean something else in English. =]


Grisu(Posted 2004) [#8]
Thank you for pointing out Hotcakes.
Will do better in the future! ;)

Let's hope Eikon always understands me the right way... :)


DjBigWorm(Posted 2005) [#9]
This Is Way Awsome!! I Know it is late reply.
Thanks A Million Eikon


Grey Alien(Posted 2005) [#10]
The example above fails for me with "User lib function not found", presumably because the proper dll names have been left off the declarations for GetActiveWindow and SetWindowPos (unless I am being dumb), they should be:

GetActiveWindow%():"GetActiveWindow"
SetWindowLong%(hWnd%,Val%,Long%):"SetWindowLongA"
GetWindowLong%(hWnd%,Val%):"GetWindowLongA"
SetWindowPos%(hWnd%,hAfter%,x%,y%,cx%,cy%,flags%):"SetWindowPos"


When fixed it does work very well! Thanks loads.

[Edit] Hmm the close detection only works for the X button, it doesn't work for Alt+F4 or if the user clicks the system menu and selects close. Any ideas?

[Edit2] Also it is a shame to have to include another .dll just to detect if the X is clicked. Surely there is another way to do this with user32 or kernal32 etc?