Jump to content
  • Advertisement
Sign in to follow this  
BigSadBear

Problem with EDITTEXT control

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I`m developing little program in VC++ using win32 API and I have the following problem: In a dialog box the user have been asked to enter the password in text box(EDITTEXT). The problem is that I don`t know how to get the value of the text box after the user have pressed OK button. Is there a predefined function that I can use. Can somebody help somehow???

Share this post


Link to post
Share on other sites
Advertisement
Try looking at GetWindowText and GetWindowTextLength or GetDlgItemText.

Each have their uses. GetDlgItemText is used when you are using dialog templates, which looks like what you are using - however, there is no corresponding GetDlgItemTextLength. You can also use GetDlgItem to get a window handle to the editbox. You can then use the returned handle to get the length of the text.

Try this:

INT_PTR CALLBACK MyDialogProc(HWND hWndOfDialog, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch(uMsg){
case WM_COMMAND:
if(HIWORD(wParam) == 0) /*codeNotiify*/ && LOWORD(wParam) == IDC_OK_BUTTON){
HWND hWndEdit = GetDlgItem(hWndOfDialog, IDC_MY_TEXTBOX);
UINT textLength = GetWindowTextLength(hWndEdit);
LPTSTR text = new TCHAR[textLength + 1];
DWORD actualLength = GetWindowText(hWndEdit, text , textLength + 1);
//A possible effect is that actualLength != textLength when the text is altered inbetween the calls.
EndDialog(hWndOfDialog, TRUE);
return TRUE;
}
}
return FALSE; //Let the system handle the message for you
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!