我想在for()循环中创建31个复选框。我的代码:
for (int i = 1; i<32; i++)
{
wchar_t buffer[256];
std::swprintf(buffer, sizeof(buffer) / sizeof(*buffer), L"1", i);
g_hPrzycisk = CreateWindowEx(0, "BUTTON", buffer, WS_CHILD | WS_VISIBLE | BS_CHECKBOX,
polozenie, 100, 30, 30, hwnd, NULL, hInstance, NULL);
polozenie = polozenie + 30;
}
错误
C:\Users\Komputer\Desktop\grafik\GrafikOnClick\main.cpp In function 'int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)':
66 120 C:\Users\Komputer\Desktop\grafik\GrafikOnClick\main.cpp [Error] invalid conversion from 'int' to 'LPCSTR {aka const char*}' [-fpermissive]
72 0 C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\windows.h In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include/windows.h
1 C:\Users\Komputer\Desktop\grafik\GrafikOnClick\main.cpp from main.cpp
1935 26 C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\winuser.h [Note] initializing argument 3 of 'HWND__* CreateWindowExA(DWORD, LPCSTR, LPCSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)'
28 C:\Users\Komputer\Desktop\grafik\GrafikOnClick\Makefile.win recipe for target 'main.o' failed
我做错了什么?
答案 0 :(得分:-1)
我无法看到错误,但这些是其他错误已更正
for (int i = 1; i<32; i++)
{
wchar_t buffer[256];
std::swprintf(buffer, sizeof(buffer) / sizeof(*buffer), L"%d", i);
// ^___ corect this
CreateWindowEx(0, TEXT("BUTTON"), buffer, WS_CHILD | WS_VISIBLE | BS_CHECKBOX,
// ^^^___ and this (TEXT) macro
// ^___ you can also drop this 'g_hPrzycisk' (is not an error)
polozenie, 100, 30, 30, hwnd, NULL, hInstance, NULL);
polozenie = polozenie + 30;
}