Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DDX for CStatic

955 views
Skip to first unread message

jc

unread,
Jun 19, 2009, 4:11:01 PM6/19/09
to
Hello,

I defined a CStatic variable,
and I am trying to use the variable with
DoDataExchange. But, I always get a runtime
error ( I want to change the text of the static control).

CStatic m_strCtrl;

DDX_Control(pdx,IDC_STATIC1,m_stcCtrl);

...

m_strCtrl.SetWindowText("Test");

TIA,
-jc

Message has been deleted

Tom Serface

unread,
Jun 19, 2009, 4:20:28 PM6/19/09
to
Are you compiling as Unicode (of course then you should get a compile error,
but I figured it's worth asking).

Also, you need to do this call in OnInitDialog() after the call to
UpdateData() or the base constructor has been called.

Tom

"jc" <j...@discussions.microsoft.com> wrote in message
news:56A0CA14-FC40-4DE7...@microsoft.com...

jc

unread,
Jun 19, 2009, 5:16:02 PM6/19/09
to
Tom,

Thank you for taking the time to reply to my posting.

Yes, that worked!

-jc

Joseph M. Newcomer

unread,
Jun 20, 2009, 9:42:13 PM6/20/09
to
I have no idea what you are talking about. There IS NO SUCH THING as "a runtime error".
There is a SPECIFIC error with SPECIFIC text that occurs at a SPECIFIC line of code!
Unless you report EXACTLY WHAT ERROR YOU ARE GETTING AND WHERE YOU ARE GETTING IT, and
report the values of all the variables involved in the error, and show what the values
were at the call site, you are wasting your time and ours with a post.

At no point have you explained what you have done. You have not shown where the CStatic
is declared (is it in the class?), you have not shown the control ID associated with
IDC_STATIC1 (which is a LOUSY name for a control!), you have not shown any context where
the error occurs, you have not shown where the SetWindowText takes place, and overall this
is not a coherent question. You missed showing EVERYTHING that might actually help us
answer the question!
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer

unread,
Jun 20, 2009, 9:43:31 PM6/20/09
to
But why? If the goal is to set the window text, why use something as strange as DDX_Text
(which requires calling UpdateData) when a much simpler call to SetWindowText of a control
variable would work.

Providing, of course, that all necessary preconditions are met.
joe

On Fri, 19 Jun 2009 14:15:49 -0700, Henryk Birecki <soarin...@sbcglobal.net> wrote:

>You assigned a Control object not a string variable to resource. The
>latter would be
>
>CString m_s;
>
>DDX_Text((pdx,IDC_STATIC1,m_s);
>
>You can still use CStatic and set/get text using
> m_stcCtrl.SetWindowText(text);
> m_stcCtrl.GetWindowText(text);
>
>Henryk Birecki

0 new messages