注册 登录
编程论坛 VC++/MFC

vc++6.0 编译连接OK,运行报错,哪位大虾米看看

gw820522 发布于 2010-12-06 14:04, 585 次点击
//vc++6.0 编译连接OK,运行报错,哪位大虾米看看

#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinExample1Proc(HWND hwnd,UINT uMsg, WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
    wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
    wndcls.hInstance=hInstance;
    wndcls.lpfnWndProc=WinExample1Proc;
    wndcls.lpszMenuName=NULL;
    wndcls.style=CS_HREDRAW|CS_VREDRAW;
    RegisterClass(&wndcls);
    HWND hwnd;
    hwnd=CreateWindow("example1","一个WIN窗口",WS_OVERLAPPEDWINDOW,0,0,500,500,NULL,NULL,hInstance,NULL);
    ShowWindow(hwnd,SW_NORMAL);
    UpdateWindow(hwnd);
    MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}

LRESULT CALLBACK WinExample1Proc(HWND hwnd,UINT uMsg, WPARAM wParam,LPARAM lParam)
{
    char exChar2[]={"第一个WIN程序"};
    switch(uMsg)
    {
        case WM_CHAR:
            char exChar1[40];
            sprintf(exChar1,"ASCII值为:%d",wParam);
            break;   
        default:
            return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }   
    return 0;
}
1 回复
#2
andyandy2010-12-06 17:19
设计窗口类时漏了这一句
wndcls.lpszClassName="example1";
——WinMain函数体第8行后。
1