zoukankan      html  css  js  c++  java
  • 创建一个Windows窗体

    20140702加:

    WS_OVERLAPPEDWINDOW这个属性如果写成WS_OVERLAPPED,则窗口没有最大最小按钮以及左边的系统的菜单。

    vs2010下的代码提示快捷键:CTRL + J

    step:

    窗口类赋值(12个参数)

    注册窗口类

    创建窗口

    消息循环

     

    #include<Windows.h>
    #include<tchar.h>
    
    LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
        const TCHAR pClassName[] = _T("MyWindow");
        WNDCLASSEX wcex;
        wcex.cbSize = sizeof(WNDCLASSEX);
        wcex.cbClsExtra = 0;
        wcex.cbWndExtra = 0;
        wcex.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);
        wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
        wcex.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
        wcex.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION);
        wcex.hInstance = hInstance;
        wcex.lpfnWndProc = WindowProc;
        wcex.lpszClassName = pClassName;
        wcex.lpszMenuName = NULL;
        wcex.style = CS_HREDRAW | CS_VREDRAW;
        BOOL bRet = ::RegisterClassEx(&wcex);
        if(!bRet)
        {
            MessageBox(NULL, _T("提示"), _T("注册窗口类失败"), MB_OK);
            return FALSE;
        }
        HWND hWnd = ::CreateWindowEx(0, pClassName, _T("WinDemo"), WS_VISIBLE|WS_OVERLAPPEDWINDOW, 
                                    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
                                    NULL, NULL, hInstance, NULL);
        
        if(NULL == hWnd)
        {
            MessageBox(NULL, _T("提示"), _T("创建窗口失败!"), MB_OK);
            return FALSE;
        }
        ::ShowWindow(hWnd, SW_SHOW);
        ::UpdateWindow(hWnd);
    
        MSG msg;
        while(GetMessage(&msg, NULL, 0, 0))
        {
            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);
        }
        return TRUE;
    }
    LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch(uMsg)
        {
            case WM_CLOSE:
                ::DestroyWindow(hwnd);
                return 0;
            case WM_DESTROY:
                ::PostQuitMessage(0);
                return 0;
            default:
                break;
        }
        return ::DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
  • 相关阅读:
    《数据通信与网络》笔记--数据链路层的成帧
    设计模式10---设计模式之原型模式(Prototype)
    Yii 控制dropdownlist / select 控件的宽度和 option 的宽度
    [置顶] 如何vs在cocos2dx项目中打印中文
    mongodb实现简单的增删改查
    北京和硅谷在创新方面的区别
    Android 解决Gallery下ScrollView滑动事件冲突
    Java 授权内幕--转载
    JAVA 上加密算法的实现用例---转载
    基于事件的 NIO 多线程服务器--转载
  • 原文地址:https://www.cnblogs.com/wenwujuncheng/p/3743988.html
Copyright © 2011-2022 走看看