zoukankan      html  css  js  c++  java
  • 简单的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

  • 相关阅读:
    启动程序相关的命令
    分享的几行代码
    各种大数据软件安装
    tomcat报没法分配内存大小解决方案
    数据库事务
    pytorch之CNN实现
    搜索与匹配
    调试 pytorch 及 python 的 特殊语法
    图神经网络 GCN 等综述(转载)
    关于【finder不能完成该操作 因为未能读取或写入"文件名"中的某些数据(错误代码-36)】(实测,好用)
  • 原文地址:https://www.cnblogs.com/luowei010101/p/2170107.html
Copyright © 2011-2022 走看看