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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Tex from Edit box 1

Status
Not open for further replies.

aaadetos

Programmer
Nov 21, 2004
54
US
Hi,
I'm using the following code to try to get a double variable from an edit box, but I keep getting an error: c2660
Code:
	double x=0;
	CString strx;
        ......

        for(int i=0;i<K,i++)
{
::GetDlgItem(IDC_WELLRAD,strA);//Error c2660
x=atof((LPCTSTR)strx);
...
}
How can I fix this error, please? what is HWND hdlg??
 
hdlg is the handle of the dialog which is supposed to have that item. If this code is in the dialog, you should be calling the object's GetDlgItem to eliminate this parameter instead of the global win32 API. If it is outside of the dialog and the dialog is modeless, you need to get the HWND of the dialog (use GetSafeHwnd()).
 
Thank you.
What do you mean by the "handle" of the dialog? IDC_WELLRAD is the ID of the edit box. Is the "handle" the name of the entire dialog box:IDD_KUCHUK_DIALOG? I typed erroneous code in my previous post. The code is:
Code:
double x=0;
    CString strx;
        ......

        for(int i=0;i<K,i++)
{
::GetDlgItemText(IDC_WELLRAD,strx);//Error c2660
x=atof((LPCTSTR)strx);
...
}

The code is not in my dialog box class, CDialog, otherwise, I'd have used
Code:
GetDlgItemText(IDC_WELLRAD,strx);
I thought using '::' will be okay.


 
It might be easier to do it like this:

double x=0;
CString strx;

GetDlgItemText(this, IDC_WELLRAD, strx, 20);
x = strtod(strx, NULL);

 
Thank you;
the use of 'this' however, created an error C2673: global functions do not have 'this' pointers.....what does strtod() do?
 
Thanks. I used a pointer to CDialog, instead of 'this'; the following works:
Code:
        double x=0;
	CString strx;
	
        CDialog *pDialog;
	pDialog = new CDialog;

	pDialog -> GetDlgItemText(IDC_WELLRAD,strx);	
	x = atof((LPCTSTR)strx);
 
A handle is what Windows uses internally to tell different windows apart. Every window (pretty much everything that descends from CWnd) has a HWND type for its handle, which is what Win32 actually uses. You never manipulate this directly, you just pass it off to various APIs so it knows how to apply things. Using the pointer to the dialog like you did is probably the best way of doing it in this example, but I would strongly recommend taking a look at the underlying Win32 API - that is, write a few simple Windows apps without using MFC, ATL, .NET framework, or anything else like that. You'll learn a lot and you will certainly find it useful in the future when using MFC. IMO, you can't really say you understand how to write Windows apps if you don't understand basic Win32.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top