Home » U++ Library support » TopWindow&PopUp, TrayIcon » Fix for TopMost on Win32 to allow it to be changed at any time.
Fix for TopMost on Win32 to allow it to be changed at any time. [message #5530] |
Sun, 01 October 2006 03:02 |
gprentice
Messages: 260 Registered: November 2005 Location: New Zealand
|
Experienced Member |
|
|
Hi
I've found that on Win32, calling TopMost to change the topmost property doesn't work the second or subsequent times. SDK help says SetWindowPos has to be called to change it. UPP is currently calling SetWindowLong. The code below works for me. I added the second param stay_visible to allow choice of the window not disappearing immediately when it's made non-topmost.
I had to still do the call to ExStyle so the flag would get set - without it, the topmost property changes as desired but subsequent calls to GetWindowLong won't have the flag in the correct state. There might be better ways to do this.
I don't know why the first call to TopMost actually succeeds - I don't particularly care either!
Any idea why the code navigator takes me to TopWinX11.cpp when I use "goto definition" on the call to TopMost() ?
Graeme
TopWindow& TopMost(bool b = true, bool stay_visible = true);
TopWindow& TopWindow::TopMost(bool b, bool stay_visible)
{
HWND hwnd;
if(hwnd = GetHWND())
{
SetWindowPos(hwnd, b ? HWND_TOPMOST : (stay_visible ? HWND_NOTOPMOST : HWND_BOTTOM),0,0,0,0,SWP_NOMOVE|SWP_NOSIZE );
}
return ExStyle(b ? GetExStyle() | WS_EX_TOPMOST : GetExStyle() & ~WS_EX_TOPMOST);
}
Following is some code to test if you want - modified hello world.
#include <CtrlLib/CtrlLib.h>
#include <stdio.h>
class HelloWorld : public TopWindow {
MenuBar menu;
StatusBar status;
Button button;
bool tm;
void FileMenu(Bar& bar);
void MainMenu(Bar& bar);
void About();
void swap_topmost(){
char buf[100];
tm = !tm;
if (tm)
{
TopMost(true);
//button.SetLabel("No");
}
else
{
TopMost(false,true);
//button.SetLabel(ToString(123));
}
typedef unsigned int uint;
sprintf(buf,"%u %u %u",(uint)GetExStyle(),GetStyle(),tm);
button.SetLabel(buf);
}
public:
typedef HelloWorld CLASSNAME;
HelloWorld();
};
void HelloWorld::About()
{
PromptOK("{{1@5 [@9= This is the]::@2 [A5@0 Ultimate`+`+ Hello world sample}}");
}
void HelloWorld::FileMenu(Bar& bar)
{
bar.Add("About..", THISBACK(About));
bar.Separator();
bar.Add("Exit", THISBACK(Close));
}
void HelloWorld::MainMenu(Bar& bar)
{
menu.Add("File", THISBACK(FileMenu));
}
HelloWorld::HelloWorld()
{
AddFrame(menu);
AddFrame(status);
menu.Set(THISBACK(MainMenu));
status = "Welcome to the Ultimate++ !";
button <<= THISBACK(swap_topmost);
tm = false;
button.SetLabel("&I'm an Ultimate++ button!");
Add(button.VCenterPos(20).HCenterPos(200));
Sizeable().TopMost();
}
GUI_APP_MAIN
{
SetLanguage(LNG_ENGLISH);
HelloWorld().Run();
}
|
|
|
|
Goto Forum:
Current Time: Fri Mar 29 12:07:31 CET 2024
Total time taken to generate the page: 0.01562 seconds
|