How to open a window full client size?

Just starting out? Need help? Post your questions and find answers here.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

How to open a window full client size?

Post by Derek »

What I want is a window opened on the client area of the screen which is full size and not resizeable.

Trouble is unless I include the #pb_window_sizegadget in the second window command then the resize command that is used to position the window in the corner actually moves the window slightly to the left and up.

The reason for the resize command is because the #pb_screen_centered part is not actually centering on the client area but on the whole screen, but that's another story.

Also, this code seems to work if the taskbar is on the bottom or right of the screen but if it's on the top or left then a full screen sized window gets created.

Code: Select all

OpenWindow(0,0,0,200,200,"",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_Invisible) 

GetWindowRect_(WindowID(0),win.RECT) 

widthtoadd=(win\right-win\left)-200  
heighttoadd=(win\bottom-win\top)-200 

SystemParametersInfo_(#SPI_GETWORKAREA,0,@screen.RECT,0)
windowwidth = screen\right-widthtoadd
windowheight = screen\bottom-heighttoadd
CloseWindow(0)

OpenWindow(0,0,0,WindowWidth,WindowHeight,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)

;ResizeWindow(0,0,0,#PB_Ignore,#PB_Ignore)

Repeat

Until WaitWindowEvent()=#PB_Event_CloseWindow 
So what I'm asking is how do you create a window with borders that aren't half off screen which takes up only the client area and also takes into account where the taskbar is?

Or how do you stop a window from being resized when you have to include the #pb_window_sizegadget?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Does something like this work for you?

Code: Select all

SystemParametersInfo_(#SPI_GETWORKAREA,0,@screen.RECT,0) 
captionheight = GetSystemMetrics_(#SM_CYCAPTION)
borderwidth = GetSystemMetrics_(#SM_CXFIXEDFRAME)
borderheight = GetSystemMetrics_(#SM_CYFIXEDFRAME)
windowwidth = screen\right-screen\left-(borderwidth*2)
windowheight = screen\bottom-screen\top-captionheight-(borderheight*2)


OpenWindow(0,0,0,windowwidth,windowheight,"",#PB_Window_SystemMenu|#PB_Window_Maximize|#PB_Window_MaximizeGadget) 

Repeat 
  
Until WaitWindowEvent()=#PB_Event_CloseWindow 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

See if this works for you (test with all taskbar locations):

Code: Select all

SystemParametersInfo_(#SPI_GETWORKAREA,0,rcwa.RECT,0)

BorderWidth = GetSystemMetrics_(#SM_CXFIXEDFRAME)
CaptionHeight = GetSystemMetrics_(#SM_CYCAPTION)
WinWidth = rcwa\right - rcwa\left - (BorderWidth * 2)
WinHeight = rcwa\bottom - rcwa\top - CaptionHeight - (BorderWidth * 2)

OpenWindow(0,rcwa\left,rcwa\top,WinWidth,WinHeight,"void",#PB_Window_SystemMenu)

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
[edit]
God damn it Sparkman! Image
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Because:
Derek wrote:So what I'm asking is how do you create a window with borders that aren't half off screen which takes up only the client area and also takes into account where the taskbar is?
[edit]
Hah Mistrel! You deleted that post. Got ya! Image
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Or how do you stop a window from being resized when you have to include the #pb_window_sizegadget?
Example:

Code: Select all

Global wr.RECT

Procedure WinProc(hwnd, msg, wparam, lparam)
  result=#PB_ProcessPureBasicEvents
  Select msg
    Case #WM_MOVING, #WM_SIZING
      *dragrect.RECT = lparam
      With *dragrect
        \left   = wr\left
        \top    = wr\top
        \right  = wr\right
        \bottom = wr\bottom
      EndWith
    result = #True
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,640,480,"Sizable but.. nope",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
GetWindowRect_(WindowID(0), wr)
SetWindowCallback(@WinProc())
Repeat:Until WaitWindowEvent()=#WM_CLOSE
BERESHEIT
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Fluid Byte wrote:God damn it Sparkman!
T e m p e r . . . t e m p e r, Fluid Byte :P :wink: :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Fluid Byte wrote:Because:
Derek wrote:So what I'm asking is how do you create a window with borders that aren't half off screen which takes up only the client area and also takes into account where the taskbar is?
[edit]
Hah Mistrel! You deleted that post. Got ya! Image
I would have played with it further but when I realized that he wanted it to be taskbar friendly I had to withdraw. I don't use the Windows taskbar and therefore can't test the code. :roll:
Sparkie wrote:
Fluid Byte wrote:God damn it Sparkman!
T e m p e r . . . t e m p e r, Fluid Byte :P :wink: :)
I was tempted to reserve the first reply. I knew Sparkie would beat me to it!
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

This works OK within Window ME:

Code: Select all

; GUI metrics
Define winx, winy, winw, winh
winw = GetSystemMetrics_(#SM_CXFULLSCREEN)
winh = GetSystemMetrics_(#SM_CYFULLSCREEN)
winx = -3: winy = -3 ; Force the window to start as though maximised

; Create GUI
#winMain = 0
Define flags = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_TitleBar
OpenWindow(#winMain, winx, winy, winw, winh, "Test", flags)

; Eventloop
Repeat
Until WaitWindowEvent(#winMain)=#PB_Event_CloseWindow
End
Anthony Jordan
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

@Sparkman:

I find it a bit frightening that our codes are so similar. Even the variable names! :shock:

Well, the temper ....

I try to control it! ImageImageImageImage
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Fluid Byte wrote:I find it a bit frightening that our codes are so similar.
GMTA 8)
Fluid Byte wrote:Well, the temper .... I try to control it!
...and you're doing a damn good job....keep it up! :D
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Can anyone tell me why this isn't enough?

Code: Select all

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_Maximize)
CreateGadgetList(WindowID(0))


Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

@Sparkie, trouble is the gadgets don't go exactly into the corners.

Code: Select all

SystemParametersInfo_(#SPI_GETWORKAREA,0,@screen.RECT,0) 
captionheight = GetSystemMetrics_(#SM_CYCAPTION) 
borderwidth = GetSystemMetrics_(#SM_CXFIXEDFRAME) 
borderheight = GetSystemMetrics_(#SM_CYFIXEDFRAME) 
windowwidth = screen\right-screen\left-(borderwidth*2) 
windowheight = screen\bottom-screen\top-captionheight-(borderheight*2) 


OpenWindow(0,0,0,windowwidth,windowheight,"",#PB_Window_SystemMenu|#PB_Window_Maximize|#PB_Window_MaximizeGadget) 
CreateGadgetList(WindowID(0))
ButtonGadget(0,0,0,100,100,"")
ButtonGadget(1,windowwidth-100,0,100,100,"")
ButtonGadget(2,0,windowheight-100,100,100,"")
ButtonGadget(3,windowwidth-100,windowheight-100,100,100,"")

Repeat 
  
Until WaitWindowEvent()=#PB_Event_CloseWindow 
It's probably me just being padantic, I'm just trying to get it looking right. :lol:
Last edited by Derek on Sun Apr 13, 2008 9:49 am, edited 1 time in total.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

@Trond, the thing is that the maximised window doesn't quite reach the right hand side and also continues under the taskbar. At least on vista it does.

@Fluid, I'll give your code a try, thanks.

@netmaestro, thanks, if that works ok then that'll be the way I go. :D
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Here's the final bit of code.

Looks neat and tidy on mine anyway.

Thanks to everyone for the help. :D

Code: Select all

OpenWindow(0,0,0,200,200,"",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_Invisible) 

GetWindowRect_(WindowID(0),win.RECT) 
width_to_subtract=(win\right-win\left)-200  
height_to_subtract=(win\bottom-win\top)-200 

SystemParametersInfo_(#SPI_GETWORKAREA,0,@screen.RECT,0) 
windowwidth = (screen\right-screen\left)-width_to_subtract 
windowheight = (screen\bottom-screen\top)-height_to_subtract
ResizeWindow(0,screen\left,screen\top,WindowWidth,WindowHeight)
HideWindow(0,0)

Global wr.RECT 

Procedure WinProc(hwnd, msg, wparam, lparam) 
  result=#PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_MOVING, #WM_SIZING 
      *dragrect.RECT = lparam 
      With *dragrect 
        \left   = wr\left 
        \top    = wr\top 
        \right  = wr\right 
        \bottom = wr\bottom 
      EndWith 
    result = #True 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

GetWindowRect_(WindowID(0), wr) 
SetWindowCallback(@WinProc()) 

CreateGadgetList(WindowID(0))
ButtonGadget(0,0,0,100,100,"") 
ButtonGadget(1,windowwidth-100,0,100,100,"") 
ButtonGadget(2,0,windowheight-100,100,100,"") 
ButtonGadget(3,windowwidth-100,windowheight-100,100,100,"") 

Repeat 

Until WaitWindowEvent()=#PB_Event_CloseWindow 
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Derek wrote:@Trond, the thing is that the maximised window doesn't quite reach the right hand side and also continues under the taskbar. At least on vista it does.

@Fluid, I'll give your code a try, thanks.

@netmaestro, thanks, if that works ok then that'll be the way I go. :D
I see now what you want. You want to create a maximized window that isn't maximized. That's what I call evil, simply because there's a very good reason the borders are removed from maximized windows. The only reason have to have the borders anyways is if you want to resize the window, which you want to prohibit (that's also evil, because resize-border means: this window can be resized. It's like having a button that does nothing).
What I want is a window opened on the client area of the screen which is full size and not resizeable.
This done like this:

Code: Select all

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_Maximize | #PB_Window_SizeGadget)
CreateGadgetList(WindowID(0)) 

Repeat 
  Select WaitWindowEvent() 
    Case #PB_Event_CloseWindow 
      Break 
  EndSelect 
ForEver
Post Reply