zoukankan      html  css  js  c++  java
  • 对话框学习3

    学习一个收缩对话框的方法

    在C***Dlg类中的OnInitDialog函数里

    CRect winRect;
        GetWindowRect(winRect);
        m_winWidth = winRect.right;
        /*CString str;
        str.Format("%d", winRect.Width());
        AfxMessageBox(str);*/
        CRect btRect;
        GetDlgItem(IDC_BUTTON1)->GetWindowRect(btRect);
        m_shrinkWidth = btRect.right;
        winRect.SetRect(winRect.left, winRect.top,
            winRect.right, winRect.bottom);

    GetWindowRect是获取整个对话框的CRect值

    GetDlgItem(IDC_BUTTON1)->GetWindowRect(btRect)则是获取一个控件(按钮)的CRect值,并且在这里记录下来

    双击button1响应消息并添加代码:

    void CShrinkDlg::OnBnClickedButton1()
    {
        // TODO: 在此添加控件通知处理程序代码
        CRect winRect;
        GetWindowRect(winRect);
        if(m_shrikn){
            winRect.SetRect(winRect.left, winRect.top,
                winRect.left + m_winWidth, winRect.bottom);
            GetDlgItem(IDC_BUTTON1)->SetWindowText("<<");
        }else{
            winRect.SetRect(winRect.left, winRect.top,
                winRect.left + m_shrinkWidth, winRect.bottom);
            GetDlgItem(IDC_BUTTON1)->SetWindowTextA(">>");
        }
        MoveWindow(winRect, TRUE);
        m_shrikn = ! m_shrikn;
            
    }

    通过SetRect函数来重新设定对话框大小 

    并通过MoveWindows来实现对话框

    写代码好累啊!

  • 相关阅读:
    Python assert(断言)
    Python importlib(动态导入模块)
    Python 异常处理
    Qt Clipboard剪贴板简单使用
    Qt5 QTableWidget设置列表自动适应列宽
    Fix VNC Desktop Sharing on Ubuntu Desktop 14.04
    Golang 交叉编译
    stdobj to array php
    Elasticsearch-集群原理
    Elasticsearch-基本操作2
  • 原文地址:https://www.cnblogs.com/louzhang/p/2706974.html
Copyright © 2011-2022 走看看