Home » U++ Library support » TopWindow&PopUp, TrayIcon » Windows that cant leave Mainwindow
|
|
Re: Windows that cant leave Mainwindow [message #30472 is a reply to message #30469] |
Mon, 03 January 2011 13:31   |
|
Hi Jens!
Welcome to the U++ 
Jschn88 wrote on Mon, 03 January 2011 11:33 |
The subwindows should only be moved arround in the mainwindow and are not allowed to leave it.
|
If I understand right, you want something like this: #include <CtrlLib/CtrlLib.h>
using namespace Upp;
class RestrictedTopWindow:public TopWindow{
TopWindow* parent;
typedef RestrictedTopWindow CLASSNAME;
public:
RestrictedTopWindow(TopWindow* parent):parent(parent){
SetTimeCallback(-50,THISBACK(CheckPos));
}
void CheckPos(){
Rect allowed=parent->GetRect();
Rect r=GetRect();
if(!r.Contains(allowed)){
SetRect(minmax(r.left,allowed.left,allowed.right-r.GetWidth()),
minmax(r.top,allowed.top,allowed.bottom-r.GetHeight()),
r.GetWidth(),r.GetHeight());
}
}
};
class App :public TopWindow {
typedef App CLASSNAME;
public:
RestrictedTopWindow rtw;
App():rtw(this){
Title("MainWindow");
}
void LeftUp(Point p,dword){
rtw.SetRect(p.x,p.y,200,100);
rtw.Title("Child window").Sizeable().Run();
}
};
GUI_APP_MAIN{
App().Sizeable().Run();
} This code is of course oversimplified and probably not very clever anyway, but it might give you some ideas to start with. The basic idea is that you derive your custom class from TopWindow (or some TopWindow-derived class) which checks periodically if its location is correct and reposition itself if necessary. Checking every 100ms is fine enough to go unnoticed for human eye 
I didn't find any better way to do it, but that doesn't mean that there is none I think there is no callback or virtual method that is called upon repositioning of window, so unless I missed something this is out of scope. But there might a nicer way how to achieve what you want using Docking windows (have a look in bazaar and search here on the forum).
Best regards,
Honza
EDIT: Fixed an error in the code
[Updated on: Mon, 03 January 2011 14:43] Report message to a moderator
|
|
|
|
Re: Windows that cant leave Mainwindow [message #31776 is a reply to message #30473] |
Sat, 26 March 2011 09:52  |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
I think the best way to achieve this is to not use TopWindows at all. Just create a child control that looks like a window and is dragable around the client area. This will naturally restrict it to the window's area and allow you a lot more flexibility in how the system works.
|
|
|
Goto Forum:
Current Time: Tue Apr 22 08:01:59 CEST 2025
Total time taken to generate the page: 0.02203 seconds
|