How do I dynamically create a new Swindow in the Soui window?

Source: Internet
Author: User

Some netizens often appear a problem is I the following code why in the Soui xxx window did not dynamically create a new window:

New Swindow (); Findchildbyname (L"xxx")->insertchild (pWnd);
The above code has 3 questions: 1, it does not display in the interface you new out of the child window. Because this newly inserted window does not specify a layout property. 2. This may crash when the program exits because memory allocations and translations may not be in the same module. 3. The various other properties in Pwnd are not initialized properly. The correct approach is to use the Swindow::createchildren (LPCWSTR Pszxml) method to create the window. Pszxml must be an XML string. What is the difference between Swindow::createchildren and the above code? Find this function first to look at its code:
1Swindow *Swindow::createchildren (lpcwstr pszxml)2     {3 pugi::xml_document xmldoc;4         if(!xmldoc.load_buffer (Pszxml,wcslen (pszxml) *sizeof(wchar_t), Pugi::p arse_default,pugi::encoding_utf16))returnNULL;5BOOL bloaded=Createchildren (xmldoc);6         if(!bloaded)returnNULL;7         Else returnM_plastchild;8     }9 Ten BOOL Swindow::createchildren (pugi::xml_node xmlNode) One     { A Testmainthread (); -          for(Pugi::xml_node xmlchild=xmlnode.first_child (); xmlchild; xmlchild=xmlchild.next_sibling ()) -         { the             if(Xmlchild.type ()! = pugi::node_element)Continue; -  -             if(_WCSICMP (Xmlchild.name (), klabelinclude) = =0) -{//support for include tags in window layouts +Sstringt strsrc = s_cw2t (Xmlchild.attribute (L"src"). Value ()); - pugi::xml_document xmldoc; + sstringtlist Strlst; A  at                 if(2==Parseresid (strsrc,strlst)) -                 { -LOADXML (xmldoc,strlst[1],strlst[0]); -}Else -                 { -LOADXML (xmldoc,strlst[0],rt_layout); in                 } -                 if(xmldoc) to                 { + Createchildren (Xmldoc.child (Klabelinclude)); -}Else the                 { * Sassert (FALSE); $                 }Panax Notoginseng}Else if(!xmlchild.get_userdata ())//flag whether a node can be ignored by UserData -             { theSwindow *pchild =Sapplication::getsingleton (). Createwindowbyname (Xmlchild.name ()); +                 if(pchild) A                 { the Insertchild (pchild); +Pchild->Initfromxml (xmlchild); -                 } $             } $         } -          -         returnTRUE; the}

Note The 39 lines and 43 lines of the above code.

39 line means let the Soui system new a Swindow object that matches the tag, view the code of Createwindowbyname, and discover that it is also a direct new object, but this is not the same as in the app layer new, Because this new object does not do special handling release is also within the Soui module, so the app layer is generally not directly new to a Window object.

The more root is the 43rd line, you should configure the layout properties and other related skin properties in XML. The newly created control will be displayed correctly by Soui these properties to the newly created object through this line.

How do I dynamically create a new Swindow in the Soui window?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.