Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to C++, can't get GETWINDOWTEXT to work at all!!

Status
Not open for further replies.

amandak

Programmer
Aug 6, 2001
5
GB
I am very new to Visual C++ and I can't get this to work. Can someone describe how this works, I am just trying to retreive text from a textbox. Also, when I try to debug the application by adding breakpoints, Visual C++ does not break, but skips over the break point and executes the code???

Thanks for any help
AmandaK
 
Show the problematic code, I can try to help.

Additionally:
Are you using MFC or pure API call?
If you have problem to debug the application in some point
you can put _ASSERT(FALSE) so you will be able to jump to the place with debugger

Issahar
Issahar Gourfinkel
senior software engineer
Softwatch LTD
Israel
 
Thanks for your reply, Issahar, but I don't really know what API is. I know that MFC is Microsoft Foundation Classes, but don't know if I am using these? Sorry for not knowing.

Don't have access to the code at the moment - could you possibly tell me the set-up of this function, in simple terms.

Thanks very much for your reply.
 
Lets begin from the next question:
You say the you use GETWINDOWTEXT function
Which one are you using (is it CWnd::GetWindowText or Simple GetWindowText)? Issahar Gourfinkel
senior software engineer
Softwatch LTD
Israel
 
It's easier to use GetDlgItemText

// At the top of your prog define this
#define MAX_CHAR 32

// In your function make a sting variable for storage
char szTempString[MAX_CHAR];
// Read the text from the control
GetDlgItemText(hDlg,ID_CONTROL, szTempString, (MAX_CHAR-1));

The first member is your dialog box handle. The easiest way to get this is as the first line in your dialog box callback function use this
HWND hDlg = hWnd; // Stores the dialog window handle in hDlg

The second parameter is the ID of the control you want to read text from. The ID's are listed in the file called resource.h created when you create a dialog box in the editor.

The third member is somewhere to store the string and the fourth member is the amount of chars to read (1 less the storage size is safest).

Hope that helps.
 
1. First thing that you can do - right after calling GetDlgItemText - call GetLastError to get extended error information

2. As I understood, you don't succeed to stop debugger exactly in the line where you are calling GetDlgItemText, don't you? I seems strange, try to put break points in the calling functions. Do you succeed to put break points on previous statements? Is this a callback functions? If yes, may this functions is not called at all?

3. Check the exact number , that is defined by ID_CONTROL - may be in your dialog there is another control with the same number


4. How do you get handler on the dialog???What is hWnd, and where do you get it???


5. Try to check your code via GetDlgItem - see if the returned handler is valid...


6. I prefere to see the order of functions calls of your code, so I will be able to help more


My best regards Issahar Gourfinkel
senior software engineer
Softwatch LTD
Israel
 
Hi issahar,

I think your getting confused. Amandak wrote the original message saying GetWindowText didn't work. He mentioned he wanted to extract data from a text box.
I thought I'd help out and advise that he uses GetDlgItemText as it's better for extracting from controls as you can use control ID's instead of having to obtain control window handles before trying to use GetWindowText

Regarding your question about hWnd.
First hWnd is of the Type HWND (Short for window handle)
A dialog box handle is also a window handle.
so:-
HWND hDlg; // Window handle storage for dialog box handle

All dialog boxes or windows have a call back function.
An example prototype of a callback function for a dialog box is as follows.

int WINAPI DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

You can see that hWnd is passed to the callback function as the first parameter so within the callback funtion you can write:

hDlg = hWnd; // Stores the dialog box handle

or if you did not declare hDlg previously you can write
HWND hDlg = hWnd; // Does the same thing.

Hope that explains what I was trying to say.

I Myself have no problems reading and writing text to text boxes.

See Ya
Ultimatemind
 
Thank you all for your replies - they have been most helpful and I think it is finally working!

I appreciate the people on this forum who help daft people like me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top