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)...
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)...
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.
You need to call
ShowWindow(hwnd, SW_SHOW);
SetForegroundWindow(hwnd);
Regards, Madshi.
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...
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...
ASKER
oops,to MadShi's comment:
It dones't appear,not do appear...
It dones't appear,not do appear...
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...
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...
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
Regards
Wyn
ASKER
Would you please detail ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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_GETFOREGROUNDLOCKTIMEO UT = $2000;
SPI_SETFOREGROUNDLOCKTIMEO UT = $2001;
var timeout : cardinal;
begin
SystemParametersInfo(SPI_G ETFOREGROU NDLOCKTIME OUT, 0, @timeout, 0);
SystemParametersInfo(SPI_S ETFOREGROU NDLOCKTIME OUT, 0, nil, 0);
result:=SetForegroundWindo w(FHandle) ;
SystemParametersInfo(SPI_S ETFOREGROU NDLOCKTIME OUT, 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.
const SPI_GETFOREGROUNDLOCKTIMEO
SPI_SETFOREGROUNDLOCKTIMEO
var timeout : cardinal;
begin
SystemParametersInfo(SPI_G
SystemParametersInfo(SPI_S
result:=SetForegroundWindo
SystemParametersInfo(SPI_S
This eliminates the blinking and instead moves the window really to the top (like it was in win95 and NT4).
Regards, Madshi.
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_GETFOREGROUNDLOCKTIMEO UT=2000;
const SPI_SETFOREGROUNDLOCKTIMEO UT=2001;
int timeout;
SystemParametersInfo(SPI_G ETFOREGROU NDLOCKTIME OUT,
0,&timeout,0);
SystemParametersInfo(SPI_S ETFOREGROU NDLOCKTIME OUT,
0, 0, 0);
SetForegroundWindow(hwnd);
SystemParametersInfo(SPI_S ETFOREGROU NDLOCKTIME OUT,
0, &timeout, 0);
Is this right,why no effect?
Thank you,MadShi,how to give you points?
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_GETFOREGROUNDLOCKTIMEO
const SPI_SETFOREGROUNDLOCKTIMEO
int timeout;
SystemParametersInfo(SPI_G
0,&timeout,0);
SystemParametersInfo(SPI_S
0, 0, 0);
SetForegroundWindow(hwnd);
SystemParametersInfo(SPI_S
0, &timeout, 0);
Is this right,why no effect?
Thank you,MadShi,how to give you points?
ASKER
To MadShi again:
Would you please tell me how the 2000 and 2001 come into play?
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_GETFOREGROUNDCLOCKTIME OUT 2000
#define SPI_SETFOREGROUNDCLOCKTIME OUT 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... (-:
In C++ it's something like
#define SPI_GETFOREGROUNDCLOCKTIME
#define SPI_SETFOREGROUNDCLOCKTIME
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... (-:
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_GETFOREGROUNDLOCKTIMEO UT 2000
#define SPI_SETFOREGROUNDLOCKTIMEO UT 2001
Sleep(4000);
int timeout;
ShowWindow(hwnd, SW_SHOW);
//SPI_GETACCESSTIMEOUT
SystemParametersInfo(SPI_G ETFOREGROU NDLOCKTIME OUT,
0,&timeout,0);
SystemParametersInfo
SPI_SETFOREGROUNDLOCKTIMEO UT,
0, 0, 0);
SetForegroundWindow(hwnd);
SystemParametersInfo(SPI_S ETFOREGROU NDLOCKTIME OUT,
0, &timeout, 0);
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_GETFOREGROUNDLOCKTIMEO
#define SPI_SETFOREGROUNDLOCKTIMEO
Sleep(4000);
int timeout;
ShowWindow(hwnd, SW_SHOW);
//SPI_GETACCESSTIMEOUT
SystemParametersInfo(SPI_G
0,&timeout,0);
SystemParametersInfo
SPI_SETFOREGROUNDLOCKTIMEO
0, 0, 0);
SetForegroundWindow(hwnd);
SystemParametersInfo(SPI_S
0, &timeout, 0);
ASKER
It seems the 2000 is not eligible ,where you this magic number ,Madsin?
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_GETFOREGROUNDLOCKTIMEO UT 0x2000
#define SPI_SETFOREGROUNDLOCKTIMEO UT 0x2001
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_GETFOREGROUNDLOCKTIMEO
#define SPI_SETFOREGROUNDLOCKTIMEO
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?
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... :-)
//after I have create a window...
Sleep(4000);
ShowWindow(hwnd, SW_SHOW);
BringWindowToTop ( hwnd); // <-- !!!
Feel free to ask if you need more information!