Solved

Giving dynamic text to a dialog/edit box

Posted on 2004-09-14
8
308 Views
Last Modified: 2010-04-24
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
Comment
Question by:yqureshi
  • 4
  • 3
8 Comments
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
Comment Utility
You can get the old text with GetDlgItemText(), append your new char and then set it again with SetDlgItemText().
0
 

Author Comment

by:yqureshi
Comment Utility
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
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
Comment Utility
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
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:yqureshi
Comment Utility
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
 
LVL 6

Accepted Solution

by:
Svetlin_Panayotov earned 50 total points
Comment Utility
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
 

Author Comment

by:yqureshi
Comment Utility
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
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now