Fenstergröße beim Borderless ändern

Anfängerfragen zum Programmieren mit PureBasic.
Benutzeravatar
DarkSoul
Beiträge: 689
Registriert: 19.10.2006 12:51

Fenstergröße beim Borderless ändern

Beitrag von DarkSoul »

hallo!

ich hab ein rahmenloses fenster, das ich jetzt gerne in der größe änderbar haben möchte (resizegadget klappt nicht)

hat da vielleicht jemand eine idee??
Bild
Benutzeravatar
nco2k
Beiträge: 892
Registriert: 08.09.2004 23:13

Beitrag von nco2k »

wie kommst du auf ResizeGadget(). :?

probier einfach mal ResizeWindow().

c ya,
nco2k
~|__/
..o.o.. <--- This is Einkaufswagen. Copy Einkaufswagen into your signature to help him on his way to world domination.
Benutzeravatar
DarkSoul
Beiträge: 689
Registriert: 19.10.2006 12:51

Beitrag von DarkSoul »

nee, resizegadget meine ich die konstante bei openwindow, die mit borderless nicht klappt. ich möchte, dass der user an Rand klickt und dass man das fenster größenverändern kann
Bild
Benutzeravatar
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

Beitrag von ts-soft »

>> ich möchte, dass der user an Rand klickt
Dein Fenster hat keinen Rand, also die Mousekoordinaten mußte laufend
prüfen, wenn er so und so dicht am rand ist und drückt, dann das Fenster
resizen. Sehr aufwendig :mrgreen:
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.
Bild
Benutzeravatar
Kiffi
Beiträge: 10714
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Beitrag von Kiffi »

wir sind zwar hier im Anfängerforum und ich liefere ungern vorgekauten
Code, aber in diesem Fall mache ich eine Ausnahme:

Code: Alles auswählen

Enumeration
  #frmResizeExample
  #cmdTopLeft
  #cmdTopRight
  #cmdLeft
  #cmdTop
  #cmdRight
  #cmdBottom
  #cmdBottomLeft
  #cmdBottomRight
  #cmdExit 
EndEnumeration

Procedure.l IsMouseOverGadget(Gadget.l)
  
  Protected wnd.l
  Protected re.RECT
  Protected pt.POINT
  
  wnd=GadgetID(Gadget)
  If wnd
    GetWindowRect_(wnd,re)
    GetCursorPos_(pt)
    ProcedureReturn PtInRect_(re,pt\x,pt\y)
  EndIf
  
EndProcedure

