CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Gettext ?

  1. #1
    Join Date
    Apr 2009
    Posts
    2

    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.

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Gettext ?

    Perhaps, you know the control ID of this editr control?
    Then you could use GetDlgItemText API.
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Smile Re: Gettext ?

    Quote Originally Posted by kcomeby View Post
    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.

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured