Solved

How to loop through IDC_CONTROLS?

Posted on 2013-06-21
2
294 Views
Last Modified: 2013-06-23
I have nine text fields, named IDC_COMBO1 to IDC_COMBO9 ( values are consecutive ).

I want to obtain the values of each and make one string.

I tried this:

char szComboBuffer[];

  // Loop through all COMBO controls,
     // build final string.
    for (int i = IDC_COMBO1; i <= IDC_COMBO9; ++i)
    {
            GetDlgItemText(gl_hWnd, i, szComboBuffer, 2);
    }
   

Open in new window


I chose 2 as last parameter because they might enter 2 digits in the text field.

If it worked as intended, szComboBuffer would hold the final string.

I am fairly new to this. Can someone help me finish this up? Thanks.
0
Comment
Question by:edvinson
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39268177
The easiest way would be to use a std::string for that, e.g.

#include <tchar.h>
#include <string>
usineg namespace std;
typedef basic_string<TCHAR> tstring;

TCHAR szComboBuffer[256];
tstring sAllCombos;

  // Loop through all COMBO controls,
     // build final string.
    for (int i = IDC_COMBO1; i <= IDC_COMBO9; ++i)
    {
            GetDlgItemText(gl_hWnd, i, szComboBuffer, 256);

            sAllCombos += sComboBuffer;
    }
   
    MessageBox(NULL,sAllCombos.c_str(),_T("All Together"),MB_OK)';
                                  

Open in new window

0
 
LVL 1

Author Closing Comment

by:edvinson
ID: 39270356
perfect! I ended up taking the long way, but I am rewriting using this. It's much more efficient. Again, I always learn from your solutions.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Issue accessing member variable of atomic class 16 110
Which IDE to use to begin C++ training? 5 59
C++ question 3 62
Header Errors LNK2019, LNK1120 - Unresolved Externals 4 95
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now