WindowsAPI 程序

 
#include <windows.h>
#include <stdio.h>
 
 
HINSTANCE hinst;
 
/* 函数声明 */
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
 
 
//  功能显示一个窗口
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
    WNDCLASSEX wcx;         //窗口类
    HWND hwnd;              //窗口句柄
    MSG msg;                //消息
    BOOL fGotMessage;        //是否成功获取信息
    hinst = hinstance;       //应用程序实例句柄,保存为全局变量     
 
    //填充窗口类的数据结构
    wcx.cbSize = sizeof(wcx);
    wcx.style = CS_HREDRAW | CS_VREDRAW;
 
    wcx.lpfnWndProc = MainWndProc;
    wcx.cbClsExtra=0;
    wcx.cbWndExtra = 0;
    wcx.hInstance = hinstance;
    wcx.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    wcx.hCursor = LoadCursor(NULL,IDC_ARROW);
 
    wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
 
    wcx.lpszMenuName = NULL;
    wcx.lpszClassName = "MainWClass";
    wcx.hIconSm = (HICON)LoadImage(hinstance, // 小图标
        MAKEINTRESOURCE(5),
        IMAGE_ICON,
        GetSystemMetrics(SM_CXSMICON),
        GetSystemMetrics(SM_CYSMICON),
        LR_DEFAULTCOLOR);
    
    // 注册窗口类
    if (!RegisterClassEx(&wcx))
    {
        return 1;
    }
 
    // 创建窗口 
    hwnd = CreateWindow(
        "MainWClass",        // 窗口名
        "CH 2-3",            // 窗口标题 
        WS_OVERLAPPEDWINDOW, // 窗口样式  
        CW_USEDEFAULT,       // 水平位置X:默认 
        CW_USEDEFAULT,       // 垂直位置Y:默认
        CW_USEDEFAULT,       // 宽度:默认
        CW_USEDEFAULT,       // 高度:默认 
        (HWND)NULL,         // 父窗口:无 
        (HMENU)NULL,        // 菜单:使用窗口类的菜单 
        hinstance,           // 应用程序实例句柄 
        (LPVOID)NULL);      // 窗口创建时数据:无 
 
    if (!hwnd)
    {
        return 1;
    }
 
 
    // 显示窗口 
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
 
    // 消息循环
    while (
        (fGotMessage = GetMessage(&msg, (HWND)NULL, 0, 0)) != 0
        && fGotMessage != -1)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
 
    
    
 
}
 
//窗口消息处理函数
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_DESTROY:
        ExitThread(0);
        return 0;
    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
}
 
 
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

这个月太忙没时间看C++

你的鼓励将是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值