Wie abfragen, ob (OS-)Fenster maximiert ist?
Wie abfragen, ob (OS-)Fenster maximiert ist?
Achtung! Der Threadtitel wurde mehrfach geändert. Ursprünglicher Titel: Fenster verschieben auf APIisch
Hi.
Mit SetWindowPos_ () oder MoveWindow_ () kann man die Göße eines gesamten Fensters setzen. Dabei wird der Rahmen mitberechnet, heißt: die angegebene Größe wird zu (Fenstergröße + Rahmen).
Nun weiß ich, dass unter Window 10 die Rahmen nur noch 1 oder 2 Pixel breit sind (bis auf die Titelzeile). Ich möchte aber genau sein und frage Euch deshalb nach einer Lösung, wie man nur die ClientArea in Ihrer Größe verändern kann.
... So, wie es PureBasic auch macht, bei seinen eigenen Fenstern.
Hi.
Mit SetWindowPos_ () oder MoveWindow_ () kann man die Göße eines gesamten Fensters setzen. Dabei wird der Rahmen mitberechnet, heißt: die angegebene Größe wird zu (Fenstergröße + Rahmen).
Nun weiß ich, dass unter Window 10 die Rahmen nur noch 1 oder 2 Pixel breit sind (bis auf die Titelzeile). Ich möchte aber genau sein und frage Euch deshalb nach einer Lösung, wie man nur die ClientArea in Ihrer Größe verändern kann.
... So, wie es PureBasic auch macht, bei seinen eigenen Fenstern.
Zuletzt geändert von es_91 am 05.11.2014 16:50, insgesamt 7-mal geändert.
Re: Fensterkoordinatensetzen auf APIisch
Wir wärs mit GetWindowRect_() und GetClientRect_() ?
Code: Alles auswählen
lpRect.rect
If OpenWindow(0, 300, 400, 200, 100, "test", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
GetWindowRect_(WindowID(0), lpRect)
Debug "Pos x: " + Str(lpRect\left)
Debug "Pos y: " + Str(lpRect\top)
Debug "Width: " + Str(lpRect\right - lpRect\left)
Debug "Hight: " + Str(lpRect\bottom - lpRect\top)
GetClientRect_(WindowID(0), lpRect)
Debug "Pos x: " + Str(lpRect\left)
Debug "Pos y: " + Str(lpRect\top)
Debug "Width: " + Str(lpRect\right - lpRect\left)
Debug "Hight: " + Str(lpRect\bottom - lpRect\top)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
PureBasic 5.46 LTS (Windows x86/x64) | windows 10 x64 Oktober failure
Re: Fensterkoordinatensetzen auf APIisch
Gibt es denn eine SetClientRect_ ()-Funktion?
Bedenke: ich will keine Fenster von PureBasic in deren Größe verändern, sondern "fremde"!
Bedenke: ich will keine Fenster von PureBasic in deren Größe verändern, sondern "fremde"!
- ts-soft
- Beiträge: 22292
- Registriert: 08.09.2004 00:57
- Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel - Wohnort: Berlin
Re: Fensterkoordinatensetzen auf APIisch
Meinste:
// edit
So macht der Code mehr Sinn
Code: Alles auswählen
Define rect.RECT
rect\right = 600
rect\bottom = 200
AdjustWindowRect_(@rect, #WS_BORDER | #WS_CAPTION, 0)
Debug rect\right
Debug rect\bottom
So macht der Code mehr Sinn

Zuletzt geändert von ts-soft am 27.10.2014 16:45, insgesamt 1-mal geändert.
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.

Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.

Re: Fensterkoordinatensetzen auf APIisch
Alles klar, ich ermittle also die "echten" RECT-Daten über AdjustWindowRect_ () und setze diese dann mit SetWindowPos_ (). Dankeschön! 

- CodeCommander
- Beiträge: 213
- Registriert: 02.03.2014 16:06
~ DELETE ~
Zuletzt geändert von CodeCommander am 18.01.2015 14:40, insgesamt 1-mal geändert.
~ DELETE ~
- ts-soft
- Beiträge: 22292
- Registriert: 08.09.2004 00:57
- Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel - Wohnort: Berlin
Re: Fensterkoordinatensetzen auf APIisch
Ich hatte vorhin recht wenig Zeit, aber du bist ja von allein drauf gekommen 

PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.

Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.

Re: Koordinaten fremder Fenster setzen
/* Titel wurde geändert */
Hallo. Ich habe ein Program geschrieben, mit dem ein Fenster automatisch in der Mitte des Bildschirms angezeigt wird und eine bestimmte Größe erhält. Ich hatte gehofft, damit alle meine Fensterchen auf eine Standartgröße setzen zu können, jedoch (bei den meisten Anwendungen) ohne Erfolg.
Folgende Fenster kann ich mit unten stehendem Code in ihrer Größe verändern: Notepad (Editor) und PureBasic IDE.
(Der Teil, in dem die Desktopkoordinaten abgefragt werden musste sein, da DesktopWidth () und DesktopHeight () bei meinem Arbeitsrechner nicht mehr funktionieren (engl.).)
Jetzt funktioniert dies allerdings nur bei den genannten Programmen. Warum geht das nicht auch bei anderen Anwendungen, wie zum Beispiel Word, Excel oder Notepad++?
Hallo. Ich habe ein Program geschrieben, mit dem ein Fenster automatisch in der Mitte des Bildschirms angezeigt wird und eine bestimmte Größe erhält. Ich hatte gehofft, damit alle meine Fensterchen auf eine Standartgröße setzen zu können, jedoch (bei den meisten Anwendungen) ohne Erfolg.
Folgende Fenster kann ich mit unten stehendem Code in ihrer Größe verändern: Notepad (Editor) und PureBasic IDE.
Code: Alles auswählen
;
; SetProperWindowCoordinates.pb
;
; Author: Enrico Seidel
; Date: 10/28/2014
; Demo: no
#WindowWidth = 1008
#WindowHeight = 544
;{ Calculating desktop measures savely
DevMode. DEVMODE
DevMode\ dmSize = SizeOf (DEVMODE)
EnumDisplaySettings_ (#Null, #ENUM_CURRENT_SETTINGS, DevMode)
DesktopWidth = DevMode\ dmPelsWidth
DesktopHeight = DevMode\ dmPelsHeight
;}
WindowRect. RECT
SolidWindowRect. RECT
WindowRect\ Bottom = (DesktopHeight + #WindowHeight) / 2
WindowRect\ Left = (DesktopWidth - #WindowWidth) / 2
WindowRect\ Top = (DesktopHeight - #WindowHeight) / 2
WindowRect\ Right = (DesktopWidth + #WindowWidth) / 2
SolidWindowRect = WindowRect
WindowName. s = InputRequester("Fenster", "Titel des Fensters:", "")
If WindowName
WindowHandle = FindWindow_ (0, WindowName)
AdjustWindowRect_ (WindowRect, #WS_SYSMENU| #WS_CAPTION, #Null)
WindowRect\ Bottom = (DesktopHeight + SolidWindowRect\ Bottom - SolidWindowRect\ Top) / 2
WindowRect\ Left = (DesktopWidth - SolidWindowRect\ Right + SolidWindowRect\ Left) / 2
WindowRect\ Top = (DesktopHeight - SolidWindowRect\ Bottom + SolidWindowRect\ Top) / 2
WindowRect\ Right = (DesktopWidth + SolidWindowRect\ Right - SolidWindowRect\ Left) / 2
Debug SetWindowPos_ (WindowHandle, #Null, WindowRect\ Left, WindowRect\ Top, WindowRect\ Right - WindowRect\ Left, WindowRect\ Bottom - WindowRect\ Top, #Null)
EndIf
Jetzt funktioniert dies allerdings nur bei den genannten Programmen. Warum geht das nicht auch bei anderen Anwendungen, wie zum Beispiel Word, Excel oder Notepad++?
Re: Koordinaten von Fenstern verändern
Zuverlässiger wäre es so...
Code: Alles auswählen
;
; SetProperWindowCoordinates.pb
;
; Author: Enrico Seidel
; Date: 10/28/2014
; Demo: no
Procedure ListVisibleWindows()
Protected hwnd, txt.s
hwnd = GetWindow_(GetDesktopWindow_(), #GW_CHILD)
While hwnd ! 0
If IsWindowVisible_(hwnd)
txt = Space(#MAX_PATH)
GetWindowText_(hwnd, txt, #MAX_PATH)
If LCase(txt) <> "start" And LCase(txt) <> "program manager" And txt <> ""
Debug "handle: " + hwnd + Chr(9) + txt
EndIf
EndIf
hwnd = GetWindow_(hwnd, #GW_HWNDNEXT)
Wend
EndProcedure
#WindowWidth = 1008
#WindowHeight = 544
;{ Calculating desktop measures savely
DevMode. DEVMODE
DevMode\ dmSize = SizeOf (DEVMODE)
EnumDisplaySettings_ (#Null, #ENUM_CURRENT_SETTINGS, DevMode)
DesktopWidth = DevMode\ dmPelsWidth
DesktopHeight = DevMode\ dmPelsHeight
;}
WindowRect. RECT
SolidWindowRect. RECT
WindowRect\ Bottom = (DesktopHeight + #WindowHeight) / 2
WindowRect\ Left = (DesktopWidth - #WindowWidth) / 2
WindowRect\ Top = (DesktopHeight - #WindowHeight) / 2
WindowRect\ Right = (DesktopWidth + #WindowWidth) / 2
SolidWindowRect = WindowRect
ListVisibleWindows()
WindowHandle = Val(InputRequester("Fenster", "Handle des Fensters:", ""))
If WindowHandle
If IsIconic_(WindowHandle)
ShowWindow_(WindowHandle, #SW_RESTORE)
EndIf
AdjustWindowRect_ (WindowRect, #WS_SYSMENU| #WS_CAPTION, #Null)
WindowRect\ Bottom = (DesktopHeight + SolidWindowRect\ Bottom - SolidWindowRect\ Top) / 2
WindowRect\ Left = (DesktopWidth - SolidWindowRect\ Right + SolidWindowRect\ Left) / 2
WindowRect\ Top = (DesktopHeight - SolidWindowRect\ Bottom + SolidWindowRect\ Top) / 2
WindowRect\ Right = (DesktopWidth + SolidWindowRect\ Right - SolidWindowRect\ Left) / 2
Debug SetWindowPos_ (WindowHandle, #Null, WindowRect\ Left, WindowRect\ Top, WindowRect\ Right - WindowRect\ Left, WindowRect\ Bottom - WindowRect\ Top, #Null)
EndIf
[Programm] Fenster schön mittig anzeigen lassen
Ja! Vielen Dank, chi. 
Hier ein verbessertes Programm, was die Änderungen von chi verwendet:
//updated: 17:14 Uhr
Try it! 
ToDo:
- Unterstützung für den k/Ä-Button hinzufügen
- Programme wie WinAmp zur Kooperation bringen
- diverse Verbesserungen...

Hier ein verbessertes Programm, was die Änderungen von chi verwendet:
//updated: 17:14 Uhr
Code: Alles auswählen
;
; SetProperWindowCoordinates3.pb
;
; Author: Enrico Seidel
; Date: 10/30/2014
; Demo: no
Window = OpenWindow (#PB_Any, 0, 0, 315, 56, "Auswahl", #PB_Window_SystemMenu| #PB_Window_ScreenCentered)
Button1 = ButtonGadget (#PB_Any, 13, 17, 50, 22, "16 : 9")
Button2 = ButtonGadget (#PB_Any, 73, 17, 50, 22, "16 : 10")
Button3 = ButtonGadget (#PB_Any, 133, 17, 50, 22, "4 : 3")
Button4 = ButtonGadget (#PB_Any, 193, 17, 50, 22, "5 : 4")
Button5 = ButtonGadget (#PB_Any, 253, 17, 50, 22, "k/Ä")
DisableGadget (Button5, #True)
Repeat
Select WaitWindowEvent ()
Case #PB_Event_Gadget
Select EventGadget ()
Case Button1
H = 360
Break
Case Button2
H = 400
Break
Case Button3
H = 480
Break
Case Button4
H = 512
Break
Case Button5
OnlyCenter = #True
Break
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
CloseWindow (Window)
Procedure ListVisibleWindows ()
Protected HWnd, Txt.s
Shared ListIcon
HWnd = GetWindow_ (GetDesktopWindow_ (), #GW_CHILD)
While Not HWnd = #Null
If IsWindowVisible_ (HWnd)
txt = Space (#MAX_PATH)
GetWindowText_ (HWnd, Txt, #MAX_PATH)
If LCase (Txt) <> "start" And LCase (Txt) <> "program manager" And Txt <> ""
AddGadgetItem (ListIcon, -1, Str (HWnd) + #LF$ + Txt)
EndIf
EndIf
hwnd = GetWindow_ (HWnd, #GW_HWNDNEXT)
Wend
EndProcedure
Window = OpenWindow (#PB_Any, #PB_Ignore, #PB_Ignore, 630, 340, "Visible Windows on Desktop", #PB_Window_SystemMenu| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered)
ListIcon = ListIconGadget (#PB_Any, 15, 10, 600, 290, "Handle", 125, #PB_ListIcon_FullRowSelect)
AddGadgetColumn(ListIcon, 1, "Title", 300)
Button = ButtonGadget (#PB_Any, 535, 310, 80, 20, "Aktualisieren")
;{ Calculating desktop measures savely
DevMode. DEVMODE
DevMode\ dmSize = SizeOf (DEVMODE)
EnumDisplaySettings_ (#Null, #ENUM_CURRENT_SETTINGS, DevMode)
DesktopWidth = DevMode\ dmPelsWidth
DesktopHeight = DevMode\ dmPelsHeight
;}
ListVisibleWindows()
Repeat
Select WaitWindowEvent ()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_SizeWindow
ResizeGadget (ListIcon, 15, 10, WindowWidth (Window) - 30, WindowHeight (Window) - 50)
ResizeGadget (Button, WindowWidth (Window) - 95, WindowHeight (Window) - 30, #PB_Ignore, #PB_Ignore)
Case #PB_Event_Gadget
Select EventGadget ()
Case ListIcon
If EventType () = #PB_EventType_LeftDoubleClick
WindowHandle = Val (GetGadgetItemText (ListIcon, GetGadgetState (ListIcon), #Null))
If WindowHandle
If IsIconic_ (WindowHandle)
ShowWindow_ (WindowHandle, #SW_RESTORE)
EndIf
If OnlyCenter
Rect. RECT
GetClientRect_ (WindowHandle, Rect)
WindowWidth = Rect\ Right
WindowHeight = Rect\ Bottom
Else
WindowWidth = 630 * (1.0 * DesktopWidth / 640)
WindowHeight = 1.0 * WindowWidth / 630 * (336.0 / 360 * H)
EndIf
WindowRect. RECT
WindowRect\ Bottom = (DesktopHeight + WindowHeight) / 2
WindowRect\ Left = (DesktopWidth - WindowWidth) / 2
WindowRect\ Top = (DesktopHeight - WindowHeight) / 2
WindowRect\ Right = (DesktopWidth + WindowWidth) / 2
SolidWindowRect. RECT
SolidWindowRect = WindowRect
AdjustWindowRect_ (WindowRect, #WS_SYSMENU| #WS_CAPTION, #Null)
WindowRect\ Bottom = (DesktopHeight + SolidWindowRect\ Bottom - SolidWindowRect\ Top) / 2
WindowRect\ Left = (DesktopWidth - SolidWindowRect\ Right + SolidWindowRect\ Left) / 2
WindowRect\ Top = (DesktopHeight - SolidWindowRect\ Bottom + SolidWindowRect\ Top) / 2
WindowRect\ Right = (DesktopWidth + SolidWindowRect\ Right - SolidWindowRect\ Left) / 2
SetWindowPos_ (WindowHandle, #Null, WindowRect\ Left, WindowRect\ Top, WindowRect\ Right - WindowRect\ Left, WindowRect\ Bottom - WindowRect\ Top, #Null)
EndIf
EndIf
Case Button
ClearGadgetItems (ListIcon)
ListVisibleWindows ()
EndSelect
EndSelect
ForEver

ToDo:
- Unterstützung für den k/Ä-Button hinzufügen
- Programme wie WinAmp zur Kooperation bringen
- diverse Verbesserungen...