回 帖 发 新 帖 刷新版面

主题:程序哪里有错?

以下程序创建一个窗口,在VC中有错误,不知怎么改正,请高手赐教:

#define STRICT
#include<windows.h>
#include<windowsx.h>
#include<string.h>
char Name[]="MakeWin";
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int pascal WinMain(HINSTANCE hInst,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,int nCmdShow)
{HWND hwnd;
MSG Msg;
WNDCLASS W;
memset(&W,0,sizeof(WNDCLASS));
W.style=CS_HREDRAW|CS_VREDRAW;
W.lpfnWndProc=hInst;
W.hInstance=hInst;
W.hbrBackground=GetStockBrush(WHITE_BRUSH);
W.lpszClassName=Name;
RegisterClass(&W);
hwnd=CreateWindow(Name,Name,WS_OVERLAPPENWINDOW,10,10,600,400,NULL,NULL,hInst,NULL);
     ShowWindow(hwnd,nCmdShow);
     UpdateWindow(hwnd);
     while(GetMessage(&Msg,NULL,0,0))
     {TranslateMessage(&Msg);
      DispatchMessage(&Msg);}
     return Msg.wParam;}

LRESULT CALLBACK_export WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
{if(Message==WM_DESTROY)
{PostQuitMessage(0);
return 0;}
return DefWindowProc(hwnd,Message,wParam,lParam);}
[em10]

回复列表 (共3个回复)

沙发

你是不是该把错误提出来?

板凳

我刚接触API,这是一本老书上的例子,我原原本本照打出来,编译时有错,却不知道怎么错了,还望赐教

3 楼

错识有五个正确代码如下:
#define STRICT
#include<windows.h>
#include<windowsx.h>
#include<string.h>
char Name[]="MakeWin";
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int pascal WinMain(HINSTANCE hInst,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,int nCmdShow)
{
    HWND hwnd;
    MSG Msg;
    WNDCLASS W;
    memset(&W,0,sizeof(WNDCLASS));
    W.style=CS_HREDRAW|CS_VREDRAW; //1
    W.lpfnWndProc=WndProc;
    W.hInstance=hInst;
    W.hbrBackground=GetStockBrush(WHITE_BRUSH);
    W.lpszClassName=Name;
    RegisterClass(&W);
    hwnd=CreateWindow(Name,Name,WS_OVERLAPPEDWINDOW,10,10,600,400,NULL,NULL,hInst,NULL);//2
    ShowWindow(hwnd,nCmdShow);
    UpdateWindow(hwnd);
    while(GetMessage(&Msg,NULL,0,0))
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam) //4
{
    if(Message==WM_DESTROY)
    {
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hwnd,Message,wParam,lParam);//5
}

我来回复

您尚未登录,请登录后再回复。点此登录或注册