Procedure ResizeGadgets()
  
  Protected x.l, y.l, w.l, h.l
  
  ; Topleft braucht keinen resize
  ; [...]
  
  ; TopRight
  x = WindowWidth(#frmResizeExample) - GadgetWidth(#cmdTopRight)
  y = 0
  w = #PB_Ignore
  h = #PB_Ignore
  ResizeGadget(#cmdTopRight, x, y, w, h)
  
  ; Left
  x = 0
  y = GadgetHeight(#cmdTopLeft)
  w = #PB_Ignore
  h = WindowHeight(#frmResizeExample) - GadgetHeight(#cmdTopLeft) - GadgetHeight(#cmdBottomLeft)
  ResizeGadget(#cmdLeft, x, y, w, h)
  
  ; Top
  x = GadgetWidth(#cmdTopLeft)
  y = 0
  w = WindowWidth(#frmResizeExample) - GadgetWidth(#cmdTopLeft) - GadgetWidth(#cmdTopRight) 
  h = #PB_Ignore
  ResizeGadget(#cmdTop, x, y, w, h)
  
  ; Right
  x = WindowWidth(#frmResizeExample) - GadgetWidth(#cmdRight)
  y = GadgetHeight(#cmdTopRight)
  w = #PB_Ignore
  h = WindowHeight(#frmResizeExample) - GadgetHeight(#cmdTopRight) - GadgetHeight(#cmdBottomRight) 
  ResizeGadget(#cmdRight, x, y, w, h)
  
  ; Bottom
  x = GadgetWidth(#cmdBottomLeft)
  y = WindowHeight(#frmResizeExample) - GadgetHeight(#cmdBottom)
  w = WindowWidth(#frmResizeExample) - GadgetWidth(#cmdBottomLeft)- GadgetWidth(#cmdBottomRight)
  h = #PB_Ignore
  ResizeGadget(#cmdBottom, x, y, w, h)
  
  ; BottomLeft
  x = 0
  y = WindowHeight(#frmResizeExample) - GadgetHeight(#cmdBottomLeft)
  w = #PB_Ignore
  h = #PB_Ignore
  ResizeGadget(#cmdBottomLeft, x, y, w, h)
  
  ; BottomRight
  x = WindowWidth(#frmResizeExample) - GadgetWidth(#cmdBottomRight)
  y = WindowHeight(#frmResizeExample) - GadgetHeight(#cmdBottomRight)
  w = #PB_Ignore
  h = #PB_Ignore
  ResizeGadget(#cmdBottomRight, x, y, w, h)
  
  ; Exit-Button
  
  x = GadgetWidth(#cmdLeft)
  y = GadgetHeight(#cmdTop)
  w = WindowWidth(#frmResizeExample) - GadgetWidth(#cmdLeft) - GadgetWidth(#cmdRight)
  h = WindowHeight(#frmResizeExample) - GadgetHeight(#cmdTop) - GadgetHeight(#cmdBottom)
  ResizeGadget(#cmdExit, x, y, w, h)
  
EndProcedure

Procedure ResizeBorderlessWindow(ResizeWhat.l)
  ReleaseCapture_()
  SendMessage_(WindowID(#frmResizeExample), #WM_NCLBUTTONDOWN, ResizeWhat, 0)  
EndProcedure

If OpenWindow(0, #PB_Ignore, #PB_Ignore, 200, 200, "", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
  
  If CreateGadgetList(WindowID(#frmResizeExample))
    
    ButtonGadget(#cmdTopLeft, 0, 0, 30, 30, "tl")
    ButtonGadget(#cmdTopRight, 0, 0, 30, 30, "tr")
    
    ButtonGadget(#cmdLeft, 0, 0, 30, 0, "l")
    ButtonGadget(#cmdTop, 0, 0, 0, 30, "t")
    ButtonGadget(#cmdRight, 0, 0, 30, 0, "r")
    ButtonGadget(#cmdBottom, 0, 0, 0, 30, "b")
    
    ButtonGadget(#cmdBottomLeft, 0, 0, 30, 30, "bl")
    ButtonGadget(#cmdBottomRight, 0, 0, 30, 30, "br")
    
    ButtonGadget(#cmdExit, 25, 25, 50, 40, "Exit")
    
    ResizeGadgets()
    
    Repeat
      
      WWE = WaitWindowEvent()
      EG  = EventGadget()
      
      Select WWE 
        
        Case #WM_LBUTTONDOWN
          
          If IsMouseOverGadget(#cmdTopLeft)         : ResizeBorderlessWindow(#HTTOPLEFT)
          ElseIf IsMouseOverGadget(#cmdTopRight)    : ResizeBorderlessWindow(#HTTOPRIGHT)
          ElseIf IsMouseOverGadget(#cmdTop)         : ResizeBorderlessWindow(#HTTOP)
          ElseIf IsMouseOverGadget(#cmdLeft)        : ResizeBorderlessWindow(#HTLEFT)
          ElseIf IsMouseOverGadget(#cmdRight)       : ResizeBorderlessWindow(#HTRIGHT)
          ElseIf IsMouseOverGadget(#cmdBottom)      : ResizeBorderlessWindow(#HTBOTTOM)
          ElseIf IsMouseOverGadget(#cmdBottomLeft)  : ResizeBorderlessWindow(#HTBOTTOMLEFT)
          ElseIf IsMouseOverGadget(#cmdBottomRight) : ResizeBorderlessWindow(#HTBOTTOMRIGHT)
          ElseIf IsMouseOverGadget(#cmdExit)        : Quit = #True
          EndIf
          
        Case #PB_Event_SizeWindow
          ResizeGadgets()
          
      EndSelect
      
    Until Quit = #True
    
  EndIf
  
EndIf
Grüße ... Kiffi
a²+b²=mc²
Benutzeravatar
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

Beitrag von ts-soft »

Schöner Code Peter :wink:
Wenn man jetzt vor ResizeGadget() noch folgendes einfügt, kommts noch besser :D

Code: Alles auswählen

    Define i.l
    For i = 1 To 8
      HideGadget(i, #True)
    Next
    
Gruß
Thomas
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.
Bild
Benutzeravatar
#NULL
Beiträge: 2238
Registriert: 20.04.2006 09:50

Beitrag von #NULL »

ich hab das auch nochmal versucht.
man hat jetzt auch die resize-cursor und kann eine fenster-mindestgröße festlegen (#WinWidthMin und #WinHeightMin).
#touchWidth ist die breite des randes.


Code: Alles auswählen

#N=2
#S=4
#O=8
#W=16
#touchWidth=6
#WinWidthMin=150
#WinHeightMin=30

Global dmx.l ;DesktopMouseX
Global dmy.l ;DesktopMouseY
Global wmx.l ;WindowMouseX
Global wmy.l ;WindowMouseY

Global hC_N=LoadCursor_(0,#IDC_SIZENS)    ; cursor |
Global hC_NO=LoadCursor_(0,#IDC_SIZENESW) ; cursor /
Global hC_O=LoadCursor_(0,#IDC_SIZEWE)    ; cursor -
Global hC_SO=LoadCursor_(0,#IDC_SIZENWSE) ; cursor \

Declare.l getResizeFlag()
Declare setResizeCursor(flag.l)
Declare resizeWin(flag.l)
Declare refreshSize()

ww=200
wh=300
hWin=OpenWindow(0, 50,50, ww,wh, "", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
CreateGadgetList(hWin)
ButtonGadget(0, ww-#touchWidth-50, #touchWidth, 50,20, "exit")
ButtonGadget(1, ww-#touchWidth-50-4-50, #touchWidth, 50,20, "move")
;hC_Default=GetCursor_()



;######################### MAIN #########
Repeat
  event=WaitWindowEvent(200)

  dmx=DesktopMouseX()
  dmy=DesktopMouseY()
  wmx=WindowMouseX(0)
  wmy=WindowMouseY(0)
  
  eg=EventGadget()
  Select event
    Case #PB_Event_CloseWindow
      quit=1
    Case #PB_Event_Gadget
      Select eg
        Case 0 ;exit-button
          quit=1
        Case 1 ;move-button
          ;moveWin=1
      EndSelect
    Case #WM_LBUTTONDOWN
      gaX=GadgetX(1) ;(move-button metrics)
      gaY=GadgetY(1)
      gaW=GadgetWidth(1)
      gaH=GadgetHeight(1)
      If wmx>=gaX And wmx<gaX+gaW And wmy>=gaY And wmy<gaY+gaH
        ReleaseCapture_()
        SendMessage_(hWin, #WM_NCLBUTTONDOWN, #HTCAPTION, 0) 
      EndIf
    Case #PB_Event_SizeWindow
      refreshSize()
  EndSelect

  If Not GetAsyncKeyState_(#VK_LBUTTON)&(1<<15)
    resFlag=getResizeFlag()
  EndIf
  setResizeCursor(resFlag)
  If resFlag
    resizeWin(resFlag)
  EndIf

Until quit
;########################################



Procedure.l getResizeFlag()
  Protected ret.l
  Protected wx=WindowX(0)
  Protected wy=WindowY(0)
  Protected ww=WindowWidth(0)
  Protected wh=WindowHeight(0)

  If dmx >= wx And dmx < wx+#touchWidth
    ret|#W
  ElseIf dmx < wx+ww And dmx > wx+ww-#touchWidth
    ret|#O
  EndIf

  If dmy >= wy And dmy < wy+#touchWidth
    ret|#N
  ElseIf dmy < wy+wh And dmy > wy+wh-#touchWidth
    ret|#S
  EndIf

  ProcedureReturn ret
EndProcedure


Procedure setResizeCursor(flag.l)
  If flag=#N Or flag=#S
      SetCursor_(hC_N)
  ElseIf flag=#W Or flag=#O
      SetCursor_(hC_O)
  ElseIf flag=(#W|#N) Or flag=(#S|#O)
      SetCursor_(hC_SO)
  ElseIf flag=(#S|#W) Or flag=(#N|#O)
      SetCursor_(hC_NO)
  EndIf
EndProcedure


Procedure resizeWin(flag.l)
  Protected wx=WindowX(0)
  Protected wy=WindowY(0)
  Protected ww=WindowWidth(0)
  Protected wh=WindowHeight(0)
  Protected x=wx
  Protected y=wy
  Protected w=ww
  Protected h=wh

  If GetAsyncKeyState_(#VK_LBUTTON)&(1<<15)
    If flag&#W
      x=dmx
      w=ww+(wx-x)
    ElseIf flag&#O
      x=wx
      w=dmx-wx
    EndIf
    
    If flag&#N
      y=dmy
      h=wh+(wy-y)
    ElseIf flag&#S
      y=wy
      h=dmy-wy
    EndIf
    
    If w<#WinWidthMin
      w=#WinWidthMin
      x=wx
    EndIf
    If h<#WinHeightMin
      h=#WinHeightMin
      y=wy
    EndIf
    ResizeWindow(0 ,x,y,w,h)
  EndIf
  
EndProcedure


Procedure refreshSize()
  Protected ww=WindowWidth(0)
  Protected wh=WindowHeight(0)
  ResizeGadget(0, ww-#touchWidth-50, #touchWidth, 50,20) ; exit-button
  ResizeGadget(1, ww-#touchWidth-50-4-50, #touchWidth, 50,20) ; move-button
EndProcedure
my pb stuff..
Bild..jedenfalls war das mal so.
Benutzeravatar
AND51
Beiträge: 5220
Registriert: 01.10.2005 13:15

Beitrag von AND51 »

@ Biedermeier:
#PB_Window_ResizeGadget und #PB_Window_BorderLess sind wie #Feuer und #Wasser oder #Katze und #Maus... Um ein fenster zu resizen, bedarf es einer #Titelleiste. :wink:
PB 4.30

Code: Alles auswählen

Macro Happy
 ;-)
EndMacro

Happy End
Benutzeravatar
edel
Beiträge: 3667
Registriert: 28.07.2005 12:39
Computerausstattung: GameBoy
Kontaktdaten:

Beitrag von edel »

So geht es auch :

Code: Alles auswählen

hwnd = OpenWindow(0,0,0,300,300,"",#WS_SIZEBOX|#PB_Window_BorderLess)

Repeat
  event = WaitWindowEvent()
  
Until event = 16 ; ohne titelleiste wird es schwer :D
a14xerus
Beiträge: 1440
Registriert: 14.12.2005 15:51
Wohnort: Aachen

Beitrag von a14xerus »

edel hat geschrieben:So geht es auch :

Code: Alles auswählen

hwnd = OpenWindow(0,0,0,300,300,"",#WS_SIZEBOX|#PB_Window_BorderLess)

Repeat
  event = WaitWindowEvent()
  
Until event = 16 ; ohne titelleiste wird es schwer :D
son code is doch mal was , womit man was anfangen kann :allright:
Antworten