刚学VC++,照抄一段代码,出了问题,看一下。。

来源:百度知道 编辑:UC知道 时间:2024/05/15 02:47:42
#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_CROSS);
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinSunProc;
wndclass.lpszClassName="abc";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);

HWND hwnd;
hwnd=CreateWindow("abc","´°¿ÚÃû×Ö",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL);

case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"1t1t",strlen("1t1t"));
EndPaint(hwnd,&ps);

这段后面少一个break,导致后面代码总是被执行

把exe文件拖到Dos窗口下试试,不行就在程序的头加语句:#include <stdlib.h>
在main函数返回之前加语句system("pause");
试试吧!

case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"1t1t",strlen("1t1t"));
EndPaint(hwnd,&ps);
break; //加break;

楼上说法绝对正确
这段后面少一个break,导致后面代码总是被执行
以后敲代码要细心