[Resolved] WindowActivate() Not Working?

Mac OSX specific forum
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

[Resolved] WindowActivate() Not Working?

Post by garretthylltun »

Greetings,

Has anyone else found that WindowActivate() is not working for them?

Or, am I doing something wrong?

Code: Select all

OpenWindow (0, 0, 40, 100, 600, #PB_Window_BorderLess , "Bar Test")
CreateGadgetList(WindowID(0))
  ButtonGadget(2, 2, 2, 32, 24, "X", #PB_Button_Left)
  ButtonGadget(1, 2, 30, 96, 24, "App", #PB_Button_Left)

  vMouseLocStatus = 0
  ResizeWindow(2, WindowHeight())

Event_Loop:
  Delay(100)
  EventID = WindowEvent()
  If EventID = #PB_Event_CloseWindow
    End
  EndIf
  GadgetID = EventGadgetID()
  If GadgetID = 1
    Goto Branch_1
  ElseIf GadgetID = 2
      Goto Branch_2
  EndIf
  ; X is left to right
  ; Y is top to bottom
  vMouseX = DesktopMouseX()
  vMouseY = DesktopMouseY()
  If vMouseX < 2 And vMouseLocStatus = 0
    vMouseLocStatus = 1
    For vWide = 2 To 100 Step 7
      ResizeWindow(vWide, WindowHeight())
    Next
    ActivateWindow()
  EndIf
  If vMouseX > WindowWidth() And vMouseLocStatus = 1
    vMouseLocStatus = 0
    vWide = 100
    While vWide > 2
      vWide = vWide - 7
      ResizeWindow(vWide, WindowHeight())
    Wend
    ResizeWindow(2, WindowHeight())
  EndIf
  Goto Event_Loop
  
  
Branch_1:
  ;Result = RunProgram("/Applications/File/Xfolders.app")
  Goto Event_Loop

Branch_2:
  End
As usual.... Any help, advice, spankings are graciously welcomed and
appreciated. :-)

Thanks,
-Garrett
Last edited by garretthylltun on Wed Jan 18, 2006 2:28 am, edited 1 time in total.
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

1. Tell us what the code is supposed to do. If it doesn't do what it is supposed to do we obviously can't see what it's supposed to do by looking at it, can we?

2. Tell us what it does.

3. That's right, ActivateWindow doesn't work. It can be demonstrate by the following code:

Code: Select all

OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu, "What")
CreateGadgetList(WindowID())
  TextGadget(0, 10, 10, 100, 20, "")
Delay(1000)
; Manually focus another window here
  SetGadgetText(0, "askdlfj asldkf jasldfj")
ActivateWindow()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Tested on Windows XP and ActivateWindow() did nothing.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Trond:

ActivateWindow() does work, but it does only set the focus within the windows of your app.
It cannot grab the focus off another Program.
This is a windows limitation that makes sense, as it is not good to "steal" the
focus from another Program, as usually the user is working with that right now.

Dunno about OSX though. I am unable to test this right now.
quidquid Latine dictum sit altum videtur
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

[quote=Manual]Activate the current window, this means than focus has been put on this window.[/quote]

I say that it does not work if it doesn't do what the manual says it should do, and it definitely doesn't.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

If you have a window 1 which has the focus, and you call ActivateWindow()
on another window 2, the window 2 will later have the focus. Exactly what the manual says.

I can clarify this a bit more in the manual, but this is the correct behaviour.
quidquid Latine dictum sit altum videtur
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Well, the manual clearly says that "this means that focus has been put on this window".
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

Post by garretthylltun »

I see, it means that your window will get the focus if you are working
with more than one window from within your application.

In previous languages that I've used, this would bring my window to the
top of the Z-Order (to the front) and make it the active window regardless
of who the owner of the window was.

Of course for Windows there is a WM message to do this also, but I'm not
sure OSX has such. Even if it did, I have not been succesful at getting
OSX Api calls working yet.

-Garrett
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
SEO
Enthusiast
Enthusiast
Posts: 178
Joined: Fri Dec 09, 2005 11:42 pm
Location: Sweden
Contact:

Post by SEO »

OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu, "What")
CreateGadgetList(WindowID())
TextGadget(0, 10, 10, 100, 20, "")
Delay(1000)
; Manually focus another window here
SetGadgetText(0, "askdlfj asldkf jasldfj")
ActivateWindow()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Activate Window ... What Window? You activate window 0!

This code works on OS X 10.4.3 and 10.4.4 using PB Mac 3.94b

Code: Select all

Procedure Set_ActiveWindow(ID)
;
; Move tihis procedure to Settergettter include file later...
UseWindow(ID)
ActivateWindow()
EndProcedure
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Trond: The command does what the manual say. I explained that above.
Just because you want it to do something else does not mean there is a bug.


There is a big difference, between "application focus" and "window focus".
ActivateWindow() changes the window focus, nothing more.

On recent Windows versions (Me/2k/XP) you can only get the application focus
from the foreground process if this process
explicitly allows you to do this with AllowSetForegroundWindow(), which
is usually not the case.

There are hacks to allow to "steal" the focus from another process without
having the rights to do it, but it is a bad thing to do, for several reasons:

1) If the user puts your app in the background, there is usually a reason for it
(probably because he is working with another program).
It is annoying as hell if some app suddenly pops up and grabs the Keyboard
focus, while you are typing someting in another program.

2) This method is potentially unsafe. Try to get the focus from an app that is hanging,
and your program will lock up too... bad luck.
quidquid Latine dictum sit altum videtur
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

Post by garretthylltun »

The only instance I see of needing this is when I build app bars, which
i've done in the past, and which my example above is.

When the mouse is moved to side of the screen, the bar is brought out
from the side, and should be focused so the user can simply click on the
needed item without having to click the window first in order to gain the
focus.

Or to give your system X11 style mouse over focusing(annoying as all
hell).

-Garrett
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

Post by garretthylltun »

SEO wrote:
OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu, "What")
CreateGadgetList(WindowID())
TextGadget(0, 10, 10, 100, 20, "")
Delay(1000)
; Manually focus another window here
SetGadgetText(0, "askdlfj asldkf jasldfj")
ActivateWindow()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Activate Window ... What Window? You activate window 0!

This code works on OS X 10.4.3 and 10.4.4 using PB Mac 3.94b

Code: Select all

Procedure Set_ActiveWindow(ID)
;
; Move tihis procedure to Settergettter include file later...
UseWindow(ID)
ActivateWindow()
EndProcedure
This code does not work!

If you lose the focus of your program to say Finder, then move the
mouse back over your window, you do not regain the focus.

ActivateWindow() was not intended for this purpose. :-(

Thanks anyway :-)
-Garrett
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

I've pasted a few functions used by the IDE which access the OS X API: http://www.rafb.net/paste/results/a0FaOs39.html . There is a BringToFront_() which might help you. It also give an idea on how to use the OS X API in PB (nothing fancy as you can see).
SEO
Enthusiast
Enthusiast
Posts: 178
Joined: Fri Dec 09, 2005 11:42 pm
Location: Sweden
Contact:

Post by SEO »

This code does not work!

If you lose the focus of your program to say Finder, then move the
mouse back over your window, you do not regain the focus.

ActivateWindow() was not intended for this purpose.
And it should not! There is no app that take focus from an another by move the mouse over an window. Then you have first to activate the app and then detect 'mouse over' ...
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

Post by garretthylltun »

SEO wrote:And it should not! There is no app that take focus from an another by move the mouse over an window. Then you have first to activate the app and then detect 'mouse over' ...
You seem to be missing something here.

You can detect mouse coordinates even if your window is not the active
window.

Did you even run the code I pasted? If you had, you would have noticed
that when the window is not even active, if you move the mouse to the
left of your screen, the window rolls out. How can I do that if I am not
able to detect the mouse coordinates while my window is not the active
window?

Look at the code, follow the code, play with the code.... May the code be
with you.. ;-)

-Garrett
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
SEO
Enthusiast
Enthusiast
Posts: 178
Joined: Fri Dec 09, 2005 11:42 pm
Location: Sweden
Contact:

Post by SEO »

You are great!
Nope, I did not even run your code, because If I should try I have a lot of work to clean up the code, there is some characters, that give compiler error. And it is absolute not worth that work...

And you missing someting, the code to 'activate' an window works, as it should... (Why do you say that is not working?)

You also missing something fundamental: The documentation of the Carbon functions....

And also: Your Operating System (OS) and the version (X)
Locked