Solved

getting caption on a button

Posted on 2002-07-28
3
219 Views
Last Modified: 2013-12-03
Ok, I'm doing a simple test program to learn about buttons using win32 api calls, no mfc, the problem is, I can't get the caption on a button. I have a function that sets the text but when I try to retrieve the new text it seems like I end up with an empty variable. BTW, I'm using C++(the area said Windows Programming, not C++ Windows Programming:)).
This is what I use to get the text:
LPTSTR mystr;
int count;
Button_GetText(button[2],mystr,count);

button[2] is a handle to my third button in an array of nine buttons...
Then when I try to view the text retrieved with a MessageBox it's just an empty messagebox...

I appreciate any thoughts on this...
0
Comment
Question by:DeproG
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
RolandAZ earned 100 total points
ID: 7183656

hi, DeproG

Make sure you allocate the necessary number of bytes for
the string, and your count bytes is correct.

I presume you are passing the correct HWND of your button.

Example:

TCHAR mystr[50];
int count = 10;

//... get hWnd to button
// yourDlgHWnd = hWnd of your dialog
// IDB_OFYOURBUTTON = resource id of button
// button[2] = GetDlgItem(yourDlgHWnd,IDB_OFYOURBUTTON);

//call your routine
Button_GetText(button[2],mystr,count);


In your Button_GetText routine you use:
 if(GetWindowText(hWnd,strX,count))
    {
    MessageBox(NULL,strX,"My App", MB_OKCANCEL);
    }

//passed parameters
 //strX = mystr
  //count = count
 // hWnd = button[2]

//=====================

 
I hope that solves your problem!

Have fun!
Roland

     
0
 

Author Comment

by:DeproG
ID: 7183717
It worked fine by declaring mystr as TCHAR while also specifying the size. Should've thought of that myself hehe, anyway, thanks for your help :)
0
 
LVL 1

Expert Comment

by:RolandAZ
ID: 7183748
Great to hear it is working fine now, DeproG!

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

785 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