Real SetForegroundWindow Fell Off The Plate

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Randy Walker
Addict
Addict
Posts: 998
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Real SetForegroundWindow Fell Off The Plate

Post by Randy Walker »

Fred... First I want to thank you for posting this workaround solution yourself -- Thank you :D

viewtopic.php?f=12&t=7424&hilit=real+Se ... oundWindow

Now I'm going to razz you because you did post the solution ''yourself'' over 6 years ago... and I still cannot find ReallySetForegroundWindow() in the PB command set! Come on... you're up to ver 4.51 now!!!!! Slacker :P
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
bobobo
Enthusiast
Enthusiast
Posts: 206
Joined: Mon Jun 09, 2003 8:30 am

Re: Real SetForegroundWindow Fell Off The Plate

Post by bobobo »

Maybe StickyWindow() will help You
사십 둘 .
Randy Walker
Addict
Addict
Posts: 998
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Real SetForegroundWindow Fell Off The Plate

Post by Randy Walker »

bobobo wrote:Maybe StickyWindow() will help You
Its not that way -- nothing to do with "sticky windows". Its all about Windows "sticky taskbar" stealing the show when you try to manage the foreground window. You should click the link above and read Fred's post about the "Real SetForgroundWindow()" to appreciate this request. I am not looking for a solution. He gave a nearly perfect solution already. He just hasn't made it part of the PB command set. That would make it the perfect solution :)
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Real SetForegroundWindow Fell Off The Plate

Post by nco2k »

Randy Walker wrote:He just hasn't made it part of the PB command set
why should he? its a windows xp+ thing only.. :? its not his job to suppress ms design changes.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Randy Walker
Addict
Addict
Posts: 998
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Real SetForegroundWindow Fell Off The Plate

Post by Randy Walker »

nco2k wrote:
Randy Walker wrote:He just hasn't made it part of the PB command set
why should he? its a windows xp+ thing only.. :? its not his job to suppress ms design changes.
Actually, if you clicked on the link above and actually read the post by Fred that I am making refernence to, you would see in his opening line:
Here is a snippet I need for my work, to really put a window in the foreground, instead of flashing taskbar for Win98/2000 or XP
... so it is not just a Windows xp+ thing. The problem existed long before windows XP per say so I'm not sure it is fair to call it design change. Definitely not anytime recent.

Oh, by the way Fred... I guess we have to drop the above request and ask that you remove these PB commands IMMEDIATELY ! ! ! :o

Code: Select all

InitScintilla()
MDIGadget
GetFunctionEntry
SetWindowCallback
EnableGraphicalConsole()
GadgetItemID()
We can't have no stinking "Windows only" as part of the PB command set :!:
What were you thinking Fred ! ! ! :lol: :lol: :lol: :lol: :lol:

Oh yeh Fred. While you are at it. We also have to ask that you remove this stinking windows specific error code too:

Code: Select all

#PB_OnError_DivideByZero
:shock:

Boy. I don't know there nco2k. Just what was he thinking anyway? :?

Ok, now for my last request: PLEEEEASE READ my original post thoroughly and completely before adding comments. I'm getting sooo embarrased :oops: :lol:

Uhhh!!! Something else just occured to me Fred. :lol: You may recall all the fuss I made about the term ''Gadget" years ago when I was first introduced to your work. Eventually I had to concede the term was acceptable :) and I dropped the whole argument. Well. Now this ''Windows'' thing got me thinking, and maybe its too soon to ask before we get a vote on it, but I'm thinking maybe you should go through and replace every occurance of the term ''Windows'' with some other term. Something more generic and perhaps more appropriate, like ''Squarish box looking thingies that go all over the monitor display''. Thats a little long I guess. Could you shrink that down into an acronym? Yeh!! ''sblttgaotmd''. Granted, its kind of hard to pronounce but its going to be really hard for anyone to attribute anything about that one to Microsoft. :wink:

Uh OHhhhh! I did it now, didn't I? The can is open and the worms are out :lol: Whooopsie :oops:
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Real SetForegroundWindow Fell Off The Plate

Post by freak »

The linked code is very bad for various reasons:
  • Stealing focus from another program is a bad practice. The user gave the focus to the other program for a reason. Who are you to tell the user that your window is more important?
  • The code attaches to the input of the currently active program. This has a simple consequence: If the active program is hung, your program will hang too. Are you really willing to put the responsiveness of your own program into the hands of whatever random program has the focus right now?
We try not to introduce functions like that into the language. Use the code if you want, but it won't ever be an official function.
Randy Walker wrote:Uhhh!!! Something else just occured to me Fred. :lol: You may recall all the fuss I made about the term ''Gadget" years ago when I was first introduced to your work. Eventually I had to concede the term was acceptable :) and I dropped the whole argument. Well. Now this ''Windows'' thing got me thinking, and maybe its too soon to ask before we get a vote on it, but I'm thinking maybe you should go through and replace every occurance of the term ''Windows'' with some other term. Something more generic and perhaps more appropriate, like ''Squarish box looking thingies that go all over the monitor display''. Thats a little long I guess. Could you shrink that down into an acronym? Yeh!! ''sblttgaotmd''. Granted, its kind of hard to pronounce but its going to be really hard for anyone to attribute anything about that one to Microsoft. :wink:
The term "window" is not a Microsoft invention. Apart from that, I don't really see what you are trying to accomplish with this rant.
quidquid Latine dictum sit altum videtur
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Real SetForegroundWindow Fell Off The Plate

Post by nco2k »

@Randy Walker
first of all, i read that post already years ago and second, when i said winxp+ i meant the flashing, which is a design change by ms and there for a reason. prior to that it was just bullsh*t anway and they didnt change it for fun. SetForegroundWindow_() doesnt interfere with the user input anymore, which is a good thing and i doubt fred will encourage people to mess with that. its something you only need in some rare special cases and up to the programmer. im not against this because its windows only. its just more of a hack, instead of something mandatory like a callback etc. which are just simple wrappers in most cases anyway, so dont mix apples and oranges here.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Real SetForegroundWindow Fell Off The Plate

Post by PB »

The tip, which I posted before fred, only steals the input for less than a millisecond,
so a hung app isn't going to do anything. also, giving the focus to another window
might be a feature of your app, so it won't bother the user.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Real SetForegroundWindow Fell Off The Plate

Post by freak »

PB wrote:The tip, which I posted before fred, only steals the input for less than a millisecond,
so a hung app isn't going to do anything.
Yes it does: http://blogs.msdn.com/b/oldnewthing/arc ... 95860.aspx
Notice how the "code in italics is wrong" is exactly the code we have here as well.
PB wrote:also, giving the focus to another window
might be a feature of your app, so it won't bother the user.
If you have a valid need to get the focus, there is usually a way of getting it without hacks like these. Programmers tend to think that their program is sooo important that the user just has to see this right away, but generally they are wrong and it is just annoying. Why do you think the Windows developers found it necessary to limit the abilities to grab the focus in the first place?
quidquid Latine dictum sit altum videtur
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Real SetForegroundWindow Fell Off The Plate

Post by PB »

Of course there are valid needs to steal the focus. Why do people insist that there isn't? My app sets a hotkey so that whenever I press it, the calculator (or whatever window I've designated) comes to the front. I'd love to know how to do it without the tip in this topic, since it's considered so evil. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Randy Walker
Addict
Addict
Posts: 998
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Real SetForegroundWindow Fell Off The Plate

Post by Randy Walker »

Ahh. The masters step in. Always look forward to those great thought provoking comments and solutions from PB and Freak (to mention a few).
freak wrote:If you have a valid need to get the focus, there is usually a way of getting it without hacks like these....
I feel I do have legitimate reason so I would be interested in knowing the proper non-hack method... if I can do it using PureBasic -- I'm not a programmer so ASM and C stuff is just going to bounce off me. :oops:

I reject the term when people try to call me a programmer. I think that title should be reserved for people like yourself, Fred, PB, NetMaestro and others that actually have a clue what is going on outside of their own field of expertise. Networking. or game applications for example. Something may not be your field of expertise but you still understand the PureBasic language structure, command set, etc. to put something together and make it work without outside help. Not to mention you understand other languages to a large degree. I don't. I struggle with the simplest things and even then barely reach my goals after coming here and getting help from the experts. When I find a command that does what I need then that makes things a lot easiuer on me -- the non-programmer.

My legitimate reason actually does not concerm "my" application. The problem I was trying to overcome (and did with that tip from Fred) is the fact that Skype txt chat windows will only "bonk" on a new post if the chat window is not already in focus. If I have messages coming in on one computer, but I am working on the computer beside that one, I do not hear a new message come in on the other computer if I forget to "manually" move some other app window to the foreground. The only way to get Skype to "bonk" on a new post is to remove focus from that window. My solution is very selective and totally dependant on lack of user activity so in this case there is absolutley nothing arrogant, domineering, or annoyingly presumptuous about my "need" to control the forground window.

Code: Select all

If SkypeLimit > 0 ; fixed number of seconds as specified by user setting 
  GetLastInputInfo_(@lippi)
  timeNow.l = ElapsedMilliseconds() ; get current timestamp value for comparison calculations
  If ((timeNow.l - lippi\dwTime)/1000) > SkypeLimit ; << get duration on user inactivity 
    If IsIconic_(WindowID(1))
      ShowWindow_(WindowID(1),#SW_RESTORE)
    EndIf
    classname$ = Space(1024) 
    hTopWin = GetForegroundWindow_()
    GetClassName_(hTopWin, @classname$, 1024) ; only Skype "chat" windows per say use these classnames!!!
    If classname$="TskMultiChatForm.UnicodeClass" Or classname$="TConversationForm.UnicodeClass"
      ReallySetForegroundWindow(1)
    EndIf
  EndIf
EndIf
Nothing arrogant, domineering, or annoyingly presumptuous about it. Yes it does move the focus to my little innocuous clock sitting in the top left corner of the screen. Thats only matter of convenience to me as a non-programmer. I don't really care where the focus goes as long as it does not sit on that Skype chat window after "n" seconds of user inactivity. If Skype does not "bonk" then people think I am just ignoring them, and that is not the case -- just trying to get something else done while I wait on their next post. Is there any reason why that Skype chat window "needs" to maintain foreground position when there is no user interactions on that computer -- no! Absolutley none. Got a better solution? Great!! :) Tell me I legitimate reasons cannot exist :shock: -- cannot! :wink:
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 998
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Real SetForegroundWindow Fell Off The Plate

Post by Randy Walker »

freak wrote:The term "window" is not a Microsoft invention. Apart from that, I don't really see what you are trying to accomplish with this rant.
Well, first off, you dropped the "s" in windows as it applied to my rant, and "windows" in itself just happens to have the same exact pronunciation as the product created and marketed by Microsft so I was using that as leverage in my pointless rant :)
Second, my rant was strickly a nonsense retort to a strickly nonsense retort posted by nco2k. I would be very suprised to learn that "any" user here has made use of "every" command in the entire PB command set so I find it rather pointless for anyone outside of the actual PB developement team to declare what should and should not be a part of that command set.

