zoukankan      html  css  js  c++  java
  • Windows API编程(一)完整的示范程序

    ##

    #include <windows.h>
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//回调函数;
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASS wndclass;//窗口类;
        MSG msg;
        wndclass.style = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc = WndProc;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 0;
        wndclass.hInstance = hInstance;
        wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        wndclass.lpszMenuName = NULL;
        wndclass.lpszClassName = L"Window窗口创建";  //窗口类名称
    
        if (!RegisterClass(&wndclass))//注册窗口;
        {
            MessageBox(NULL, L"创建失败", L"error", MB_OK);
            return false;
        }
    
        HWND hwnd = CreateWindow(    //创建窗口,返回句柄;
            L"Window窗口创建",  //1.窗口类名称
            L"window窗口创建",  //2.窗口标题
            WS_OVERLAPPEDWINDOW, //3.窗口风格
            CW_USEDEFAULT,  //4.窗口左上角相对于屏幕左上角的初始x坐标
            CW_USEDEFAULT,  //5.窗口左上角相对于屏幕左上角的初始y坐标
            CW_USEDEFAULT,  //6.窗口宽度
            CW_USEDEFAULT,  //7.窗口高度
            NULL,           //8.一个子窗口的父窗口的句柄,或隶属窗口的拥有者窗口的句柄,若没有拥有者窗口或者父窗口,置为NULL;
            NULL,           //9.选单句柄
            hInstance,      //10.创建窗口对象的应用程序的实例句柄
            NULL            //11.创建窗口的额外参数
            );
    
        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)
    {
        switch (message)
        {
        case WM_PAINT:
            HDC hdc;
            PAINTSTRUCT ps;
            hdc = BeginPaint(hwnd, &ps);
            TextOut(hdc, 20, 20, L"Window OK!", 10);
            EndPaint(hwnd, &ps);
            return 0;
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        }
        return DefWindowProc(hwnd, message, wParam, lParam);
    }
  • 相关阅读:
    Ubuntu环境下mysql常见的操作
    Ubuntu 下 Galera cluster for MySQL 集群安装
    Linux如何查看进程、杀死进程、启动进程等常用命令
    Ubuntu16.04配置静态IP地址
    Linux软件包管理之源码包、脚本安装包
    Linux软件包管理之yum在线管理
    Linux软件包管理之RPM命令
    Linux文本编辑器vim
    Linux常用命令之网络和关机重启命令
    Linux常用命令之压缩和解压缩命令
  • 原文地址:https://www.cnblogs.com/tinaluo/p/6867177.html
Copyright © 2011-2022 走看看