🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
12 messages
12 total messages Started by Jos� Thu, 24 Jan 2008 21:38
How to ... ?
#752
Author: Jos�
Date: Thu, 24 Jan 2008 21:38
8 lines
1022 bytes
Dear friends I have two little questions

A program displays some status information. I want it to be "Always On
Top" without taking focus for input. Can it be done?

Can a program force the computer to shut down?
-- 
Jos�
Re: How to ... ?
#753
Author: Remy Lebeau (TeamB)
Date: Thu, 24 Jan 2008 21:41
18 lines
1535 bytes
"Jos�" <jose@127.0.0.1> wrote in message 
news:871ip39v9f1nqt1f3i2pk22bpfifsl6p3t@4ax.com...

> A program displays some status information. I want it
> to be "Always On Top" without taking focus for input.
> Can it be done?

Sure.  "Stay on Top" and "input focus" are two separate things.  Just 
because a window is on top does not mean that the user can't still click on 
other windows.

> Can a program force the computer to shut down?

Look at the EWX_POWEROFF and EWX_SHUTDOWN flags of ExitWindowsEx()


Gambit 
Re: How to ... ?
#755
Author: Jos�
Date: Fri, 25 Jan 2008 09:20
21 lines
1727 bytes
On Thu, 24 Jan 2008 13:41:36 -0800, "Remy Lebeau \(TeamB\)"
<no.spam@no.spam.com> wrote in borland.public.cppbuilder.nativeapi:

>> A program displays some status information. I want it
>> to be "Always On Top" without taking focus for input.
>> Can it be done?
>
>Sure.  "Stay on Top" and "input focus" are two separate things.  Just 
>because a window is on top does not mean that the user can't still click on 
>other windows.

But how? I can find no functions which force a window on top. And I
think it is easy to take focus, but not to deny focus.
>
>> Can a program force the computer to shut down?
>
>Look at the EWX_POWEROFF and EWX_SHUTDOWN flags of ExitWindowsEx()

Yes, that was really helpful. Thanks
-- 
Jos�
Re: How to ... ?
#758
Author: Asger Joergensen
Date: Fri, 25 Jan 2008 12:18
29 lines
1922 bytes
Hi Jos 
 
 Jos says:
> On Thu, 24 Jan 2008 13:41:36 -0800, "Remy Lebeau \(TeamB\)"
> <no.spam@no.spam.com> wrote in borland.public.cppbuilder.nativeapi:
> 
> >> A program displays some status information. I want it
> >> to be "Always On Top" without taking focus for input.
> >> Can it be done?
> >
> >Sure.  "Stay on Top" and "input focus" are two separate things.  Just 
> >because a window is on top does not mean that the user can't still click on 
> >other windows.
> 
> But how? I can find no functions which force a window on top. And I
> think it is easy to take focus, but not to deny focus.

SetWindowPos(Form2->Handle,
                 HWND_TOPMOST,
                 Form2->Left,  // horizontal position
                 Form2->Top,   // vertical position   SWP_NOREDRAW |
                 Form2->Width, // width
                 Form2->Height,    // height
                 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE
                 );

Kind regards
Asger
Re: How to ... ?
#759
Author: Jos�
Date: Fri, 25 Jan 2008 13:05
26 lines
2007 bytes
On Fri, 25 Jan 2008 13:18:52 +0100, Asger Joergensen <junk@Asger-P.dk>
wrote in borland.public.cppbuilder.nativeapi:

>> >Sure.  "Stay on Top" and "input focus" are two separate things.  Just 
>> >because a window is on top does not mean that the user can't still click on 
>> >other windows.
>> 
>> But how? I can find no functions which force a window on top. And I
>> think it is easy to take focus, but not to deny focus.
>
>SetWindowPos(Form2->Handle,
>                 HWND_TOPMOST,
>                 Form2->Left,  // horizontal position
>                 Form2->Top,   // vertical position   SWP_NOREDRAW |
>                 Form2->Width, // width
>                 Form2->Height,    // height
>                 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE
>                 );
>

Thanks. It does stay on top (fine), but it also takes focus (wrong).
This means, when I am typing and the form appears unexpectedly
(because its Visible property is set), my typing disappears into
oblivion.
-- 
Jos�
Re: How to ... ?
#760
Author: Asger Joergensen
Date: Fri, 25 Jan 2008 13:21
14 lines
1443 bytes
Hi Jos 
 
 Jos says:
> Thanks. It does stay on top (fine), but it also takes focus (wrong).
> This means, when I am typing and the form appears unexpectedly
> (because its Visible property is set), my typing disappears into
> oblivion.

You can set the focus back to the form You are writing in just
use SetWindowPos with some other flags.

Kind regards
Asger
Re: How to ... ?
#512
Author: Jos�
Date: Fri, 25 Jan 2008 13:58
19 lines
1782 bytes
On Fri, 25 Jan 2008 14:21:52 +0100, Asger Joergensen <junk@Asger-P.dk>
wrote in borland.public.cppbuilder.nativeapi:

>> Thanks. It does stay on top (fine), but it also takes focus (wrong).
>> This means, when I am typing and the form appears unexpectedly
>> (because its Visible property is set), my typing disappears into
>> oblivion.
>
>You can set the focus back to the form You are writing in just
>use SetWindowPos with some other flags.

I tried that. But imagine that the programs ar unrelated.

For example, I am writing a text in Word. My home made program appears
to inidicate that a job has been completed. It appears on top, and it
takes focus. It cannot give the focus back to Word, since it does not
know whence the focus came.
-- 
Jos�
Re: How to ... ?
#513
Author: Jos�
Date: Fri, 25 Jan 2008 14:14
16 lines
1625 bytes
On Fri, 25 Jan 2008 14:21:52 +0100, Asger Joergensen <junk@Asger-P.dk>
wrote in borland.public.cppbuilder.nativeapi:

>You can set the focus back to the form You are writing in just
>use SetWindowPos with some other flags.

This is what worked eventually. Thanks for your kind help:

Hide window:  
  SetWindowPos(....HWND_BOTTOM,......SWP_NOACTIVATE  );
    Form1->Visible=false;

Show window  .
 SetWindowPos(......HWND_TOPMOST......,SWP_NOACTIVATE  );
-- 
Jos�
Re: How to ... ?
#514
Author: Asger Joergensen
Date: Fri, 25 Jan 2008 15:09
22 lines
1862 bytes
Hi Jos 
 
 Jos says:
> I tried that. But imagine that the programs ar unrelated.
> 
> For example, I am writing a text in Word. My home made program appears
> to inidicate that a job has been completed. It appears on top, and it
> takes focus. It cannot give the focus back to Word, since it does not
> know whence the focus came.

I wasn't aware that it was two different applications but I'm 
gladd You got it working.

You could probably also use:
ShowWindow with the SW_SHOWNOACTIVATE flag 

I think You could also use a THintWindow to show such a message,
something like the windows update does.

Kind regards
Asger
Re: How to ... ?
#517
Author: Remy Lebeau (TeamB)
Date: Fri, 25 Jan 2008 17:41
10 lines
1345 bytes
"Jos�" <jose@127.0.0.1> wrote in message 
news:pbajp3d5r5g754trs4jdqh8e28srn3cq1u@4ax.com...

> But how? I can find no functions which force a window on top.

Set the form's FormStyle to fsStayOnTop, or use SetWindowPos(HWND_TOPMOST).


Gambit 
Re: How to ... ?
#516
Author: Remy Lebeau (TeamB)
Date: Fri, 25 Jan 2008 17:43
13 lines
1754 bytes
"Jos�" <jose@127.0.0.1> wrote in message 
news:ohqjp3tnknh2vl5h7oe8991n8gt4psu1ku@4ax.com...

> For example, I am writing a text in Word. My home made program
> appears to inidicate that a job has been completed. It appears on top,
> and it takes focus. It cannot give the focus back to Word, since it
> does not know whence the focus came.

Yes, you can - call GetForegroundWindow() before displaying your own window.


Gambit 
Re: How to ... ?
#520
Author: David Pratt
Date: Sat, 26 Jan 2008 01:54
22 lines
2068 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:479a1fa9$1@newsgroups.borland.com...
>
> "Jos�" <jose@127.0.0.1> wrote in message 
> news:ohqjp3tnknh2vl5h7oe8991n8gt4psu1ku@4ax.com...
>
>> For example, I am writing a text in Word. My home made program
>> appears to inidicate that a job has been completed. It appears on top,
>> and it takes focus. It cannot give the focus back to Word, since it
>> does not know whence the focus came.
>
> Yes, you can - call GetForegroundWindow() before displaying your own 
> window.
>
>
> Gambit


Wouldn't handling the WM_SETFOCUS msg work just as well or better? It sends 
the handle for the window losing focus as a parameter, so all the OP would 
have to do is to set the focus back to the losing window. 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads