Window Focus ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Window Focus ?

Post by netmaestro »

If you're on Windows, this should help. If not, not so much:

Code: Select all

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(2000) ; <------------------- Use this time to click the IDE window bar to set focus
  PostMessage_(WindowID(0),#WM_SYSCOMMAND, #SC_RESTORE, 0) 
  SetForegroundWindow_(WindowID(0))
EndProcedure

OpenWin()
CreateThread(@max(),0)

Repeat
  
Until WaitWindowEvent()=#WM_CLOSE
BERESHEIT
Nubcake
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Feb 03, 2011 7:44 pm

Re: Window Focus ?

Post by Nubcake »

I tested your code and it still gives the same results as before but if you comment out the webgadget and set the focus in the IDE it works , what's the problem there? I'm on Windows
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Window Focus ?

Post by IdeasVacuum »

...netmaestro's code is working fine on my machine - WinXP 32bit.

Is it a problem with, say specifically Win7? What Windows are you using Nubcake?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Nubcake
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Feb 03, 2011 7:44 pm

Re: Window Focus ?

Post by Nubcake »

IdeasVacuum wrote:...netmaestro's code is working fine on my machine - WinXP 32bit.

Is it a problem with, say specifically Win7? What Windows are you using Nubcake?
Win 7 Ultimate 64bit - It works for you? Even with the webgadget ? did you set the focus in/on the pb window/ide
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Window Focus ?

Post by IdeasVacuum »

It works for you?
yes
Even with the webgadget ?
yes
did you set the focus in/on the pb window/ide
yes

So, are you compiling a 32bit app on 64bit windows or a 64 bit app? That might be significant.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Nubcake
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Feb 03, 2011 7:44 pm

Re: Window Focus ?

Post by Nubcake »

IdeasVacuum wrote:
It works for you?
yes
Even with the webgadget ?
yes
did you set the focus in/on the pb window/ide
yes

So, are you compiling a 32bit app on 64bit windows or a 64 bit app? That might be significant.
32 bit :|
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Window Focus ?

Post by netmaestro »

Ok, another try then:

Code: Select all

Global tid

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(2000) ; <------------------- Use this time to click the IDE window bar to set focus

  AttachThreadInput_(GetCurrentThreadId_(), tid, #True)
  SendMessage_(WindowID(0),#WM_SYSCOMMAND, #SC_RESTORE, 0) 
  SetForegroundWindow_(WindowID(0))
  SetFocus_(WindowID(0))
 
EndProcedure

OpenWin()
tid = GetCurrentThreadId_()
CreateThread(@max(),0)

Repeat
  
Until WaitWindowEvent()=#WM_CLOSE
BERESHEIT
Nubcake
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Feb 03, 2011 7:44 pm

Re: Window Focus ?

Post by Nubcake »

netmaestro wrote:Ok, another try then:

Code: Select all

Global tid

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(2000) ; <------------------- Use this time to click the IDE window bar to set focus

  AttachThreadInput_(GetCurrentThreadId_(), tid, #True)
  SendMessage_(WindowID(0),#WM_SYSCOMMAND, #SC_RESTORE, 0) 
  SetForegroundWindow_(WindowID(0))
  SetFocus_(WindowID(0))
 
EndProcedure

OpenWin()
tid = GetCurrentThreadId_()
CreateThread(@max(),0)

Repeat
  
Until WaitWindowEvent()=#WM_CLOSE
Doesn't work :x Anyone else have this problem ?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Window Focus ?

Post by netmaestro »

Let's go postal on it then:

Code: Select all

Global tid, 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(2000) ; <------------------- Use this time to click the IDE window bar to set focus

  AttachThreadInput_(GetCurrentThreadId_(), tid, #True)
  SendMessage_(WindowID(0),#WM_SYSCOMMAND, #SC_RESTORE, 0) 
  SetForegroundWindow_(WindowID(0))
  SetFocus_(WindowID(0))
  ShowCursor_(0)
  GetCursorPos_(cp.POINT)
  SetCursorPos_(WindowX(0)+2, WindowY(0)+2)
  keybd_event_(#VK_LBUTTON,0,0,0)
  keybd_event_(#VK_LBUTTON,0,#KEYEVENTF_KEYUP,0)
  SetCursorPos_(cp\x, cp\y)
  ShowCursor_(1)
  r=1
EndProcedure

OpenWin()
tid = GetCurrentThreadId_()
CreateThread(@max(),0)


Repeat
  If r
    r=0
    If GetFocus_() = WindowID(0)
      Debug "Success"
    Else
      Debug "No success"
    EndIf
  EndIf
  
Until WaitWindowEvent()=#WM_CLOSE
BERESHEIT
Nubcake
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Feb 03, 2011 7:44 pm

Re: Window Focus ?

Post by Nubcake »

netmaestro wrote:Let's go postal on it then:

Code: Select all

Global tid, 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(2000) ; <------------------- Use this time to click the IDE window bar to set focus

  AttachThreadInput_(GetCurrentThreadId_(), tid, #True)
  SendMessage_(WindowID(0),#WM_SYSCOMMAND, #SC_RESTORE, 0) 
  SetForegroundWindow_(WindowID(0))
  SetFocus_(WindowID(0))
  ShowCursor_(0)
  GetCursorPos_(cp.POINT)
  SetCursorPos_(WindowX(0)+2, WindowY(0)+2)
  keybd_event_(#VK_LBUTTON,0,0,0)
  keybd_event_(#VK_LBUTTON,0,#KEYEVENTF_KEYUP,0)
  SetCursorPos_(cp\x, cp\y)
  ShowCursor_(1)
  r=1
EndProcedure

OpenWin()
tid = GetCurrentThreadId_()
CreateThread(@max(),0)


Repeat
  If r
    r=0
    If GetFocus_() = WindowID(0)
      Debug "Success"
    Else
      Debug "No success"
    EndIf
  EndIf
  
Until WaitWindowEvent()=#WM_CLOSE
Success for both (when not in ide and when in ide) however when in the ide only SetForeGroundWindow() works ; the window flashes in the taskbar but is not brought up over the other windows like before.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4996
Joined: Sun Apr 12, 2009 6:27 am

Re: Window Focus ?

Post by RASHAD »

See if it works for you

Code: Select all

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(2000) ; <------------------- Use this time to click the IDE window bar to set focus
  SendMessage_(#HWND_BROADCAST, #WM_SYSCOMMAND, #SC_HOTKEY, WindowID(0))
EndProcedure

OpenWin()
CreateThread(@max(),0)

Repeat  
Until WaitWindowEvent()=#WM_CLOSE

Egypt my love
Nubcake
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Feb 03, 2011 7:44 pm

Re: Window Focus ?

Post by Nubcake »

RASHAD wrote:See if it works for you

Code: Select all

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(2000) ; <------------------- Use this time to click the IDE window bar to set focus
  SendMessage_(#HWND_BROADCAST, #WM_SYSCOMMAND, #SC_HOTKEY, WindowID(0))
EndProcedure

OpenWin()
CreateThread(@max(),0)

Repeat  
Until WaitWindowEvent()=#WM_CLOSE

Works! Thanks RASHAD! :mrgreen: :D :D
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Window Focus ?

Post by IdeasVacuum »

Another Rescue by Rashad! 8)

(works on XP too)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply