关于创建VC创建窗口的问题

今天看了孙鑫的视频教程,跟着做了一个一样的创建一个窗口的程序,可以编译运行,但是不能在产生的窗口上做任何操作,关也关不掉,是什么原因啊,帮帮我啊,程序如下:#includ... 今天看了孙鑫的视频教程,跟着做了一个一样的创建一个窗口的程序,可以编译运行,但是不能在产生的窗口上做任何操作,关也关不掉,是什么原因啊,帮帮我啊,程序如下:
#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK winsunproc(
HWND hwnd,
UINT uMsg,
WPARAM wparam,
LPARAM lparam
);

int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=winsunproc;
wndclass.lpszClassName="哈哈";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW ¦CS_VREDRAW;
RegisterClass(&wndclass);

HWND hwnd;
hwnd=CreateWindow("哈哈","hello word",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;
}

LRESULT CALLBACK winsunproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR:
char szchar[20];
sprintf(szchar,"char is %d",wParam);
MessageBox(hwnd,szchar,"哈哈",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click","哈哈",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"heihei",strlen("heihei"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"嘿嘿",strlen("嘿嘿"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否结束?","哈哈",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
展开
 我来答
fascinating_li
推荐于2016-06-06 · TA获得超过844个赞
知道小有建树答主
回答量:1944
采纳率:0%
帮助的人:1284万
展开全部
恩看了应该这样吧,到底你不对在哪自己看吧
还有sprintf在WINDOWS.H中有wsprintf来代替不需要在stdio.h了
改过代码这样吧
#include <windows.h>

LRESULT CALLBACK winsunproc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
TCHAR szApp[]=TEXT("playli");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style=CS_VREDRAW|CS_HREDRAW;
wndclass.lpfnWndProc=winsunproc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,MAKEINTRESOURCE(IDI_APPLICATION));
wndclass.hCursor=LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW));
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szApp;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,"Please run it in windows!!","Wrong!!",NULL);
return 1;
}
hwnd=CreateWindow(szApp,
TEXT("hello word"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,
NULL,
hInstance,NULL);
ShowWindow(hwnd,SW_NORMAL);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
return msg.wParam;
}

LRESULT CALLBACK winsunproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch(uMsg)
{
case WM_CHAR:
char szchar[20];
wsprintf(szchar,"char is %c",wParam);
MessageBox(hwnd,szchar,"哈哈",0);
return 0;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click","哈哈",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"heihei",strlen("heihei"));
ReleaseDC(hwnd,hdc);
return 0;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"嘿嘿",strlen("嘿嘿"));
EndPaint(hwnd,&ps);
return 0;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否结束?","哈哈",MB_YESNO))
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式