-
April 9th, 2009, 08:07 AM
#1
Gettext ?
Hello and first sorry for my very bad english.
i have little knowledge about c and c++ but im trying to learn win32 programming with c++. its little hard and im very new at that. im trying to do very very simple thing: i have an main window, 1 button, 1 edit control. when user clicks button, i wanna show edit controls text with messagebox. there is a problem, i guess i should get text from editcontrol with gettext api, but i have to pass hwnd for that. actually im already have hwnd when i calling createwindowex function, but its not public. so in message switch block i dont have hwnd for edit control. what should i do? findwindow? or maybe public variable? Thanks.
-
April 9th, 2009, 09:23 AM
#2
Re: Gettext ?
Perhaps, you know the control ID of this editr control?
Then you could use GetDlgItemText API.
Victor Nijegorodov
-
April 24th, 2009, 01:54 AM
#3
Re: Gettext ?
Originally Posted by kcomeby
Hello and first sorry for my very bad english.
i have little knowledge about c and c++ but im trying to learn win32 programming with c++. its little hard and im very new at that. im trying to do very very simple thing: i have an main window, 1 button, 1 edit control. when user clicks button, i wanna show edit controls text with messagebox. there is a problem, i guess i should get text from editcontrol with gettext api, but i have to pass hwnd for that. actually im already have hwnd when i calling createwindowex function, but its not public. so in message switch block i dont have hwnd for edit control. what should i do? findwindow? or maybe public variable? Thanks.
Hi. you should have to draw the controls (Edit, Button etc..) in the WM_CREATE message handling section of main Parent Window. So, the controls will be drawn right after when the main window is drawn.
So, you will get the hWnd handle of all controls from inside the Message Callback thread.
Anotherway is, decalring the hWnd variables of controls as Global variables.. but its a bad idea.
You not need to declare every controls handle in the window as global. So, i think the first one will be better for you.
-
April 24th, 2009, 09:38 AM
#4
Re: Gettext ?
As Victor already suggested, if you know the parent handle (you know it in the parent window procedure) and the identifier of the control (you know it as the value passed in hMenu parameter of CreateWindow(Ex) function or as a resource ID), then
- you can call GetDlgItemText to directly get its text;
- you can call GetDlgItem to get its handle to be used in other function calls.
So, you don't need to keep the control handles as global variables, as class members, or in any other place.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|