Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Giving dynamic text to a dialog/edit box

Posted on 2004-09-14
8
Medium Priority
?
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 6

Expert Comment

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

Author Comment

by:yqureshi
ID: 12057412
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
ID: 12057987
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
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12061561
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
 

Author Comment

by:yqureshi
ID: 12061876
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 200 total points
ID: 12061944
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
ID: 12065677
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
ID: 12071586
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 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