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 » Community » Newbie corner » always on top SOLVED (GUI)
always on top SOLVED [message #46241] Fri, 01 April 2016 07:19 Go to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I have an app compiled may 2014 that is always on top.

I just updated M$VS to 2015 for the compiler and upp #9628

The code has this line:
TopMost(true, true).MinimizeBox();

When compiled and run now it is not always on top.

Has the upp code for always on top changed? If so what is used now?


Neil

[Updated on: Fri, 08 April 2016 20:56]

Report message to a moderator

Re: always on top [message #46244 is a reply to message #46241] Fri, 01 April 2016 21:02 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Hi nlneilson:

After some digging into the code, I find that the failure is because this line doesn't behave as it's expected or it used to behave:

in Win32Ctrl.h
	HWND  GetHWND() const	{
		return parent ? NULL : top ? top->hwnd : NULL;
	}


The reason of the failure is because when this function is called before you call Run() on the TopWindow derivative, parent is NULL, which is expected, and top is NULL too (this might have been changed either by UPP developers or is due to changes in Windows SDK). the top will only get a meanful value after Run() is called.

See the following code for an effect:
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct MyApp: public TopWindow
{
	MyApp()
	{
		Add(b.SetLabel("Set TopMost").SizePos());
		b<<=THISBACK(Clicked);
	}
	
	Button b;
	
	void Clicked()
	{
		this->TopMost();
	}
	
	typedef MyApp CLASSNAME;
};


GUI_APP_MAIN
{
	MyApp().TopMost().Run();
}


Notice the MyApp mainwindow is a normal window contrast to our will, but after click on the button, it becomes TopMost as requested. The only thing changed would be [b]top[/top]'s proper assignment after show.


I don't know how to fix the library code, but he's a quick workaround.

In you top window's construct, add one line:
     this->SetTimeCallback(0,THISBACK(SetTopMost));

And add a member function to your MyApp equivalent:
     void SetTopMost(){  TopMost();  }


for a reference:
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct MyApp: public TopWindow
{
	MyApp()
	{
		SetTimeCallback(0,THISBACK(SetTopMost));
	}
	
	
	void SetTopMost(){	this->TopMost(); }
	
	typedef MyApp CLASSNAME;
};


GUI_APP_MAIN
{
	MyApp().Run();
}
Re: always on top [message #46252 is a reply to message #46241] Sat, 02 April 2016 19:59 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Hi Lance Thanks for finding the cause of the problem

I have not been able to get my app changes as you suggested to get it to work for me.

doing a search for topmost I found this thread re the eye care example.

http://www.ultimatepp.org/forums/index.php?t=msg&goto=44 093&&srch=TopMost#msg_44093
Re: always on top [message #46253 is a reply to message #46252] Sat, 02 April 2016 23:43 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
It surprised me that it didn't work for you. The linked post is actually irrelevant to our situation.

If you can create a minimized sample, I can try and determine what goes wrong.

Before that, try the following
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

GUI_APP_MAIN
{
	TopWindow a;
	a.Open();
	a.TopMost().Run();
}


Replace TopWindow with your TopWindow direvative. This is neater way to guarantee the TopWinow(derivative)'s top->hwnd is initiallized, ie, call Open() before call TopMost().

If above won't work, then your problem is a little different, e.g., your ctrl might have a parent (which will result in GetHWND() returning NULL).

[Updated on: Sat, 02 April 2016 23:59]

Report message to a moderator

Re: always on top [message #46258 is a reply to message #46241] Sun, 03 April 2016 03:53 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
attached is test 2 which was a very early example I tinkered with.

I am not used to how the FUDforum is setup, it makes my head hurt until I get used to it.
  • Attachment: Test2.zip
    (Size: 1.44KB, Downloaded 174 times)

[Updated on: Sun, 03 April 2016 04:16]

Report message to a moderator

Re: always on top [message #46259 is a reply to message #46258] Sun, 03 April 2016 04:29 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Here are the first lines of my app:

NefbG2() {
ver = " v2.1"; // snd Sleep time line 1895
// time_t tEnd = 1500e6; // 1 for ~11.6 days;
time_t tEnd = 1480e6; // 1 for ~11.6 days;
CtrlLayout(*this, "NefbG2 © " + ver);
TopMost(true, true).MinimizeBox();
NoCenter();
// FrameLess(true);
AddFrame(menu); // To make a menu bar you must add the frame before setting the callback
menu.Set(THISBACK(MainMenu)); // Set the menu callback

P1 <<= THISBACK(Point1Action);
P2 <<= THISBACK(Point2Action);

fnum = 1;
IO = true; ioX = false;
slocX = false;
cfgfile = "nefbg2.cfg";
reset();


Re: always on top [message #46264 is a reply to message #46259] Sun, 03 April 2016 13:54 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Test2 doesn't compile.
String AddNum2 ( int a, int b ) {
	if ( a > b )
	//	t1<<="2 OK";
		Set_t1("2 OK");	
}


Set_t1 is not defined. And the function should return something. Anyway, after comment the Set_t1 thing and return an empty String, and change your GUI_MAIN to something like
GUI_APP_MAIN {
	H1 h;
	h.Open();
	h.TopMost().Run();
}


It works like a charm.
Re: always on top [message #46265 is a reply to message #46259] Sun, 03 April 2016 14:03 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
nlneilson wrote on Sat, 02 April 2016 22:29
Here are the first lines of my app:

NefbG2() {
ver = " v2.1"; // snd Sleep time line 1895
// time_t tEnd = 1500e6; // 1 for ~11.6 days;
time_t tEnd = 1480e6; // 1 for ~11.6 days;
CtrlLayout(*this, "NefbG2 © " + ver);
TopMost(true, true).MinimizeBox();
NoCenter();
// FrameLess(true);
AddFrame(menu); // To make a menu bar you must add the frame before setting the callback
menu.Set(THISBACK(MainMenu)); // Set the menu callback

P1 <<= THISBACK(Point1Action);
P2 <<= THISBACK(Point2Action);

fnum = 1;
IO = true; ioX = false;
slocX = false;
cfgfile = "nefbg2.cfg";
reset();




Is NefbG2 a TopWindow derivative?
		TopMost(true, true).MinimizeBox();


Move this line (you might do without moving it, just in case) to the end of the NefbG2 constructor, and insert a call to Open() before it. End result is something like this:
	NefbG2() {
		ver = "  v2.1"; // snd Sleep time line 1895
//		time_t tEnd = 1500e6; // 1 for ~11.6 days;
		time_t tEnd = 1480e6; // 1 for ~11.6 days;
		CtrlLayout(*this, "NefbG2 ©   " + ver);
		NoCenter();
//		FrameLess(true);
		AddFrame(menu); 		// To make a menu bar you must add the frame before setting the callback
		menu.Set(THISBACK(MainMenu));   // Set the menu callback
		
		P1 <<= THISBACK(Point1Action);
		P2 <<= THISBACK(Point2Action);
		
		fnum = 1;
		IO = true; ioX = false;
		slocX = false;
	    cfgfile = "nefbg2.cfg";
		reset();
                
                Open();      //<-----Added
		TopMost(true, true).MinimizeBox();   //<---- Moved

Re: always on top [message #46268 is a reply to message #46241] Mon, 04 April 2016 13:06 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Hi Lance Thanks for the suggestions.
I have other problems with the code, a zip file or whatever.
I will try your suggestions when I get my computer straightened out, I had to wipe my hard drive and re-install Win 7 a while back because of problems installing Ubuntu, I think.
Re: always on top [message #46284 is a reply to message #46258] Fri, 08 April 2016 03:56 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I searched my old threads/posts to see where I started from in January 2010 and a 'minimalistic' example or test case is still in the tutorial: Gui07

How can that be made as 'top window/ always on top ???

Neil
Re: always on top [message #46291 is a reply to message #46284] Fri, 08 April 2016 15:10 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
change the gui_app_main from
GUI_APP_MAIN
{
	MyAppWindow app;
	app.Run();
}


to

GUI_APP_MAIN
{
	MyAppWindow app;
	app.Open();
	app.TopMost().Run();
}



Re: always on top SOLVED [message #46293 is a reply to message #46241] Fri, 08 April 2016 20:45 Go to previous message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks Lance, that works good.

The app I am working on doesn't really do anything alone but controls a 3D globe app that is in java (NASA WWJ}

It has to stay on top.

[Updated on: Fri, 08 April 2016 20:48]

Report message to a moderator

Previous Topic: upp-mingw-9671 with win\upp9628 SOLVED
Next Topic: link error with MINGW - - SOLVED
Goto Forum:
  


Current Time: Thu Mar 28 17:02:48 CET 2024

Total time taken to generate the page: 0.01499 seconds