Windows开发:WinSDK初始化

一.简介

分享图片

 

二.编译流程

对话框编辑器(Dialog Editor)->.DLG文件->集合成.RC文件

图片编辑器(Image Editor)->.BMP/.ICO/.CUR文件->集合成.RC文件

字体编辑器(Font Editor)->.FON文件->集合成.RC文件

.RC文件通过资源编译器(RC Compiler)->.RES文件->链接(LINKER)

 

文件(.h)+源文件(.c)->通过C语言编译器(C Compiler)->.OBJ文件+动态库(.LIB/C runtime/DLL Import)->链接器(LINKER)

链接器最终生成.EXE文件

 

三.流程

#include <windows.h>
 
//1.声明回调函数
LONG WINAPI WndProc(HWND,UINT,WParaM,LParaM);
 
 
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdshow){
 
    //2.填充窗口类
    WNDCLASS wc;
    HWND hwnd;
    MSG msg;
 
    wc.style=0;    //Class Style
    wc.lpfnWndProc=(WNDPROC)WndProc;    //Window procedure address
    wc.cbClsExtra=0;    //Class extra bytes
    wc.cbWndExtra=0;    //Window extra bytes
    wc.hInstance=hInstance;    //Instance handle
    wc.hIcon=LoadIcon(NULL,IDC_ARROW);    //Icon handle
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);    //Cursor handle
    wc.hbrBackground=(HBrush)(COLOR_WINDOW+1);    //Background handle
    wc.lpszMenuName=NULL;    //Menu name
    wc.lpszClassName="MyWndClass";    //WNDCLASS name
    
 
    //3.注册窗口类
    RegisterClass(&wc);
 
    //4.创建窗口
    hwnd=CreateWindow(
        "MyWndClass",//WNDCLASS name
        "SDK Application",//Window title
        WS_OVERLAPPEDWINDOW,//Window style
        CW_USEDEFAULT,//Horizontal position
        CW_USEDEFAULT,//Vertical position
        CW_USEDEFAULT,//Initial width
        CW_USEDEFAULT,//Initial height
        HWND_DESKTOP,//Handle of parent window
        NULL,//Menu handle
        hInstance,//Application‘s instance handle
        NULL                    //Window-creation data
    );
 
    //5.显示更新窗口
    ShowWindow(hwnd,nCmdshow);
    UpdateWindow(hwnd);
    
    //6.消息循环
    while(GetMessage(&msg,NULL,0)){
        TranlateMessage(&msg);
        dispatchMessage(&msg);
    }
 
    return msg.wParam;
 
}
 
//7.实现回调函数处理消息
LPRESULT CALLBACK WndProc(HWND hwnd,UINT message,WParaM wParam,LParaM lParam){
    
    PAINTSTRUCT ps;
    HDC hdc;
 
    switch(message){
    
    case WM_PAINT:
        hdc=BeginPaint(hwnd,&ps);
        Ellipse(hdc,200,100);
        EndPaint(hwnd,&ps);
        return 0;
 
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
 
    return DefWindowProc(hwnd,message,wParam,lParam);
 
}

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...