Skip to main content
gamedev.net
🔒 Locked

Problem with EDITTEXT control

Started by BigSadBear Sep 13, 2005 at 5:52 AM 1 replies 850+ views
Original Post
BigSadBear
BigSadBear
Hi. Im 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 dont 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???
MrEvil
MrEvil
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}
BigSadBear
BigSadBear
Thanks a lot MrEvil. I hope this will work.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.