Solved

getting caption on a button

Posted on 2002-07-28
3
229 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
[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
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

737 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