|
|
Home » Community » Newbie corner » Question on a widget on top of a widget **BUG STATEMENTS NOT COMPLETED BEFORE NEXT STATEMENT
|
Re: Question on a widget on top of a widget [message #33287 is a reply to message #33281] |
Fri, 22 July 2011 16:16   |
|
Hi silverx,
If I understand correctly, you wan't to do something like this:#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class App:public TopWindow {
typedef App CLASSNAME;
Button b;
EditString e;
public:
App(){
b.SetLabel("Click me!"); //set the button text
Add(b.HCenterPos(100).VCenterPosZ(30)); //add button to the window
b.Add(e.HCenterPos(80).VCenterPos(20)); //add editfield to the button,
//positioning is relative to the button
b<<=THISBACK(SwitchEdit); // assign function to the button click
e.Hide(); // hide the editfield initialy
}
void SwitchEdit(){
e.Show(!e.IsShown()); // switch the visibility
}
};
GUI_APP_MAIN{
App().Sizeable().Run();
}
As you can see, you can just easily Add a Ctrl into any other Ctrl. Simple solutions are often the best 
Best regards,
Honza
PS: Forgot to mention that if you're using layouts, you can use the button from layout, but the "second layer" ctrl must be added in code. (Well, actually you COULD, but it is bit more complicated and seldom necessary...). Also, you can add more than one widget or even entire layout.
[Updated on: Fri, 22 July 2011 16:21] Report message to a moderator
|
|
|
Re: Question on a widget on top of a widget [message #33288 is a reply to message #33287] |
Fri, 22 July 2011 17:02   |
silverx
Messages: 62 Registered: March 2011
|
Member |
|
|
Thanks for the information, but it still didn't work.
What is the difference between .Hide and .Show(false)?
That is what I was using. The other thing is all items where added from layout and not from any code. Why should that make any difference?
I would prefer to build it in Layout instead of in code, if possible.
But if I do set it in code I need to set the size and position with .SetRect, is the x and y based upon the item it is added to?
Also I tried your code, but changing from App to T5, Code is:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class T5:public TopWindow {
typedef T5 CLASSNAME;
Button b;
EditString e;
public:
T5(){
b.SetLabel("Click me!"); //set the button text
Add(b.HCenterPos(100).VCenterPosZ(30)); //add button to the window
b.Add(e.HCenterPos(80).VCenterPos(20)); //add editfield to the button,
//positioning is relative to the button
b<<=THISBACK(SwitchEdit); // assign function to the button click
e.Hide(); // hide the editfield initialy
}
void SwitchEdit(){
e.Show(!e.IsShown()); // switch the visibility
}
};
GUI_APP_MAIN{
T5().Sizeable().Run();
}
And I get the following error:
t5: 1 file(s) built in (0:02.35), 2356 msecs / file, duration = 2356 msecs, parallelization 0%
Linking...
LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
C:\upp\out\MSC9.Debug.Debug_full\t5.exe : fatal error LNK1120: 1 unresolved externals
There were errors. (0:02.88)
In addition I tried to do the add of the object in my code to my program, and just set position and FrameSet so I could see it. When I execute the code it does show up, but then when I start using it, it never comes back. The only way it shows up is if I do a PromptOK after I do the .Show.
I did the add in code using the following. It is for my own widget, that I have defined, after button.
W1.Add(E1.HCenterPos(10).VCenterPos(10));
W2.Add(E2.HCenterPos(10).VCenterPos(10));
E1.SetFrame(BlackFrame());
E2.SetFrame(BlackFrame());
I am using a image in the both cases, I just want the second image to show up for about 1 second then hide it again on top of the other image.
I think it is a bug on Windows Vista.
|
|
|
Re: Question on a widget on top of a widget [message #33289 is a reply to message #33288] |
Fri, 22 July 2011 17:48   |
|
silverx wrote on Fri, 22 July 2011 17:02 | What is the difference between .Hide and .Show(false)
| There is no difference, Hide() exists just for convenience.
silverx wrote on Fri, 22 July 2011 17:02 | That is what I was using. The other thing is all items where added from layout and not from any code. Why should that make any difference?
I would prefer to build it in Layout instead of in code, if possible.
| Everything in layout is automatically Add()ed to the TopWindow. Well, IIRC, calling Add() on already added Ctrl is legal (it calls remove first), so theoretically you can put it in layout, but you still need to call the Add() in the code and probably also reposition it.
silverx wrote on Fri, 22 July 2011 17:02 | But if I do set it in code I need to set the size and position with .SetRect, is the x and y based upon the item it is added to?
| Yes, everything is then positioned relatively to the top-left corner of the parent Ctrl.
silverx wrote on Fri, 22 July 2011 17:02 | Also I tried your code, but changing from App to T5, Code is:
...
And I get the following error:
t5: 1 file(s) built in (0:02.35), 2356 msecs / file, duration = 2356 msecs, parallelization 0%
Linking...
LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
C:\upp\out\MSC9.Debug.Debug_full\t5.exe : fatal error LNK1120: 1 unresolved externals
There were errors. (0:02.88)
|
You forget to add a GUI flag 
silverx wrote on Fri, 22 July 2011 17:02 | In addition I tried to do the add of the object in my code to my program, and just set position and FrameSet so I could see it. When I execute the code it does show up, but then when I start using it, it never comes back. The only way it shows up is if I do a PromptOK after I do the .Show.
I did the add in code using the following. It is for my own widget, that I have defined, after button.
W1.Add(E1.HCenterPos(10).VCenterPos(10));
W2.Add(E2.HCenterPos(10).VCenterPos(10));
E1.SetFrame(BlackFrame());
E2.SetFrame(BlackFrame());
I am using a image in the both cases, I just want the second image to show up for about 1 second then hide it again on top of the other image.
I think it is a bug on Windows Vista.
|
I don't see anything wrong with the posted line, the problem is probably somewhere else. Can't say where without seeing more of the code. Anyway, I am pretty sure that it is not related to Windows 
Honza
|
|
|
|
|
Re: Question on a widget on top of a widget [message #33294 is a reply to message #33293] |
Fri, 22 July 2011 23:07   |
|
silverx wrote on Fri, 22 July 2011 21:38 | It appears that the code to do things stop working when I have Sleep(x) after the command.
Things are not processed in order, and continue with the next command after the previous command is completed.
To me this is a bug in the system. It should complete the previous command before starting the next command.
Any way to force a commands to complete before starting the next command in the program?
David
|
Yes this is one of the problems. It is not a bug, it works exactly as intended. Sleep just sleeps, halting all the code execution. To force the changes to be drawn to screen, you can call Sync() method, which causes all the areas marked to be refreshed to be redrawn.
The second thing is that overriding the Paint() method seems like an overkill, at least in the example code you sent. You are using SetImage to cover the entire area of button, so the changes you did to the painting routine are not visible anyway. And if I understood it correctly the only intention was to hide the borders, which can be achieved in simpler way just by calling Hide() in constructor and Show() when starting the quiz 
Honza
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 10:32:36 CEST 2025
Total time taken to generate the page: 0.00862 seconds
|
|
|