Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
gprentice is currently offline  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();
}

Re: Fix for TopMost on Win32 to allow it to be changed at any time. [message #5535 is a reply to message #5530] Sun, 01 October 2006 18:47 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
gprentice wrote on Sat, 30 September 2006 21:02

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.



Thanks.

Quote:


I don't know why the first call to TopMost actually succeeds - I don't particularly care either!



I think it is because there are two phases there (which U++ usually makes look the same, but windows not) - I think that you have done the first call before opening the window (HWND does not exist), so exstyle is used for CreateWindow.

Quote:


Any idea why the code navigator takes me to TopWinX11.cpp when I use "goto definition" on the call to TopMost() ?



It should cycle through all places where it is defined/declared.

And, of course, the heurestic parser is still not perfect Smile
Previous Topic: Testers Needed for trayicon for linux version 0.2
Next Topic: [Solved] How to merge two EventLoops together
Goto Forum:
  


Current Time: Tue Apr 16 19:46:03 CEST 2024

Total time taken to generate the page: 0.02063 seconds