?
Solved

How to loop through IDC_CONTROLS?

Posted on 2013-06-21
2
Medium Priority
?
306 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

719 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