Link to home
Start Free TrialLog in
Avatar of SFS
SFS

asked on

how to make window upmost here.

Dear experts:
Here is the code:

//after I have create a window...
Sleep(4000);
ShowWindow(hwnd, SW_SHOW);

The problem is during the 4 seconds,if another window active and become the top window,
for example:
If I click a task  from the taskbar,then the window associated wiht that task pop up,

Then,in the showwindow(), my window will be showed into the taskbar ,but I wanna show it at top,how to ?(it's not a topmost window)...







Avatar of jkr
jkr
Flag of Germany image

Simply use

//after I have create a window...
Sleep(4000);
ShowWindow(hwnd, SW_SHOW);
BringWindowToTop ( hwnd); // <-- !!!

Feel free to ask if you need more information!
Avatar of Madshi
Madshi

Nope, BringWindowToTop works only for child windows of the same application - or am I wrong, Jürgen?   :-)

You need to call

ShowWindow(hwnd, SW_SHOW);
SetForegroundWindow(hwnd);

Regards, Madshi.
Avatar of SFS

ASKER

jkr,have you really tried your answer,it doesn't work...

To MadShi:
I try your suggestion and it does make difference,but still do appear on top,it only make the button in the taskbar flicker to notify the user push it to make it show up...

Here is the code:

hwnd = CreateWindowEx(0,"HELLO", "HELLO",                      WS_SYSMENU  ,
0, 0, 300, 300,
NULL, NULL, hInstance, NULL);

Sleep(4000);
//meanwhile ,another window became the top,you can try simple to click a button from the taskbar to invoke an application you have launched..

ShowWindow(hwnd, SW_SHOW);
//SetForegroundWindow(hwnd);
//BringWindowToTop(hwnd);
Here I try both....

Regards...
Avatar of SFS

ASKER

oops,to MadShi's comment:
It dones't appear,not do appear...
Avatar of SFS

ASKER

Maybe you think Why I need to sleep() and invoke another application.Ok,it is just an analogy,the truth is :

I have a .exe and first it hides its window and it appears an icon in the tray and I wanna it appears to top when the user click it,if after I launch my .exe,I don't make other window at top,no problem.
But if after I launch my .exe,I make another or two or three winow onto  the screen,it only appears into the task bar...

Avatar of SFS

ASKER

I increase the points but originally I dont figure it's so hard...
no way, I think you should make it topmost style and remove that style when It shows up using SetWindowPos().Latter ,add it again when it droppes.
Regards
Wyn
Avatar of SFS

ASKER

Would you please detail ?
ASKER CERTIFIED SOLUTION
Avatar of Wyn
Wyn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry,the way to add style again seems wrong prone.I will figure,but it's not in the range of your question.

Seems strange,the layout of this site.
Especially the expert ranking chart,the color too musty,but I think it should  be splendid.

The blinking effect is a so called feature invented by Microsoft in win98 and NT5. I hate it, but luckily there's a way around it:

const SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
      SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var   timeout                      : cardinal;
begin
  SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout,         0);
  SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, nil,              0);
  result:=SetForegroundWindow(FHandle);
  SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, pointer(timeout), 0);

This eliminates the blinking and instead moves the window really to the top (like it was in win95 and NT4).

Regards, Madshi.
Avatar of SFS

ASKER

To Wyn:
Thank you,your way works perfectly,but I also need to add it again,how to?

To MadShi:
I think your way will work but It's in VB,I translate to vc but fail work,this is my code I translate:



ShowWindow(hwnd, SW_SHOW);

const  SPI_GETFOREGROUNDLOCKTIMEOUT=2000;
const  SPI_SETFOREGROUNDLOCKTIMEOUT=2001;
int timeout;

SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,
 0,&timeout,0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,
0, 0, 0);

SetForegroundWindow(hwnd);

SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,
 0, &timeout, 0);
Is this right,why no effect?

Thank you,MadShi,how to give you points?
Avatar of SFS

ASKER

To MadShi again:
Would you please tell me how the 2000 and 2001 come into play?
They are just constants used for the SystemParametersInfo call. (BTW, it's Delphi code, not VB code... :-)

In C++ it's something like

#define SPI_GETFOREGROUNDCLOCKTIMEOUT 2000
#define SPI_SETFOREGROUNDCLOCKTIMEOUT 2001

If you want to give ME the points, you should reject the current answer, then you can accept one of my comments as the answer. Thank you...   (-:
Avatar of SFS

ASKER

Still don't work ,I pose code again.
I will give you certain points if it works as a new question and you simplly take it.
Wyn's answer is good,how can I reject?

These is whole code after I create the window.

#define  SPI_GETFOREGROUNDLOCKTIMEOUT 2000
#define  SPI_SETFOREGROUNDLOCKTIMEOUT 2001
Sleep(4000);
int timeout;
ShowWindow(hwnd, SW_SHOW);
//SPI_GETACCESSTIMEOUT
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,
 0,&timeout,0);
SystemParametersInfo
SPI_SETFOREGROUNDLOCKTIMEOUT,
 0, 0, 0);
SetForegroundWindow(hwnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,
 0, &timeout, 0);
Avatar of SFS

ASKER

It seems the 2000 is not eligible ,where you this magic number ,Madsin?
Avatar of SFS

ASKER

Sorry,Madshi.:)
Ooops. Well, we both worked together to build a bug in my suggestion...  :-)

In your first C++ sources you left away the "$" from the $2000. And in my following comment I left it away, too. In Delphi this "$" means the same as "0x" means in C++.

So it must be this way:

#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
Avatar of SFS

ASKER

Ok,Madshi,Thank you .
It works perfectly.
I will pose a question naming "for Madshi" ,please.

BUT:
Out of my curiosity:
Would you please tell me which site you got the information of 0x2000 in case I haunt it for my life?

Another expert told me...   :-)