PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

GetDlgItemText question

Hi

I am new to VisualC programming and I have a lot of questions :D
I already tried my luck with the evc supplied "Hello World" which worked just fine. Probably since I didnt have to code a single line.

Now I wanted to program a more generic version where I can supply my name in a textfield and by pressing a button it spits out something like "Hello Valentin".

I added this:
Code:

BEGIN_MESSAGE_MAP(CKeygenTemplateApp, CWinApp)
// {{AFX_MSG_MAP(CKeygenTemplateApp)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
// }}AFX_MSG_MAP
END_MESSAGE_MAP()


and this

Code:

void CKeygenTemplateApp::OnButton1()
{
char strName[128];
char* pName = strName;

GetDlgItemText(dlg, IDC_NAME, pName, 128);
}


My first error I´d love to solve is where I can find GetDlgItemText
The evc help tells me I have to include winuser.h which doesnt work for me. :(

Any good tutorials on that?

Greetings,
Valentin
Sm!rk · 21 Jan 2003, 21:56 UTC — GetDlgItemText question
Valentin wrote:

Code:

void CKeygenTemplateApp::OnButton1()
{
char strName[128];
char* pName = strName;

GetDlgItemText(dlg, IDC_NAME, pName, 128);
}


My first error I´d love to solve is where I can find GetDlgItemText


First you are using MFC, which isn't a problem its just a different way of doing it. The GetDlg... function is a pure API function which in your case may not be what you want since there are other "more C++ like" functions you can use with the MFC framework. For instance you have your handle "dlg" which could be in your class, but with MFC you don't need to build that framework.

Windows headers and functions are the major pain-in-the-ass, at least to me. Trying to find a particular function tends to be more difficult then the header. But what I do is just search the entire include directory for the function I am looking for. This works for normal Windows API programming, I don't do the MFC things so can't comment on that. So hopefully you have an editor that can search whole directories, most good editors can do it. The editor I use can if you want a suggestion (textpad.com).

Another thing is you can use Help to find the function name, and usually at the bottom it will say what library and headers are required. Sometimes the library or header are missing. Also there are some differences between PC and PPC. For the really lazy, you can try just including <Windows.h>, that tends to catch a lot of them (especially on PPC).
The GetDlgItemText API should be included with MFC builds. I just tested it and it worked fine for me without including anything but the usual stdafx.h.

There are two ways of getting the string of a dialog item that is more MFC-ish than using Win32 APIs.

1: Use ClassWizard to add a CString value to that edit control. When you want to read it just call UpdateData() and access that member variable.

2: Use ClassWizard to add a CEdit control class for the edit box you're interested in. When you want to access its text call its GetWindowText member.

Dan East