我刚刚开始学习编程,我只是成功制作窗口。 我试图创建一个STATIC文本区域,所以我确实喜欢这个。
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
textfield = case WM_CREATE:
CreateWindow("STATIC", "Hggggg", WS_VISIBLE | WS_CHILD | WS_BORDER,
1, 1, 100, 20, hwnd, 0, 0, 0);
break;
我正在为初学者观看YouTube视频,然后我关注了视频。但不知何故,VisualStudio在" CreateWindow"下制作了redcurvy-underline。我真的不知道为什么。 编译失败,并显示错误编号" C2065"," C2664"。
这是我的全部代码
#include <Windows.h>
HWND windowHandle;
HWND textfield;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIconSm = 0;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpszClassName = L"rerere";
wc.lpszMenuName = 0;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
//
RegisterClassEx(&wc);
windowHandle = CreateWindowEx(WS_EX_ACCEPTFILES, L"rerere", L"rerere",
(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX ) | WS_VISIBLE, (GetSystemMetrics(SM_CXSCREEN)-300)/2, (GetSystemMetrics(SM_CYSCREEN)-300)/2, 300, 300, 0, 0, hInstance, 0);
//
if (windowHandle == 0)
MessageBoxA(0, "creafjeiwa", "ERROR", 0);
//
ShowWindow(windowHandle, showCmd);
//
UpdateWindow(windowHandle);
//
MSG msg;
SecureZeroMemory(&msg, sizeof(MSG));
int returnValue = 0;
while ((returnValue = GetMessage(&msg, 0, 0, 0)) != 0)
{
if (returnValue == -1)
{
MessageBoxA(windowHandle, "getmessage fa", "ssss", 0);
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
textfield = CreateWindow("STATIC", "Hggggg", WS_VISIBLE | WS_CHILD | WS_BORDER, 1, 1, 100, 20, hwnd, 0, 0, 0);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
如何创建静态文本区域?
答案 0 :(得分:1)
您的项目是Unicode,您必须使用Unicode文本字段而不是ANSI
CreateWindow(L"STATIC", L"Hggggg", ...
所有文本字段都需要L
前缀。如果使用ANSI,则使用ANSI版本的API代码。您已使用MessageBoxA
完成此操作。但是,在文本的L
前缀中使用Unicode函数效率更高。