Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

Giving dynamic text to a dialog/edit box

Hi,
I am currently working on a fax machine module. The qustion I have is , I have couple of telephone keys (numbers pad) and every bitmap when clicked (Selected) gives a specific number in the edit box. I am using SetDlgItemText( )function. I know this will give only one input for every touch(push). All I want is to show the complete set of numbers in the editbox as the user pushes a button/key.
Please give me the appropriate function or a hint I should call instead of SetDlgItemText( ) function.

 
0
yqureshi
Asked:
yqureshi
  • 4
  • 3
1 Solution
 
Svetlin_PanayotovCommented:
You can get the old text with GetDlgItemText(), append your new char and then set it again with SetDlgItemText().
0
 
yqureshiAuthor Commented:
Thats the key how am I going to append a new character in the edit box using the push buttons. I think SetDlgItemText () will set the edit box and remove the previous entries
0
 
Svetlin_PanayotovCommented:
You can have something like this in your message handler (when some of the buttons is pressed):

LPCTSTR newText; //the text from the button - you should have it already
LPCTSTR szText = new char[40]; //40 should be enough
ZeroMemory(szText, sizeof(szOldText));
GetDlgItemText(hDlg, ID_BTN, szText, 39);
strcat(szText,newText);
SetDlgItemText(hDlg, ID_EDIT, szText);
delete[] szText;
delete[] newText;

I don't have a compiler here to check it - but it should be working fine.

Svetlin
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Svetlin_PanayotovCommented:
Well - some fixes - I finally got near machine with VC :)
      LPTSTR newText; //the text from the button - you should have it already
      LPTSTR szText = new char[40]; //40 should be enough
      ZeroMemory(szText, sizeof(szText));
      GetDlgItemText(IDC_EDIT, szText, 39);
      strcat(szText,newText);
      SetDlgItemText(IDC_EDIT, szText);
      delete[] szText;
      delete[] newText;

Svetlin
0
 
yqureshiAuthor Commented:
Hi,
Thank you very much Svetlin_Panayotovfor your advice and code. The code really worked a minor changes and whola its working properly. Only problem left now is to erase the last entry I hope I will try that one out.

Anyway Thanks Again for the helping hand
yqureshi
0
 
Svetlin_PanayotovCommented:
If I got it right - erasing the last digit will look like this:

      LPTSTR szText = new char[40]; //40 should be enough
      ZeroMemory(szText, sizeof(szText));
      GetDlgItemText(IDC_TEXT, szText, 39);
      if (strlen(szText) > 0)
      {
            szText[strlen(szText)-1] = '\0';      //Terminate the string before the last char
      }
      
      SetDlgItemText(IDC_TEXT, szText);
      delete[] szText;
0
 
yqureshiAuthor Commented:
Yes it is a absolutly correct, Only SetItem and GetItem takes 4 and 3 identifiers respectivly, only handle to the dialog is missing the remaining works absolutly fine

Thanks once again for reconfirmation
With best Regards
yqureshi
0
 
Jaime OlivaresCommented:
Don't use SetDlgItemText. You must use the EM_REPLACESEL message.
Select an empty portion at the end of your text control and replace it with a text.

Here is an example in a previous question:
http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20606978.html
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now