Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data transfer using Property sheets 1

Status
Not open for further replies.

zulfi1234

Instructor
Jul 2, 2000
32
PK
I have&nbsp;&nbsp;got three&nbsp;&nbsp;CSTring data members in Document class. These are initialized using the document constructor. The OnDraw() function&nbsp;&nbsp;displays these string. I have a property sheet which has 3 Tabbed&nbsp;&nbsp;dialogs. Each dialog has a edit box which is connected with a CString. Now I want what ever the user types in the edit boxes of property pages, it should be displayed using OnDraw. The property sheet is invoked using a handler which is in view class. How can I have data exchange between document & property sheet class?<br><br>CPSFontDoc::CPSFontDoc()<br>{<br> m_str1= _T(&quot;First&nbsp;&nbsp;String&quot;);<br> m_str2= _T(&quot;Second String&quot;);<br> m_str3= _T(&quot;Third&nbsp;&nbsp;String&quot;);<br>&nbsp;&nbsp;&nbsp;:<br>&nbsp;&nbsp;&nbsp;:<br>}<br>void CPSFontView::OnViewTextsetting() <br>{<br> <br> CLine1&nbsp;&nbsp;line1;<br> CLine2&nbsp;&nbsp;line2;<br> CLine3&nbsp;&nbsp;line3;<br><br> CTextPage&nbsp;&nbsp;dlgText(_T(&quot;Tabbed Options&quot;), this);<br> dlgText.AddPage(&line1);<br> dlgText.AddPage(&line2);<br> dlgText.AddPage(&line3);<br><br> dlgText.DoModal();<br>}<br>
 
Dear zulfi1234,<br><br>In each of - CLine1, CLine2, CLine3 classes add a function line this:<br><br>public:<br>&nbsp;&nbsp;LPCTSTR getString(){ return m_whatever; } // return the CString variable<br><br>Now Remove the void CPSFontView::OnViewTextsetting() handler from your view class, then create a handler for that same command in your document class so you will end up with this:<br><br>void CPSFontDoc::OnViewTextsetting() <br>{<br><br>CLine1&nbsp;&nbsp;line1;<br>CLine2&nbsp;&nbsp;line2;<br>CLine3&nbsp;&nbsp;line3;<br><br>CTextPage&nbsp;&nbsp;dlgText(_T(&quot;Tabbed Options&quot;), this);<br>dlgText.AddPage(&line1);<br>dlgText.AddPage(&line2);<br>dlgText.AddPage(&line3);<br><br>// now add this code<br>if( IDOK == dlgText.DoModal()){<br>&nbsp;&nbsp;m_str1 = line1.getString();<br>&nbsp;&nbsp;m_str2 = line2.getString();<br>&nbsp;&nbsp;m_str3 = line3.getString();<br>&nbsp;&nbsp;UpdateAllViews();<br>}<br>}<br><br>Hope this helps<br>-pete
 
Hi,<br>Thanks. Its intelligent piece of code, however I am getting a compilation error at the following line:<br><br>CTextPage&nbsp;&nbsp;dlgText(_T(&quot;Tabbed Options&quot;), this);<br><br>The&nbsp;&nbsp;error is as follows:<br>error C2664: '__thiscall CTextPage::CTextPage(unsigned int,class CWnd *,unsigned int)' : cannot convert parameter 1 from 'char [15]' to 'unsigned int'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This conversion requires a reinterpret_cast, a C-style cast or function-style cast<br>Error executing cl.exe.<br><br>As you know, if I put it in view.<br>Zulfi.
 
Dear zulfi1234,<br><br>Do you have another contstructor for the dialog class other than the one the error reports: CTextPage::CTextPage(unsigned int,class CWnd *,unsigned int)' ? <br><br>If so, post it/them here.<br><br><br>-pete
 
These are the constructors:<br><br>CTextPage::CTextPage(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)<br> :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)<br>{<br>}<br><br>CTextPage::CTextPage(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)<br> :CPropertySheet(pszCaption, pParentWnd, iSelectPage)<br>{<br>}<br><br>Zulfi.
 
Dear zulfi1234,<br><br>I have been unable to reproduce the problem. I even tried a UNICODE build.<br><br>But try this it may work:<br><br>LPCTSTR caption = _T(&quot;Tabbed Options&quot;);<br>CTextPage&nbsp;&nbsp;dlgText( caption, this);<br><br>Good luck<br>-pete<br>
 
No sir, I am getting the same sort of errors. Can it be implemented in view?<br>Zulfi
 
Dear Zulfi,<br><br>Always post the error.<br><br>If CPSFontDoc is a CDocument derivation the technique I am showing you must work. If it's not working something is incorrect.<br><br>You did #include the CTextPage header file in the CPSFontDoc.cpp file, yes?<br><br>&gt; Can it be implemented in view?<br><br>Yes it can be done from the view. If your having trouble getting this to work it usually means something is wrong to begin with though. To implement in the view this would be the steps.<br><br>Create a public function of the document class that takes three LPCTSTR parameters for the three strings. The implementation of the function would save the three strings into it's own m_strX members accordingly. Then call UpdateAllViews();<br><br>In the View handler after the property dialog returns from the DoModal() call you would call:<br><br>GetDocument()-&gt;myfunc(....string parameters go here);<br><br>where &lt;myfunc&gt; is the name you give to the CPSFontDoc class member function.<br><br>Good luck<br>-pete<br>
 
Thanks it worked in&nbsp;&nbsp;view. The handler code is below:<br><br>void CPSFontView::OnViewTextsetting() <br>{<br> // TODO: Add your command handler code here<br> CLine1&nbsp;&nbsp;line1;<br> CLine2&nbsp;&nbsp;line2;<br> CLine3&nbsp;&nbsp;line3;<br><br> //LPCTSTR caption = _T(&quot;Tabbed Options&quot;);<br><br> CTextPage&nbsp;&nbsp;dlgText(&quot;Tabbed Options&quot;, this, 0);<br> dlgText.AddPage(&line1);<br> dlgText.AddPage(&line2);<br> dlgText.AddPage(&line3);<br><br> CPSFontDoc* pDoc = GetDocument();<br> line1.m_String1 = pDoc-&gt;m_str1;<br> line2.m_String2 = pDoc-&gt;m_str2;<br> line3.m_String1 = pDoc-&gt;m_str3;<br> if (dlgText.DoModal() == IDOK) {<br> <br> GetDocument()-&gt;GetString(line1.m_String1, line2.m_String2, line3.m_String1);<br> GetDocument()-&gt;UpdateAllViews(NULL);<br> }<br><br>}<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top