在VC++中创建控件数组的方法有以下几种:
#include <Windows.h>
#include <vector>
HWND hButtons[5]; // 控件指针数组
for (int i = 0; i < 5; i++) {
hButtons[i] = CreateWindowEx(0, L"BUTTON", L"Button", WS_VISIBLE | WS_CHILD,
10 + i * 100, 10, 80, 30, hWnd, NULL, hInstance, NULL);
}
#include <Windows.h>
#include <vector>
std::vector<HWND> hButtons; // 控件指针向量
for (int i = 0; i < 5; i++) {
HWND hButton = CreateWindowEx(0, L"BUTTON", L"Button", WS_VISIBLE | WS_CHILD,
10 + i * 100, 10, 80, 30, hWnd, NULL, hInstance, NULL);
hButtons.push_back(hButton); // 添加控件指针到向量
}
#include <Windows.h>
HWND* hButtons = new HWND[5]; // 动态数组
for (int i = 0; i < 5; i++) {
hButtons[i] = CreateWindowEx(0, L"BUTTON", L"Button", WS_VISIBLE | WS_CHILD,
10 + i * 100, 10, 80, 30, hWnd, NULL, hInstance, NULL);
}
// 使用完后记得释放内存
delete[] hButtons;
以上是几种常见的方法,具体选择哪种方法取决于具体的需求和场景。