Solved

Giving dynamic text to a dialog/edit box

Posted on 2004-09-14
8
335 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
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c++ class logger 6 105
Cchar * Concating 7 93
Random number generation (what's missing?) 7 85
bullzip printer only saves PDF in black and white. 5 90
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 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