Why should the command be added to the command set? I have no right to say that it should. Its your thing so do or don't as you see fit. That' s how it should be.

Why should another "user" challenge me for making a request on a command that he himself claims would not have any affect on him? Wow. :?: That one is just over my head. :?

I cannot say I buy into your argument for not adding it, but I do buy 100% into you doing what you feel justified ... so do it or don't. Its all good!!! :wink: Reason I don't buy into the argument is the same could be said about poking memory, seeking file pointer addresses and so many other things. Bottom line here is, you can't stop any of us from chosing to do stupid things with the more powerful commands.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Real SetForegroundWindow Fell Off The Plate

Post by nco2k »

i never said that such a command wouldnt be of any use for me. thats definitely not why i disagreed with you. all i said is, that such a command doesnt belong inside pb and again, not because its windows only, but because its a hack. if you look at other pb functions, you wont find anything like that at all. manipulating memory and files is mandatory, stealing the user input is not. i didnt challange you and my comment was no nonsense retort.. you have the right to make a wish and i have a right to respond to that, but if you get offended that easily, oh well.. :?

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Real SetForegroundWindow Fell Off The Plate

Post by freak »

PB wrote:Of course there are valid needs to steal the focus. Why do people insist that there isn't? My app sets a hotkey so that whenever I press it, the calculator (or whatever window I've designated) comes to the front. I'd love to know how to do it without the tip in this topic, since it's considered so evil. :)
Like this:
After you call the RegisterHotKey function to register a hotkey, the window manager will send you a WM_HOTKEY message when the user presses that hotkey, and along with it, you will get the foreground love. If you call SetForegroundWindow from inside your hotkey handler, the foreground window will change according to your instructions.
http://blogs.msdn.com/b/oldnewthing/arc ... 45006.aspx

If you want to bring a window from another program than your own to the front, use AllowSetForegroundWindow() to pass the right to get the focus to that program first.

Randy Walker wrote:My legitimate reason actually does not concerm "my" application. The problem I was trying to overcome (and did with that tip from Fred) is the fact that Skype txt chat windows will only "bonk" on a new post if the chat window is not already in focus.
Ok, I don't have a solution for that one. (except, maybe to ask for a skype feature to enable that "bonk" when the user is inactive?)

I didn't say don't use it. I said it is dangerous and usually used for the wrong reasons which is why it won't become a builtin command. We generally try to not encourage people to do things that are considered bad practise.
quidquid Latine dictum sit altum videtur
Randy Walker
Addict
Addict
Posts: 998
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Real SetForegroundWindow Fell Off The Plate

Post by Randy Walker »

nco2k wrote:i didnt challange you...
Can we take a look here again at your very first words?
nco2k wrote:
Randy Walker wrote:He just hasn't made it part of the PB command set
why should he? its a windows xp+ thing only.. :? its not his job to suppress ms design changes.
"why should he?"
If that is not a "challenge" for me to defend my previous comment then I guess I don't understand the meaning of the word "challenge"... or someone here doesn't. Clear to me here now, I did misinterpret your comment about Windows:
nco2k wrote:im not against this because its windows only.
I took that to mean you were not primarily a Windows user, and now I take it this was in my reference to my comment about allowing PB to include windows dedicated commands. Whoopsie :oops: My bad :)

No, i'm not offended at all. Amused and inspired to retort with endless banter at senseless things people say and do maybe :)
Do... please do. Jump right in and say you disagree. Balance of input is a wonderful thing. I don't know about "rights" and all that "who has the right" bla bla bla stuff. I do think it proper and appropriate to express your opinion, agree and disagree. I don't necessary believe that should include challening others to defend their comments if you do disagree. Way I see it, your place and mine here in this wishlist forum is to submit requests -- not jugde them, qualify them or challenge them. That should (I think) be left to the developers, but thats just my opinion... and you are welcome to disagree to your hearts content. :wink: Of course, ("rights" aside) you have the ability to post anything that comes to mind if you choose. If that be the case then so be it, but a word of warning... there is nothing you could ever say that will ever offend me in the slightest.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply