Solved

getting caption on a button

Posted on 2002-07-28
3
214 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now