Solved

getting caption on a button

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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