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

MFC GetWindowText in Dialog w/ CString

404 views
Skip to first unread message

Roger McCarty

unread,
Jun 28, 1995, 3:00:00 AM6/28/95
to

Is the following legal in MFC?

CString strType;
GetDlgItem(IDC_CONTROL_TYPES)->GetWindowText(strType);

I am receiving an assertion for the CString on the second line
and can't seem to determine the cause.

Thanks!
Roger

Niels Ull Jacobsen

unread,
Jun 29, 1995, 3:00:00 AM6/29/95
to
mcca...@crl.com (Roger McCarty) writes:


>Is the following legal in MFC?

>CString strType;
>GetDlgItem(IDC_CONTROL_TYPES)->GetWindowText(strType);

Yes it is. Could you be more specific as to which ASSERT you get? It
wouldn't happen to be GetDlgItem() which returns NULL due to a wrong
ID?



>I am receiving an assertion for the CString on the second line
>and can't seem to determine the cause.

>Thanks!
>Roger
--
Niels Ull Jacobsen, Dep. of CS, U of Copenhagen (nu...@diku.dk)
Roenne Alle 3 st.th, 2860 Soeborg, Denmark, tel. +45 39 66 39 86


Kevin Hintergardt

unread,
Jun 29, 1995, 3:00:00 AM6/29/95
to
In article <3ssgbr$o...@crl4.crl.com> mcca...@crl.com (Roger McCarty) writes:
>Path: news.halcyon.com!nwfocus1.wa.com!news.sprintlink.net!howland.reston.ans.net!nntp.crl.com!crl4.crl.com!not-for-mail
>From: mcca...@crl.com (Roger McCarty)
>Newsgroups: comp.os.ms-windows.programmer.tools
>Subject: MFC GetWindowText in Dialog w/ CString
>Date: 28 Jun 1995 14:08:11 -0700
>Organization: CRL Dialup Internet Access (415) 705-6060 [Login: guest]
>Lines: 11
>Message-ID: <3ssgbr$o...@crl4.crl.com>
>NNTP-Posting-Host: crl4.crl.com

>Is the following legal in MFC?

>CString strType;
>GetDlgItem(IDC_CONTROL_TYPES)->GetWindowText(strType);

>I am receiving an assertion for the CString on the second line

>and can't seem to determine the cause.

>Thanks!
>Roger

Have GetDlgItem assign to a variable, check the variable for NULL, THEN go for
the GetWindowText. Depending on where you're calling from, IDC_CONTROL_TYPES
may no exist yet. You can also do the same thing with GetDlgItemText().

-------------------
Kevin Hintergardt
ch...@halcyon.com
Welcome to the Information Goat Path

Dave Sabbagh

unread,
Jun 30, 1995, 3:00:00 AM6/30/95
to

>>Is the following legal in MFC?

>>CString strType;
>>GetDlgItem(IDC_CONTROL_TYPES)->GetWindowText(strType);
>>I am receiving an assertion for the CString on the second line
>>and can't seem to determine the cause.

>Yes it is. Could you be more specific as to which ASSERT you get? It


>wouldn't happen to be GetDlgItem() which returns NULL due to a wrong
>ID?

That should give a gpf in debug mode.

Another Possibility:

IDC_CONTROL_TYPES is a combobox.You will get an assertion failed in
strcore1.cpp.If that is the case then use GetCurSel and GetLBText
to get the combo text(if that is what you want);
>

Sud


Clifford Stabbert

unread,
Jun 30, 1995, 3:00:00 AM6/30/95
to
mcca...@crl.com (Roger McCarty) wrote:
>
>Is the following legal in MFC?
>
>CString strType;
>GetDlgItem(IDC_CONTROL_TYPES)->GetWindowText(strType);
>
>I am receiving an assertion for the CString on the second line
>and can't seem to determine the cause.
>
>Thanks!
>Roger

On the main CString help page in MFC help, there's a link
to CString Argument Passing. You *should* have been able
to find this:

"If a string is an input to a function, in most cases it
is best to declare the string function parameter as const char*.
Convert to a CString object as necessary within the function
using constructors and assignment operators. If the string contents
are to be changed by a function, declare the parameter as a
nonconstant CString reference (CString&)."

Also, see the GetBuffer/ReleaseBuffer members of CString.


Roger McCarty

unread,
Jun 30, 1995, 3:00:00 AM6/30/95
to
Yup, that's the answer.
I was trying to get the text from a dropdown combobox.
Thanks for the heklp!


0 new messages