• Win32 对话框(4)


    4.21 如何使用ENTER键控制对话框中控件的输入焦点

    将键盘转回Tab建

    BOOL CDemoDlg::PreTranslateMessage(MSG* pMsg) 
    {
        //将按键为ENTER的WM_KEYDOWN消息转换成按键为TAB的消息
        if (pMsg->message == WM_KEYDOWN)
        {
            if (pMsg->wParam == VK_RETURN)
            {
                pMsg->wParam = VK_TAB;
            }
        }
    
        return CDialog::PreTranslateMessage(pMsg);
    }
    

    4.22 如何屏蔽对话框按ESC或ENTER键退出

    还是一样,直接返回TRUE,什么事情也不发生

    BOOL CDemoDlg::PreTranslateMessage(MSG* pMsg) 
    {
        if (pMsg->message == WM_KEYDOWN)
        {
            if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)
            {
                return TRUE;
            }
        }
    
        return CDialog::PreTranslateMessage(pMsg);
    }
    

    4.23 如何设置应用程序中对话框的默认颜色

    http://blog.163.com/wenxianliang08@126/blog/static/8358326320101020173473/

    //设置对话框的默认颜色
    SetDialogBkColor(RGB(0x99, 0xCC, 0xFF), RGB(0xFF, 0x00, 0x00));
    

    4.24 如何创建消息对话框

    即MessageBox,没啥好说的

    void CDemoDlg::OnShowDlg1() 
    {
        MessageBox(_T("MessageBox函数创建的消息对话框"), 
            _T("Demo"), MB_ICONEXCLAMATION);    
    }
    
    void CDemoDlg::OnShowDlg2() 
    {
        AfxMessageBox(_T("AfxMessageBox函数创建的消息对话框"));    
    }
    

    4.25 如何实现对话框在桌面工作区的停靠

    一种思想,当左右pos少于50的时候就更改pos

    void CDemoDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 
    {
        CDialog::OnWindowPosChanging(lpwndpos);
        
        //获得桌面工作区大小
        CRect rect;
        SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
    
        //左停靠
        if (abs(lpwndpos->x - rect.left) <= 50)
        {
            lpwndpos->x = rect.left;
            lpwndpos->y = rect.top;
            lpwndpos->cy = rect.Height();
        }
        //右停靠
        else if (abs(lpwndpos->x + lpwndpos->cx-rect.right) <= 50)
        {
            lpwndpos->x = rect.right - lpwndpos->cx;
            lpwndpos->y = rect.top;
            lpwndpos->cy = rect.Height();
        }
        else
        {
            lpwndpos->cy = m_nHeigh;
        }
    
        if (lpwndpos->y < rect.top)
        {
            lpwndpos->y = rect.top;
        }
    }
    
    

    4.26 如何在客户区中移动对话框

  • 相关阅读:
    shell 学习笔记 LinuxShell脚本攻略(第2版)
    [六省联考2017]分手是祝愿
    [SDOI2010]粟粟的书架
    [CQOI2018]解锁屏幕
    [SCOI2007]最大土地面积
    CF369E Valera and Queries
    CF817F MEX Queries
    [HEOI2016/TJOI2016]求和
    [CQOI2018]九连环
    [HNOI2015]亚瑟王
  • 原文地址:https://www.cnblogs.com/Clingingboy/p/1990807.html
Copyright © 2020-2023  润新知