Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Window without title bar
|
|
|
|
|
Re: Window without title bar [message #14129 is a reply to message #14126] |
Wed, 13 February 2008 16:41   |
Werner
Messages: 234 Registered: May 2006 Location: Cologne / Germany
|
Experienced Member |
|
|
Some time ago I wrote a UPT ("StandardApplication") which also creates a splash screen. You can get it at message #8210 (Home » Developing Ultimate++ » Bazaar » New UPT: Standard Application). The UPT creates, among other files, 2 files named "...Splash.hpp" and "...Splash.cpp". Maybe a closer look at these 2 files might help you.
Furthermore you might want to have a look at the following code which deals with a popup window. But beware, it's very simple. Just a proof of concept for another U++ feature (Single).
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class PopUpWin : public LineEdit
{
private:
bool poppedUp_;
void RightDown(Point p, dword keyFlags)
{
Close();
poppedUp_ = false;
}
public:
PopUpWin() : poppedUp_(false) { }
void SetPoppedUp(bool yesNo) { poppedUp_ = yesNo; }
bool IsPoppedUp() const { return poppedUp_; }
};
class MainWin : public TopWindow
{
private:
void LeftDown(Point p, dword keyFlags)
{
if (Single<PopUpWin>().IsPoppedUp())
return;
Single<PopUpWin>().SetPoppedUp(true);
Single<PopUpWin>().LeftPos(300, 200).TopPos(300, 150);
Single<PopUpWin>().SetColor(TextCtrl::PAPER_NORMAL,Blue);
Single<PopUpWin>().SetColor(TextCtrl::INK_NORMAL, White);
Single<PopUpWin>().PopUp
(
this, // Ctrl* owner = NULL
true, // bool savebits = true
true, // bool activate = true
true, // bool dropshadow = false
false // bool topmost = false
);
}
};
GUI_APP_MAIN
{
MainWin mainWin;
mainWin.SetRect(0, 0, 800, 600);
mainWin.Run();
}
Werner
|
|
|
|
Re: Window without title bar [message #14131 is a reply to message #14130] |
Wed, 13 February 2008 21:06   |
Werner
Messages: 234 Registered: May 2006 Location: Cologne / Germany
|
Experienced Member |
|
|
Meanwhile I finished my "single"-ruminations.
At the same time I improved my popup-window test application.
Perhaps the code is interesting to you because it deals with the possible GUI effects "slide" and "fade".
Here it is:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class PopUpWin : public LineEdit
{
private:
bool poppedUp_;
void RightDown(Point p, dword keyFlags)
{
Close();
poppedUp_ = false;
}
public:
PopUpWin() : poppedUp_(false) { }
void SetPoppedUp(bool yesNo) { poppedUp_ = yesNo; }
bool IsPoppedUp() const { return poppedUp_; }
};
class MainWin : public TopWindow
{
private:
typedef MainWin CLASSNAME;
void NoEffect()
{
Single<PopUpWin>().SetPoppedUp(true);
Single<PopUpWin>().SetRect(300, 300, 600, 400);
Single<PopUpWin>().SetColor(TextCtrl::PAPER_NORMAL, White);
Single<PopUpWin>().SetColor(TextCtrl::INK_NORMAL, Black);
Single<PopUpWin>().PopUp
(
this, // Ctrl* owner = NULL
true, // bool savebits = true
true, // bool activate = true
true, // bool dropshadow = false
false // bool topmost = false
);
}
void SlideEffect()
{
Single<PopUpWin>().SetPoppedUp(true);
Single<PopUpWin>().SetRect(300, 300, 6, 4);
Single<PopUpWin>().SetColor(TextCtrl::PAPER_NORMAL, White);
Single<PopUpWin>().SetColor(TextCtrl::INK_NORMAL, Black);
Single<PopUpWin>().PopUp
(
this, // Ctrl* owner = NULL
true, // bool savebits = true
true, // bool activate = true
true, // bool dropshadow = false
false // bool topmost = false
);
Ctrl::ProcessEvents();
Animate(Single<PopUpWin>(), RectC(300, 300, 600, 400), GUIEFFECT_SLIDE);
}
void FadeEffect()
{
Single<PopUpWin>().SetPoppedUp(true);
Single<PopUpWin>().SetRect(300, 300, 600, 400);
Single<PopUpWin>().SetColor(TextCtrl::PAPER_NORMAL, White);
Single<PopUpWin>().SetColor(TextCtrl::INK_NORMAL, Black);
Single<PopUpWin>().PopUp
(
this, // Ctrl* owner = NULL
true, // bool savebits = true
true, // bool activate = true
true, // bool dropshadow = false
false // bool topmost = false
);
Ctrl::ProcessEvents();
Animate(Single<PopUpWin>(), RectC(300, 300, 600, 400), GUIEFFECT_FADE);
}
void local_menu(Bar& bar)
{
MenuBar local_menu;
bar.Add("no effect", THISBACK(NoEffect));
bar.Add("slide effect", THISBACK(SlideEffect));
bar.Add("fade effect", THISBACK(FadeEffect));
local_menu.Execute();
}
void LeftDown(Point p, dword keyFlags)
{
if (Single<PopUpWin>().IsPoppedUp())
return;
MenuBar::Execute(THISBACK(local_menu));
}
};
GUI_APP_MAIN
{
MainWin mainWin;
mainWin.SetRect(0, 0, 800, 600);
mainWin.Run();
}
Werner
[Updated on: Wed, 13 February 2008 21:10] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Window without title bar [message #14138 is a reply to message #14135] |
Thu, 14 February 2008 18:07   |
mr_ped
Messages: 826 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
mrjt wrote on Thu, 14 February 2008 16:18 | Isn't the difference that Singletons/Single<>s only get memory allocated on heap when they are first used?
Not that this is ever really useful 
|
That's completely true.
And I'm still missing any real world scenario where you need global variable allocated as late as possible. I mean, I can't even imagine one, and I really tried for couple of minutes. 
Even if such need would arise, you can still have global pointer to some memory huge object which is instantiated later into the program (at the moment when you find it appropriate).
I mean, the singletons are nice in the way you don't need to think what part of program you are in, and if that global variable has been already initialized. While some people may find this property as an advantage, I think it's actually major drawback instead. They sort of hide the structure of code and data-flow by making the initialization and usage to look the same.
It's better to understand when/how/why are executed parts of your application and when components need to be initialized, than fixing lack of understanding by using fool-proof classes.
I mean the fool-proof part of code is not a bad thing, but it should save you in case of your mistake (and detect+report that in ideal world so it gets noticed), not deliberately using it all the time and working without clue why you are doing that piece of code there but it "oh, just works anyway so who cares".
|
|
|
|
Re: Window without title bar [message #14142 is a reply to message #14139] |
Thu, 14 February 2008 22:06  |
Werner
Messages: 234 Registered: May 2006 Location: Cologne / Germany
|
Experienced Member |
|
|
Ok. Just to reconcile those singleton-haters I have created a tiny demo, featuring multiple main windows and multiple subwindows (at most 1 subwindow in 1 main window lest Windows (!) crashes ) with slide effect and fade effect - it goes without saying: WITHOUT using "Single", to say nothing of "singleton".
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class PopUpWin : public LineEdit
{
private:
bool poppedUp_;
void RightDown(Point p, dword keyFlags)
{
Close();
poppedUp_ = false;
}
public:
PopUpWin() : poppedUp_(false) { }
void SetPoppedUp(bool yesNo) { poppedUp_ = yesNo; }
bool IsPoppedUp() const { return poppedUp_; }
};
class MainWin : public TopWindow
{
private:
typedef MainWin CLASSNAME;
static int mainWinCount;
PopUpWin popUp;
virtual void Paint(Draw& w)
{
w.DrawRect(GetSize(), WhiteGray);
w.DrawText(0, 0, "Click left for context menu");
}
virtual void Close()
{
delete this; // window is on the heap
}
void AddMainWin()
{
(new MainWin)->OpenMain();
}
void NoEffect()
{
if (popUp.IsPoppedUp())
return;
popUp.SetPoppedUp(true);
Rect mainRect = GetScreenRect();
popUp.SetRect(mainRect.left + 20, mainRect.top + 20, 300, 225);
popUp.SetColor(TextCtrl::PAPER_NORMAL, LtBlue);
popUp.SetColor(TextCtrl::INK_NORMAL, Yellow);
popUp.Set(String("no effect\nclick right to close"));
popUp.PopUp
(
this, // Ctrl* owner = NULL
true, // bool savebits = true
true, // bool activate = true
true, // bool dropshadow = false
false // bool topmost = false
);
}
void SlideEffect()
{
if (popUp.IsPoppedUp())
return;
popUp.SetPoppedUp(true);
Rect mainRect = GetScreenRect();
popUp.SetRect(mainRect.left + 20, mainRect.top + 20, 4, 3);
popUp.SetColor(TextCtrl::PAPER_NORMAL, LtRed);
popUp.SetColor(TextCtrl::INK_NORMAL, White);
popUp.Set(String("slide effect\nclick right to close"));
popUp.PopUp
(
this, // Ctrl* owner = NULL
true, // bool savebits = true
true, // bool activate = true
true, // bool dropshadow = false
false // bool topmost = false
);
Ctrl::ProcessEvents();
Animate(popUp, RectC(mainRect.left + 20, mainRect.top + 20, 300, 225), GUIEFFECT_SLIDE);
}
void FadeEffect()
{
if (popUp.IsPoppedUp())
return;
popUp.SetPoppedUp(true);
Rect mainRect = GetScreenRect();
popUp.SetRect(mainRect.left + 20, mainRect.top + 20, 300, 225);
popUp.SetColor(TextCtrl::PAPER_NORMAL, LtGreen);
popUp.SetColor(TextCtrl::INK_NORMAL, Blue);
popUp.Set(String("fade effect\nclick right to close"));
popUp.PopUp
(
this, // Ctrl* owner = NULL
true, // bool savebits = true
true, // bool activate = true
true, // bool dropshadow = false
false // bool topmost = false
);
Ctrl::ProcessEvents();
Animate(popUp, RectC(mainRect.left + 20, mainRect.top + 20, 300, 225), GUIEFFECT_FADE);
}
void local_menu(Bar& bar)
{
MenuBar local_menu;
bar.Add("new main window", THISBACK(AddMainWin));
bar.Add("subwindow with no effect", THISBACK(NoEffect));
bar.Add("subwindow with slide effect", THISBACK(SlideEffect));
bar.Add("subwindow with fade effect", THISBACK(FadeEffect));
local_menu.Execute();
}
void LeftDown(Point p, dword keyFlags)
{
MenuBar::Execute(THISBACK(local_menu));
}
public:
MainWin()
{
++mainWinCount;
String title("Multi-windowed App with Subwindow: Window # ");
Title(title + AsString(mainWinCount));
SetRect(40 * mainWinCount, 40 * mainWinCount, 400, 300);
NoCenter();
}
~MainWin()
{
--mainWinCount;
}
};
int MainWin::mainWinCount = 0;
GUI_APP_MAIN
{
(new MainWin)->OpenMain(); // anytime deleteable
Ctrl::EventLoop();
}
Enjoy!
Werner
|
|
|
Goto Forum:
Current Time: Mon Apr 28 18:03:25 CEST 2025
Total time taken to generate the page: 0.00586 seconds
|