Ecere SDK/eC Forums http://ecere.org/community/ Print view |
|
About form.Create() http://ecere.org/community/viewtopic.php?f=5&t=182 |
Page 1 of 1 |
Author: | samsam598 [ Thu Sep 08, 2011 3:53 am ] |
Post subject: | About form.Create() |
Given below code,with or without form.Create(),the form(window) shows anyhow.So what's the Window::Create() for?Could you please explain?thanks. Btw,I found WindlowList in the ecere/gui/dialogs/ directory,but have no clue how to use it.Could you please explain as well.Thanks. form2.ec: Code: Select all
Code: Select all
|
Author: | jerome [ Thu Sep 08, 2011 8:59 am ] |
Post subject: | Re: About form.Create() |
Hi Sam, Excellent questions, as always! When a parent window is created, any child window inside it automatically gets created as well, unless their 'autoCreate' property is set to false. This applies to top level windows as well when the 'desktop' is 'created'. The desktop is the default parent if you don't specify a parent or specify null for a window, and is the virtual space representing the user's desktop in windowed mode. In full-screen mode, the desktop actually behaves more like a regular window, it gets a default blue background color. The desktop 'creation' occurs from GuiApplication()::Main, right after calling Init(). This is why it doesn't change anything if you call Create() from within Init() or not, it gets done automatically because autoCreate is true. Therefore, Create() usually only needs to be called when you create a window at runtime, e.g. a pop-up window. Note that calling Modal() (e.g. for MessageBox) includes an implicit call to Create(), in addition to setting isModal to true, and running a modal loop that will return when the window is destroyed. As for WindowList, this is the list of Windows you see in the IDE when you select the Window/Windows... menu item. The way to use it is normally to assign the built-in Window::MenuWindowWindows method to a menu item in the MDI frame window's menu, which will automatically create it for you. You can seen an example in sdk/samples/guiAndGfx/mdiSample. Note that you are calling it properly, WindowList lists the window of its 'master', in your case the desktop because you didn't specify any master. However, WindowList only lists windows that have the isActiveClient property set to true: try setting it on your Form2 class. Also I see you used arrays there, you might want to play with the eC containers dynamic arrays: Array<Form2> forms { }; then you can do: forms.Add(Form2 { master = form1 }); or you can even do: Array<Form2> forms { [ { master = form1 }, { master = form1 }, { master = form1 }, { master = form1 }, { master = form1 } ] }; Regards, Jerome |
Author: | D.Bane [ Thu Sep 08, 2011 9:23 am ] |
Post subject: | Re: About form.Create() |
Hi Sam. Jerome will be able to answer you better, but I want to take a try at it as well You should use the .Create() when you want some class window to be created inside of a function/button press or where you need it. Code: Select all
Code: Select all
hehe Jerome answered me before I even stated the question Best Regards, D.Bane. |
Author: | samsam598 [ Thu Sep 08, 2011 7:23 pm ] |
Post subject: | Re: About form.Create() |
Thanks both!I would like to repeat,hey,I love this place @D.Bane:sorry I can't make my app run after adding the code you listed.Could you please provide the full source?Thank you again. Regards, Sam |
Author: | D.Bane [ Fri Sep 09, 2011 6:01 am ] |
Post subject: | Re: About form.Create() |
Hi Sam. I know exactly what you mean I will post both forms here, as it seems that it will upload only one file.. form1.ec Code: Select all
Code: Select all
I hope it will help you Best Regards, D.Bane. |
Author: | samsam598 [ Fri Sep 09, 2011 8:57 am ] |
Post subject: | Re: About form.Create() |
Hi D.Bane, Excellent example! Regards, Sam |
Author: | jerome [ Fri Sep 09, 2011 9:54 am ] |
Post subject: | Re: About form.Create() |
D.Bane, you should be able to upload 2 attachments on the forums. |
Author: | jerome [ Fri Sep 09, 2011 11:25 am ] |
Post subject: | Re: About form.Create() |
D.Bane, I noticed a couple of problems in your sample. 1. Surface::CenterTextf doesn't center vertically, only horizontally. So the 'y' position is the top of the text box, the 'top' of the Update box should be the same as the y coordinate in the call to CenterTextf 2. You should update the box in OnResize rather than in OnCreate, especially since you are using a resizable border. 3. You should use clientSize as opposed to size, clientSize is the size of the client area, excluding the title bar and resizing borders. 4. In your call to CenterTextf, you're using 'CopyString' which allocates a new string copy, there's no need and it is a memory leak. surface.CenterTextf(clentSize.w/2,clentSize.h/2, txt); is fine Here is the updated sample code: Code: Select all
Jerome |
Author: | D.Bane [ Fri Sep 09, 2011 11:43 am ] |
Post subject: | Re: About form.Create() |
Hi, Nice to hear that you liked it Sam. It is also nice to hear about the memory leak.. I don't know exactly why, but I remember having some kind of trouble with strings, and CopyString() made it all work nicely so I may have been over using it since (think in 0.43 version)... Thanks for pointing this out to me Jerome. Yes, thank you for pointing that out as well (point 2 and 3), about OnResize(). I was going for a working example, but have not made it properly :/ But, now I know more Will try to make the next one a perfect sample Best Regards, D.Bane. |
All times are UTC-05:00 | Page 1 of 1 |
Powered by phpBB® Forum Software © phpBB Limited |