C++ API SetWindowText 无效

代码如下,多的被我删除了,主要是SetWindowText无法向hwndEdit和ID_LAB1内容#include<windows.h>#include<stdio.h... 代码如下,多的被我删除了,主要是SetWindowText无法向hwndEdit和ID_LAB1内容#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndcls.hCursor=LoadCursor(NULL,IDC_ARROW); wndcls.hIcon=LoadIcon(NULL,IDI_INFORMATION); wndcls.hInstance=hInstance; wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="NewT";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("NewT",
"MulitThread4",
WS_OVERLAPPEDWINDOW,
0,0,600,400
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
int s=5;
char Tmp_c[20];
char *p1=Tmp_c;
int ClickNUM=0;
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{ HWND ID_START1,ID_LAB1,hwndEdit;
switch(uMsg)
{
case WM_CREATE:
ID_START1=CreateWindow("button","1开始",BS_BOTTOM|WS_CHILD| BS_PUSHBUTTON,2,2,50,25
,hwnd,(HMENU)1001,NULL,NULL); ID_LAB2=CreateWindowEx(WS_EX_CLIENTEDGE,"Edit","",
WS_VISIBLE|WS_CHILD|ES_LEFT|ES_MULTILINE|ES_WANTRETURN,
103,80,100,25,hwnd,(HMENU)1011,NULL,NULL);

ID_LAB1 = CreateWindow("edit",NULL,WS_CHILD | WS_VISIBLE | WS_BORDER,
2,80,100,25,hwnd,NULL, NULL, NULL);

hwndEdit = CreateWindow("edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
120, 170, 100, 25, hwnd, NULL, NULL, NULL);

ShowWindow(ID_LAB1,1);
ShowWindow(ID_START1,1);
break;
case WM_COMMAND:
switch(wParam)
{
case 1001: ClickNUM=1001;
break;
}
break;
case WM_LBUTTONDOWN:
switch(ClickNUM)
{
case 1001:
s++;
itoa(s,Tmp_c,10); SetWindowText(ID_LAB1,"Hello Edit");
SetWindowText(hwndEdit, "Hello Edit");
}
break;
case WM_PAINT:
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
展开
 我来答
源语梦Hg
2010-12-19 · TA获得超过521个赞
知道小有建树答主
回答量:670
采纳率:100%
帮助的人:274万
展开全部
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndcls.hCursor=LoadCursor(NULL,IDC_ARROW); wndcls.hIcon=LoadIcon(NULL,IDI_INFORMATION); wndcls.hInstance=hInstance; wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="NewT";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("NewT", "MulitThread4",WS_OVERLAPPEDWINDOW,0,0,600,400, NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
int s=5;
char Tmp_c[20];
char *p1=Tmp_c;
int ClickNUM=0;
HWND ID_START1,ID_LAB1,ID_LAB2,hwndEdit;//修改
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{

switch(uMsg)
{
case WM_CREATE:
ID_START1=CreateWindow("button","1开始",BS_BOTTOM|WS_CHILD| BS_PUSHBUTTON,2,2,50,25
,hwnd,(HMENU)1001,NULL,NULL);

ID_LAB2=CreateWindowEx(WS_EX_CLIENTEDGE,"Edit","",
WS_VISIBLE|WS_CHILD|ES_LEFT|ES_MULTILINE|ES_WANTRETURN,
103,80,100,25,hwnd,(HMENU)1002,NULL,NULL);

ID_LAB1 = CreateWindow("edit",NULL,WS_CHILD | WS_VISIBLE | WS_BORDER,
2,80,100,25,hwnd,(HMENU)1003, NULL, NULL);

hwndEdit = CreateWindow("edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
120, 170, 100, 25, hwnd,(HMENU)1004, NULL, NULL);

ShowWindow(ID_LAB1,1);
ShowWindow(ID_START1,1);
break;
case WM_COMMAND:
switch(wParam)
{
case 1001: ClickNUM=1001;
break;
}
break;
case WM_LBUTTONDOWN:
switch(ClickNUM)
{
case 1001:
//s++;
//itoa(s,Tmp_c,10);
SetWindowText(ID_LAB1,"Hello Edit");
SetWindowText(ID_LAB2, "Hello Edit");
UpdateWindow(hwnd);//修改
}
break;
case WM_PAINT:
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}

// 注:主要是因为你误用了局部变,把局部变量当作全局变量用了
//另:设置好了文字后得刷新窗口
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式