?
Solved

getting caption on a button

Posted on 2002-07-28
3
Medium Priority
?
236 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 400 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

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.…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

649 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