+ -
当前位置:首页 → 问答吧 → 新手问题:新建一个Win32 应用程序启动后没反应

新手问题:新建一个Win32 应用程序启动后没反应

时间:2011-12-04

来源:互联网

C/C++ code

#include <Windows.h>
#include <stdio.h>

// 声明窗口过程函数
LRESULT CALLBACK WinExample1Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in 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.lpszClassName="example1";
    wndcls.lpszMenuName = NULL;
    wndcls.style = CS_HREDRAW | CS_VREDRAW;
    
    // 注册这个类
    RegisterClass(&wndcls);

    HWND hwnd;
    hwnd = CreateWindow("","",WS_OVERLAPPEDWINDOW,0,0,500,500,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 WinExample1Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    char exChar2[]={"我的第一个windows应用程序"};

    switch (uMsg)
    {
    case WM_CHAR:

        char exChar1[40];
        //sprintf(exChar1,"键盘输入字符的ASCII值为:%d",wParam);
        sprintf_s(exChar1,"键盘输入字符的ASCII值为:%d",wParam);
        MessageBox(hwnd,exChar1,"char",0);
        break;

    case WM_RBUTTONDOWN:

        MessageBox(hwnd,"右键被按下","message",0);
        break;

    case WM_CLOSE:

        if (IDYES == MessageBox(hwnd,"要结束吗?","提示:",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;

    case WM_DESTROY:

        PostQuitMessage(0);
        break;

    case WM_PAINT:

        HDC hDC;
        PAINTSTRUCT ps;
        hDC = BeginPaint(hwnd,&ps);
        RECT rt;
        GetClientRect(hwnd,&rt);
        DrawText(hDC,exChar2,strlen(exChar2),&rt,DT_CENTER);
        EndPaint(hwnd,&ps);
        break;

    default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }

    return 0;
}



以上就是全部代码。

重建,然后启动,就没有任何反应,请前辈指导一下。

作者: seti3d   发布时间: 2011-12-04

VC6下总是提示:Cannot execute program

作者: seti3d   发布时间: 2011-12-04

热门下载

更多