Solved

Giving dynamic text to a dialog/edit box

Posted on 2004-09-14
8
365 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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 50 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
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…

617 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