Solved

How to loop through IDC_CONTROLS?

Posted on 2013-06-21
2
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

635 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