Page 1 of 1
					
				SetParent_() messes up my Child Window alignment
				Posted: Thu Apr 23, 2015 2:07 pm
				by Thunder93
				Hi. I suppose It's normal when using SetParent() WinAPI, the child window goes off centered from the parent window?
Code: Select all
If OpenWindow(0, 30, 120, 500, 600, "Parent Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget |#PB_Window_MaximizeGadget) And
   OpenWindow(1, 0, 0, 200, 200, "Child Window", #PB_Window_WindowCentered)
  
    SetParent_(WindowID(1), WindowID(0))  ; REM Line to see it perfectly centered over initial Window.
  
  Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow  
EndIf
 
			 
			
					
				Re: SetParent_() messes up my Child Window alignment
				Posted: Thu Apr 23, 2015 2:34 pm
				by Julian
				When you parent it like this, the x and y positions are then relative to the parent, not the screen. So it will never work, you'll need to re-centre in code after the SetParent_
			 
			
					
				Re: SetParent_() messes up my Child Window alignment
				Posted: Thu Apr 23, 2015 2:44 pm
				by Thunder93
				This is what I want though, center to the parent Window and not screen. Using SetParent() makes it fail, without it, works as expected.
You can actually see that using SetParent() actually causes it to jump from the center of the parent window.
			 
			
					
				Re: SetParent_() messes up my Child Window alignment
				Posted: Fri Apr 24, 2015 1:29 am
				by Thunder93
				If the child window is set with borderless flag, no problem. If with system menu flag, then ResizeWindow() to move and center the child window is a requirement after SetParent API call. I was trying to avoid the extra step  
 
Code: Select all
If OpenWindow(0, 0, -1, 500, 600, "Parent Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget |#PB_Window_MaximizeGadget) And
   OpenWindow(1, WindowWidth(0)/2-200/2, WindowHeight(0)/2-200/2, 200, 200, "Child Window", #PB_Window_BorderLess)
  SetWindowColor(1, $DB887E)
  
  SetParent_(WindowID(1), WindowID(0))  
  
  
  If OpenWindow(2, 520, -1, 500, 600, "Parent Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget |#PB_Window_MaximizeGadget) And
     OpenWindow(3, 0, 0, 200, 200, "Child Window", #PB_Window_SystemMenu)  
    SetWindowColor(3, $DB887E)
    
    SetParent_(WindowID(3), WindowID(2))
    
    ResizeWindow(3, WindowWidth(2)/2-(WindowWidth(3, #PB_Window_FrameCoordinate)/2), WindowHeight(2)/2-(WindowHeight(3, #PB_Window_FrameCoordinate)/2), #PB_Ignore, #PB_Ignore) 
  EndIf
  
  Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow  
EndIf