Page 1 of 2
					
				Window Focus ?
				Posted: Mon Jun 18, 2012 10:17 pm
				by Nubcake
				I'm using SetWindowState() to return a window's state back to normal however the focus is not set on the window so I tried to use SetActiveWindow but it failed so does StickyWindow , are there reasons to why this is happening?/Solutions to this problem?
Edit:
PROBLEM - If there is a webgadget in the window and it's minimized , when you try to use SetWindowState(#Window,#PB_Window_Normal) it will work ONLY if the focus is not in PB IDE/elsewhere however it won't be brought up on the current layer , stickywindow will help but then there's no way to set the focus , how do you fix this problem? 
Test code proof
Code: Select all
OpenWindow(0,0,0,320,240,"",#PB_Window_Minimize | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
WebGadget(0,0,0,320,240,"")
Global r
Procedure max(a)
  Delay(1000)
  SetWindowState(0,#PB_Window_Normal)
  StickyWindow(0,1)
  r=1
EndProcedure
CreateThread(@max(),0)
Repeat
  If r=1
    SetActiveWindow(0)
    r=0
  EndIf   
Until WaitWindowEvent(10)=#WM_CLOSE
 
			 
			
					
				Re: Window Focus ?
				Posted: Mon Jun 18, 2012 11:17 pm
				by IdeasVacuum
				SetActiveWindow() is the one to use - if it fails, post a working snippet that demonstrates the failure.
			 
			
					
				Re: Window Focus ?
				Posted: Mon Jun 18, 2012 11:25 pm
				by Nubcake
				IdeasVacuum wrote:SetActiveWindow() is the one to use - if it fails, post a working snippet that demonstrates the failure.
Code: Select all
OpenWindow(0,0,0,320,240,"",#PB_Window_Minimize | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
Procedure max(a)
  Delay(1000)
  SetWindowState(0,#PB_Window_Normal)
  Delay(500)
  SetActiveWindow(0)
EndProcedure 
CreateThread(@max(),0)
Repeat : Until WaitWindowEvent()=#WM_CLOSE
Random Question: Is SetGadgetText() with the webgadget threadsafe? I've been using it and it works however I've been getting IMA 184 sometimes.
 
			 
			
					
				Re: Window Focus ?
				Posted: Mon Jun 18, 2012 11:39 pm
				by IdeasVacuum
				....the webgadet itself is not thread safe so, treading on egg shells there.
			 
			
					
				Re: Window Focus ?
				Posted: Mon Jun 18, 2012 11:42 pm
				by Nubcake
				IdeasVacuum wrote:....the webgadet itself is not thread safe so, treading on egg shells there.
So why does it still work sometimes and not throw up an error 

 It is advised to use 'unthreadsafe' functions for the webgadget in the main program thread? At first i thought it was threadsafe because it worked in a thread and did not give any errors.
 
			 
			
					
				Re: Window Focus ?
				Posted: Mon Jun 18, 2012 11:48 pm
				by IdeasVacuum
				Window Focus: Well, seems it is the use of the thread that is the issue as it works fine without CreateThread().
Try this:
Code: Select all
OpenWindow(0,0,0,320,240,"",#PB_Window_Invisible | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
Procedure max(a)
;-------------------
  Delay(100)
  HideWindow(0,#False)
EndProcedure
     CreateThread(@max(),0)
  SetActiveWindow(0)
Repeat : Until WaitWindowEvent()=#WM_CLOSE
 
			 
			
					
				Re: Window Focus ?
				Posted: Mon Jun 18, 2012 11:58 pm
				by Nubcake
				IdeasVacuum wrote:Window Focus: Well, seems it is the use of the thread that is the issue as it works fine without CreateThread().
Try this:
Code: Select all
OpenWindow(0,0,0,320,240,"",#PB_Window_Invisible | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
Procedure max(a)
;-------------------
  Delay(100)
  HideWindow(0,#False)
EndProcedure
     CreateThread(@max(),0)
  SetActiveWindow(0)
Repeat : Until WaitWindowEvent()=#WM_CLOSE
 
I changed it to how i wrote it in the original snippet and it seems to be working now however in my actual code i wasn't calling it from a thread and it didn't work but i guess SetActiveWindow does not work with threads.
 
			 
			
					
				Re: Window Focus ?
				Posted: Tue Jun 19, 2012 3:14 am
				by IdeasVacuum
				So why does it still work sometimes and not throw up an error
Luck  

 
			 
			
					
				Re: Window Focus ?
				Posted: Tue Jun 19, 2012 12:38 pm
				by Nubcake
				I thought it a function was not threadsafe it would immediately throw up an error when it was being used.
			 
			
					
				Re: Window Focus ?
				Posted: Tue Jun 19, 2012 2:23 pm
				by Zach
				No, it just means that it is not safe to use with threads because the behavior is unstable and unpredictable.
So you may get an error sometimes, or you may not.
			 
			
					
				Re: Window Focus ?
				Posted: Tue Jun 19, 2012 2:50 pm
				by Nubcake
				Zach wrote:No, it just means that it is not safe to use with threads because the behavior is unstable and unpredictable.
So you may get an error sometimes, or you may not.
Ok thanks for clearing that up I know now not to use functions in threads which are not threadsafe with the webgadget now 
Edit: 
PROBLEM - If there is a webgadget in the window and it's minimized , when you try to use SetWindowState(#Window,#PB_Window_Normal) it will work ONLY if the focus is not in PB IDE/elsewhere however it won't be brought up on the current layer , stickywindow will help but then there's no way to set the focus , how do you fix this problem?  
Test code to prove it
Code: Select all
OpenWindow(0,0,0,320,240,"",#PB_Window_Minimize | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
WebGadget(0,0,0,320,240,"")
Global r
Procedure max(a)
  Delay(1000)
  SetWindowState(0,#PB_Window_Normal)
  StickyWindow(0,1)
  r=1
EndProcedure
CreateThread(@max(),0)
Repeat 
  If r=1
    SetActiveWindow(0)
    r=0
  EndIf   
Until WaitWindowEvent(10)=#WM_CLOSE
 
			 
			
					
				Re: Window Focus ?
				Posted: Tue Jun 19, 2012 11:52 pm
				by IdeasVacuum
				Code: Select all
Global r
Procedure OpenWin()
;------------------
If OpenWindow(0,0,0,320,240,"",#PB_Window_Minimize | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
         WebGadget(1,0,0,320,240,"")
EndIf
EndProcedure
Procedure max(a)
;---------------
  Delay(1000)
  SetWindowState(0,#PB_Window_Normal)
  r=1
EndProcedure
     OpenWin()
CreateThread(@max(),0)
Repeat
  If r=1
    SetActiveWindow(0)
       StickyWindow(0,#True)
    r=0
  EndIf 
  
Until WaitWindowEvent(10)=#WM_CLOSE
 
			 
			
					
				Re: Window Focus ?
				Posted: Wed Jun 20, 2012 3:59 pm
				by Nubcake
				Still doesn't work for some reason , did you set the focus in the PB IDE and try it ? When you do that the window will be set to normal state but not have the focus on.
			 
			
					
				Re: Window Focus ?
				Posted: Wed Jun 20, 2012 4:14 pm
				by IdeasVacuum
				Well, I saved it as an exe - but you can't have two Windows with focus. With the PB IDE in focus, if I double-click the exe, the explorer Window has the focus momentarily, then the exe has focus (and not PB or the Explorer Window). Then of course if PB is clicked, it now has the focus again........
			 
			
					
				Re: Window Focus ?
				Posted: Wed Jun 20, 2012 7:48 pm
				by Nubcake
				I know 2 windows can't have the focus however if you comment out the webgadget it should work properly but I need to have a webgadget in my program I still don't understand why it doesn't set the focus to the window with a webgadget inside of it.