Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. visual c++ code to read number of characters in the string entered in a text box

visual c++ code to read number of characters in the string entered in a text box

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studiohelpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 10715106
    wrote on last edited by
    #1

    im using visual studio 2010.im new to this.i have a button and a text box. i want to enter a string in the text box.eg:"hello". and if i click the button it should count the number of characters in the string and return the value..eg: in this case "hello" ,when i click the button it should count each letter and display the value "5"(string "hello" contains 5 characters).can any1 help me by sending the exact code?

    D L 2 Replies Last reply
    0
    • M Member 10715106

      im using visual studio 2010.im new to this.i have a button and a text box. i want to enter a string in the text box.eg:"hello". and if i click the button it should count the number of characters in the string and return the value..eg: in this case "hello" ,when i click the button it should count each letter and display the value "5"(string "hello" contains 5 characters).can any1 help me by sending the exact code?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Have you looked at the WM_GETTEXTLENGTH message? If you are using MFC, check out GetWindowTextLength().

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      M 1 Reply Last reply
      0
      • D David Crow

        Have you looked at the WM_GETTEXTLENGTH message? If you are using MFC, check out GetWindowTextLength().

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        M Offline
        M Offline
        Munchies_Matt
        wrote on last edited by
        #3

        He has to handle WM_COMMAND first.... then the button ID..... then get the window handle to the edit control.... This guy needs to go back and start form scratch and read some books/do some tutorials on Win32/MFC.

        "The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold

        1 Reply Last reply
        0
        • M Member 10715106

          im using visual studio 2010.im new to this.i have a button and a text box. i want to enter a string in the text box.eg:"hello". and if i click the button it should count the number of characters in the string and return the value..eg: in this case "hello" ,when i click the button it should count each letter and display the value "5"(string "hello" contains 5 characters).can any1 help me by sending the exact code?

          L Offline
          L Offline
          leon de boer
          wrote on last edited by
          #4

          Ok here is a skeleton program it does a bit more than you asked it deals with resizing the window, closing etc and is really complete enough for you to build on and get the idea.

          #include
          #include

          // These are ID's to call the controls by as you add new controls you add new entries
          #define IDC_TEXT 100 // Edit box ID
          #define IDC_BUTTON 101 // Button ID
          #define IDC_ANSWER 102 // Static text box to show answer

          // THIS IS THE MAIN WINDOW HANDLER WHERE ALL THE ACTION OCCURS
          LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
          {
          switch(uMsg)
          {
          // Initialize our window and create our child controls.
          case WM_CREATE:
          {
          // Create your edit window ... we wont bother with position we will fix later
          CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, TEXT("SOME TEXT HERE"),
          ES_LEFT | WS_CHILD | WS_VISIBLE,
          0, 0, 0, 0, hWnd, (HMENU)IDC_TEXT, 0, NULL);
          // Create your button window.
          CreateWindowEx(0, WC_BUTTON, TEXT("&Count text"),
          BS_PUSHBUTTON |
          WS_CHILD | WS_VISIBLE,
          0, 0, 0, 0, hWnd, (HMENU)IDC_BUTTON, 0, NULL);
          // Create your answer text box.
          CreateWindowEx(0, WC_STATIC, TEXT("0"),
          SS_LEFT |
          WS_CHILD | WS_VISIBLE,
          0, 0, 0, 0, hWnd, (HMENU)IDC_ANSWER, 0, NULL);
          }
          return 0;

          	// We accept this message so we can set a minimum window size. This only sets the users
          	// tracking size. The window itself can always be resized smaller programmatically unless
          	// you restrict it in WM\_WINDOWPOSCHANGING/WM\_WINDOWPOSCHANGED. 
          	case WM\_GETMINMAXINFO:
          		{
          			LPMINMAXINFO lpInfo = (LPMINMAXINFO)lParam;
          			if(lpInfo) {
          				lpInfo->ptMinTrackSize.x = 300;
          				lpInfo->ptMinTrackSize.y = 300;
          			};
          		}
          		return 0;
          	// These next two messages are better to use rather than WM\_MOVE/WM\_SIZE.
          	// Remember WM\_MOVE/WM\_SIZE are from 16bit windows. In 32bit windows the window
          	// manager only sends these two messages and the DefWindowProc() handler actually
          	// accepts them and converts them to WM\_MOVE/WM\_SIZE.
          	// 
          	// We accept this so we can scale our controls to the client size.
          	case WM\_WINDOWPOSCHANGING:
          	case WM\_WINDOWPOSCHANGED:
          		{
          			HDWP hDWP;
          		
          			// Create a deferred window handle.
          			if(hDWP = BeginDeferWindowPos(3)){ // Defer 3 controls to stop flashing
          				
                                              // Position edit box
          				hDWP = DeferWindowPos(hDWP, GetDlgItem(hWnd, ID
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups