Page 1 of 1

I need help using ResizeWindow

Posted: Sat May 07, 2022 10:10 pm
by percy_b
Hi Everyone,
I'm trying to reposition a window, which has been deliberately placed at the X/Y coordinates of 0 and 0. However, I am not getting the results that I expected. Any advice?

Code: Select all

#MyWindow = 1
Define iThisWindowWidth.i
Define iThisWindowHeight.i
Define iMonitorXcoordinate.i
Define iDesktopHeight.i
Define iDesktopWidth.i
Define iMonitorYcoordinate.i
Define iEvent.i

If OpenWindow(#MyWindow, 0, 0, 400, 300, "", #PB_Window_SystemMenu)
  If GetWindowState(#MyWindow) = #PB_Window_Normal
	  iThisWindowWidth = WindowWidth(#MyWindow)
	  iThisWindowHeight = WindowHeight(#MyWindow)
		  
	  If  ExamineDesktops()
      		  iDesktopHeight = DesktopHeight(0)
      		  iDesktopWidth = DesktopWidth(0)
		  iMonitorXcoordinate = Round( ( iDesktopHeight / 2 ) - ( WindowHeight(#MyWindow) / 2 ), 0)
		  iMonitorYcoordinate = Round( ( iDesktopWidth / 2 ) - ( WindowWidth(#MyWindow) / 2 ), 0)
			  
		  ResizeWindow(#MyWindow, iMonitorXcoordinate, iMonitorYcoordinate, iThisWindowWidth, iThisWindowHeight) 
	  EndIf 	  
		Repeat
		  iEvent = WindowEvent()
		  
		  If iEvent <> 0 ; All events are assessed to display the coordinates of the mouse.
			  SetWindowTitle(#MyWindow, "Position of the mouse on the window: " + Str(WindowMouseX(#MyWindow)) + "," + Str(WindowMouseX(#MyWindow))) 
		  Else      
			  Delay(1) ; Free the CPU for the multitasking
		  EndIf
		Until iEvent = #PB_Event_CloseWindow
	EndIf 
EndIf

Re: I need help using ResizeWindow

Posted: Sat May 07, 2022 11:44 pm
by AZJIO
iMonitorXcoordinate = Round( ( iDesktopHeight / 2 ) - ( WindowHeight(#MyWindow) / 2 ), 0)

Re: I need help using ResizeWindow

Posted: Sat May 07, 2022 11:56 pm
by percy_b
Thank you.