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 » Multiple windows and focus
Multiple windows and focus [message #10368] Wed, 04 July 2007 12:41 Go to previous message
jibe is currently offline  jibe
Messages: 294
Registered: February 2007
Location: France
Experienced Member
Hi,

I need to have several windows in an application, one for each part. Those windows are created on demand, several can be opened in the same time. When I need one, it must be either created, or focus must be given to it if existing. Let's say that it's somehow similar to MS Windows' MDI apps.

I tried this :

#ifndef _MultiWin_MultiWin_h
#define _MultiWin_MultiWin_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;


class Win1 : public TopWindow {
public:
	typedef Win1 CLASSNAME;
	Win1();
	~Win1();
	void Close();
};

class Win2 : public TopWindow {
public:
	typedef Win2 CLASSNAME;
	Win2();
	~Win2();
	void Close();
};

class MultiWin : public TopWindow {
protected:
	MenuBar menu;
public:
	typedef MultiWin CLASSNAME;
	MultiWin();
	void MainMenu(Bar& bar);
	void Window1();
	void Window2();
};

Win1 *win1;
Win2 *win2;

#endif

#include "MultiWin.h"

MultiWin::MultiWin()
{
	Title("Test multiple windows").MinimizeBox().Sizeable();
	AddFrame(menu);
	AddFrame(TopSeparatorFrame());
    menu.Set(THISBACK(MainMenu));
}

void MultiWin::MainMenu(Bar& bar) {
    bar.Add("Window 1", THISBACK(Window1));
    bar.Add("Window 2", THISBACK(Window2));
}

void MultiWin::Window1() {
	if (win1==NULL) {
		win1=new Win1();
		win1->OpenMain();
	}
	else {
		this->LostFocus();
		win1->SetFocus();
	}
}

void MultiWin::Window2() {
	if (win2==NULL) {
		win2=new Win2();
		win2->OpenMain();
	}
	else {
		this->LostFocus();
		win2->SetFocus();
	}
}

Win1::Win1() {
	Title("Window 1").MinimizeBox().Sizeable();
}

Win1::~Win1() {
	win1=NULL;
}

void Win1::Close() {
	delete this;
}

Win2::Win2() {
	Title("Window 2").MinimizeBox().Sizeable();
}

Win2::~Win2() {
	win2=NULL;
}

void Win2::Close() {
	delete this;
}

GUI_APP_MAIN
{
	MultiWin().Run();
}


It works well, but when I try to re-open an existing window, it seems to get the focus but don't comes on the top of all others !

I tried a lot of things, but was unable find a solution... What can I do ? Is there a better way to do what I need to stay in "UPP spirit" ?

Thanks.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Can't get rid of minimize button on Linux, okay on Win32
Next Topic: System tray on windows
Goto Forum:
  


Current Time: Fri Mar 29 00:20:14 CET 2024

Total time taken to generate the page: 0.00453 seconds