• 简单的Win 32 Application


     

    //WinMain

    #include <windows.h>

    #include <stdio.h>

     

    LRESULT CALLBACK WinProcOne(

        HWND hwnd,

        UINT uMessage,

        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(LTGRAY_BRUSH);

        wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);

        wndcls.hIcon=LoadIcon(NULL,IDI_QUESTION);

        wndcls.hInstance=hInstance;

        wndcls.lpfnWndProc=WinProcOne;

        wndcls.lpszClassName="WndClassName2011";

        wndcls.lpszMenuName=NULL;

        wndcls.style=CS_HREDRAW|CS_VREDRAW;

        RegisterClass(&wndcls);

     

        HWND hwnd;

        hwnd=CreateWindow("WndClassName2011","创建一个窗口应用程序",WS_OVERLAPPEDWINDOW,

            0,0,600,400,NULL,NULL,hInstance,NULL);

        ShowWindow(hwnd,SW_SHOWNORMAL);

        UpdateWindow(hwnd);

     

        MSG msg;

        while(GetMessage(&msg,NULL,0,0))

        {

            TranslateMessage(&msg);

            DispatchMessage(&msg);

        }

        return 0;

    }

     

    LRESULT CALLBACK WinProcOne(

        HWND hwnd,

        UINT uMessage,

        WPARAM wParam,

        LPARAM lParam

    )

    {

        switch(uMessage)

        {

        case WM_CHAR:

            char szChar[20];

            sprintf(szChar,"char is %d",wParam);

            MessageBox(hwnd,szChar,"Create Window Program",MB_OK);

            break;

        case WM_LBUTTONDOWN:

            MessageBox(hwnd,"left mouse clicked","Window Program",MB_OK);

            HDC hdc;

            hdc=GetDC(hwnd);

            TextOut(hdc,0,50,"创建一个窗口应用程序",strlen("创建一个窗口应用程序"));

            ReleaseDC(hwnd,hdc);

            break;

        case WM_PAINT:

            HDC hDC;

            PAINTSTRUCT ps;

            hDC=BeginPaint(hwnd,&ps);

            TextOut(hDC,0,0,"响应WM_PAINT消息",strlen("响应WM_PAINT消息"));

            EndPaint(hwnd,&ps);

            break;

        case WM_CLOSE:

            if(IDYES==MessageBox(hwnd,TEXT("是否真的结束?"),"window program",MB_YESNO))

            {

                DestroyWindow(hwnd);

            }

            break;

        case WM_DESTROY:

            PostQuitMessage(0);

            break;

        default:

            return(DefWindowProc(hwnd,uMessage,wParam,lParam));

        }

        return 0;

    }

     

    截图:

     

    源程序下载地址:http://down.qiannao.com/space/file/luowei505050/WinMain.rar/.page

  • 相关阅读:
    artDialog组件应用学习(二)
    artDialog组件应用学习(一)
    MVC Request.UrlReferrer为null
    jquery的toggle()方法
    Windows 和 Linux 下生成以当前时间命名的文件
    再提供一种解决Nginx文件类型错误解析漏洞的方法
    Nginx 1.5.2 + PHP 5.5.1 + MySQL 5.6.10 在 CentOS 下的编译安装
    架构师对话
    Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器
    Nginx 0.7.x + PHP 5.2.6(FastCGI)+ MySQL 5.1 在128M小内存VPS服务器上的配置优化
  • 原文地址:https://www.cnblogs.com/luowei010101/p/2170107.html
Copyright © 2020-2023  润新知