我正在尝试更改文本框中的文本,但代码似乎不起作用。我正在使用 SetWindowText(hwnd, lpcstr); 并且不知道问题可能是什么
尝试了我想到的一切
#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
#include <tchar.h>
using namespace std;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
enum { ID_LABEL = 1,ID_LONG_TEXT,ID_EDIT,ID_EDIT_1,ID_BUTTON };
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Creo la finestra
static TCHAR szWindowClass[] = _T("Draw");
static TCHAR szTitle[] = _T("Draw");
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
if(!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Win32 Guided Tour"),
NULL);
return 1;
}
HWND hWnd = CreateWindow(
szWindowClass,
szTitle,
WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT,
450, 600,
NULL,
NULL,
hInstance,
NULL);
if(!hWnd)
{
MessageBox(NULL,
_T("Call to CreateWindow failed!"),
_T("Win32 Guided Tour"),
NULL);
return 1;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
TCHAR primo[] = _T("Inserisci la lunghezza della parola da indovinare:");
TCHAR secondo[] = _T("Inserisci le lettere (una dopo l'altra senza ne spazi ne invii):");
HDC hdc;
//HFONT hFont;
HWND button;
HWND edit;
HWND edit_1;
HWND long_edit;
HINSTANCE g_hInst;
switch(uMsg)
{
case WM_CREATE:
{
edit = CreateWindow("Edit", "1h2f3d4",
WS_BORDER |WS_CHILD | WS_VISIBLE,
5, 30, 23, 20, hWnd, (HMENU) ID_EDIT, NULL, NULL);
edit_1 = CreateWindow("Edit", "sdgf",
WS_BORDER | WS_CHILD | WS_VISIBLE,
5, 85, 250, 20, hWnd, (HMENU) ID_EDIT_1, NULL, NULL);
// Creo il pulsante
button = CreateWindow("Button","Calcola",
BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,
260, 85, 150, 20,hWnd,(HMENU) ID_BUTTON,NULL,NULL);
long_edit = CreateWindow("Edit", "kjvh",
WS_BORDER | WS_CHILD | WS_VISIBLE,
5, 125, 250, 300, hWnd, (HMENU) ID_LONG_TEXT, NULL, NULL);
}
case WM_PAINT:
{
PAINTSTRUCT ps;
hdc = BeginPaint(hWnd, &ps);
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc, RGB(255,255,255));
TextOut(hdc, 5, 5, primo, sizeof(primo));
TextOut(hdc, 5, 60, secondo, sizeof(secondo));
EndPaint(hWnd, &ps);
break;
}
case WM_COMMAND:
{
if(edit_1 == NULL)
{
MessageBox(hWnd, "Errore", "Errore", uMsg);
}
if(LOWORD(wParam) == ID_BUTTON)
{
MessageBox(hWnd, "sgf", "ghgfrore", uMsg);
SetWindowText(edit_1, "lool");
}
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
break;
}
return 0;
}
我已经发布了我所有的代码,您可以自己查看,但我没有发现任何问题