VC窗体显示问题

在VC6/WIN32Application平台下,写了个窗体API,显示时报错。代码如下,请高手指点一下!谢谢!#include<windows.h>#include<s... 在VC6/WIN32 Application平台下,写了个窗体API,显示时报错。代码如下,请高手指点一下!谢谢!
#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wndclas;
wndclas.style=CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW;
wndclas.lpfnWndProc=WindowProc;
wndclas.cbClsExtra=0;
wndclas.cbWndExtra=0;
wndclas.hInstance=hInstance;
wndclas.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclas.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclas.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wndclas.lpszMenuName=NULL;
wndclas.lpszClassName="abc";

RegisterClass(&wndclas);

HWND hwnd;
hwnd=CreateWindow("abc","asdfgh",WS_OVERLAPPEDWINDOW,100,100,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 msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[10];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"char",MB_YESNO);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","message",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,50,50,"qazwsx",strlen("qazwsx"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,30,30,"ujmik",strlen("ujmik"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否关闭","message",MB_YESNO));
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam,lParam );
}
return 0;
}
以上代码能显示窗体,但不能响应鼠标键盘消息,报错说不能写入文件。请高手指点!
展开
 我来答
13391311353
推荐于2016-06-21
知道答主
回答量:22
采纳率:0%
帮助的人:6.4万
展开全部
在VC6/WIN32 Application平台下,写了个窗体API,显示时报错。代码如下,请高手指点一下!谢谢!
#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wndclas;
wndclas.style=CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW;
wndclas.lpfnWndProc=WindowProc;
wndclas.cbClsExtra=0;
wndclas.cbWndExtra=0;
wndclas.hInstance=hInstance;
wndclas.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclas.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclas.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wndclas.lpszMenuName=NULL;
wndclas.lpszClassName="abc";

RegisterClass(&wndclas);

HWND hwnd;
hwnd=CreateWindow("abc","asdfgh",WS_OVERLAPPEDWINDOW,100,100,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 msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[10];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"char",MB_YESNO);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","message",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,50,50,"qazwsx",strlen("qazwsx"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,30,30,"ujmik",strlen("ujmik"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否关闭","message",MB_YESNO));
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam,lParam );
}
return 0;
}
以上代码能显示窗体,但不能响应鼠标键盘消息,报错说不能写入文
追问
谢谢!
我运行后还出现以下错误:
empty controlled statement found; is this the intent?
追答
什么啊
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式