텍스트 상자의 텍스트를 변경하려고하는데 코드가 작동하지 않는 것 같습니다. SetWindowText (hwnd, lpcstr)를 사용하고 있습니다; 그리고 문제가C++ SetWindowText가 작동하지 않습니다.
될 일을 전혀 생각이 난 내 모든 코드를 게시 한
#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;
}
내 마음에 온 모든 노력을하지 가지고, 당신은 직접 볼 수 있지만, 나는 어떤 문제를 찾을 수없는 그 안에
귀하의 질문에 분명한 것이 없습니다. 어떻게 선언하고 'edit_1'을 구합니까? –
죄송합니다,이 포럼은 전체 파일을 게시 나에게 몇 가지 문제를했다지만, 그러나 edit_1 = CreateWindow 함수 ("편집", "sdgf" \t \t \t \t \t \t WS_BORDER | WS_CHILD | WS_VISIBLE는 \t \t \t \t \t \t 5, 85, 250, 20, hWnd, (HMENU) ID_EDIT_1, NULL, NULL); – DomeWTF
1.'CreateWindow'가 성공 했습니까? 2.'SetWindowText'를 호출하는 경로를 사용하고 있습니까? 3. SetWindowText가 실패를 반환하는지 여부와 오류 코드를 설정하는지 여부를 확인 했습니까? – jamesdlin