如何有效地使用对话框

2016-01-29 11:52 12 1 收藏

如何有效地使用对话框,如何有效地使用对话框

【 tulaoshi.com - C语言心得技巧 】

如何有效地使用对话框
译者:徐景周(原作:VGirish)

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)

Q:如何在对话框中加入工具条

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com) 在 OnInitDialog 中加入下面代码:
BOOL CYourDlg::OnInitDialog(){       CDialog::OnInitDialog();       // Create the toolbar. To understand the meaning of the styles used, you        // can take a look at the MSDN for the Create function of the CToolBar class.          ToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS |CBRS_FLYBY | CBRS_BORDER_BOTTOM);      // I have assumed that you have named your toolbar''s resource as IDR_TOOLBAR1.      // If you have given it a different name, change the line below to accomodate       // that by changing the parameter for the LoadToolBar function.        ToolBar.LoadToolBar(IDR_TOOLBAR1);        CRect rcClientStart;      CRect rcClientNow;      GetClientRect(rcClientStart);      // To reposition and resize the control bar     RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0, reposQuery, rcClientNow);     CPoint ptOffset(rcClientNow.left - rcClientStart.left,rcClientNow.top-rcClientStart.top);     CRect rcChild;     CWnd* pwndChild = GetWindow(GW_CHILD);     while (pwndChild)     {       pwndChild->GetWindowRect(rcChild);       ScreenToClient(rcChild);       rcChild.OffsetRect(ptOffset);       pwndChild->MoveWindow(rcChild, FALSE);       pwndChild = pwndChild->GetNextWindow();     }   CRect rcWindow;     GetWindowRect(rcWindow);     rcWindow.right += rcClientStart.Width() - rcClientNow.Width();     rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();     MoveWindow(rcWindow, FALSE);     // And position the control bars     RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);       return TRUE;  // return TRUE  unless you set the focus to a control  }
Q:如何改变对话框的形状?

可用下面一些函数:
CreatePolygonRgn
CreateRectRgn
CreateRoundRectRgn 等.
  CRgn m_rgn;  // Put this in your dialog''s header file. i.e. a member variable  // This Gets the size of the Dialog: This piece of code is to be placed in the  // OnInitDialog Function of your dialog.  CRect rcDialog  GetClientRect(rcDialog);  // The following code Creates the area and assigns it to your Dialog  m_rgn.CreateEllipticRgn(0, 0, rcDialog.Width(), rcDialogHeight());  SetWindowRgn(GetSafeHwnd(), (HRGN) m_rgn, TRUE);
Q:如何实现非客户区移动?

可用下面二种方法
// Handler for WM_LBUTTONDOWN message  void CYourDialog::OnLButtonDown(UINT nFlags, CPoint point)  {     CDialog::OnLButtonDown(nFlags, point);     PostMessage( WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM( point.x, point.y));  }  // Handler for WM_NCHITTEST message  LONG CYourDialog::OnNcHitTest( UINT uParam, LONG lParam )  {       int xPos = LOWORD(lParam);     int yPos = HIWORD(lParam);     UINT nHitTest = CDialog::OnNcHitTest(CSize(xPos, yPos));     return (nHitTest == HTCLIENT) ? HTCAPTION : nHitTest;  }

Q:如何使对话框初始为最小化状态?

在 OnInitDialog 中加入下面代码:
SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, NULL);
Q:如何限定对话框大小范围?

在 WM_SIZING中加入下面代码:
void CYourDialog::OnSizing(UINT fwSide, LPRECT pRect)   {     if(pRect->right - pRect->left <=200)     pRect->right = pRect->lef
                        

来源:https://www.tulaoshi.com/n/20160129/1483687.html

延伸阅读
1、意图 有时候我们希望将非模态窗口显示为模态窗口。比如在IE的“文件”菜单下选择“打印”,弹出的“打印”对话框就是非模态的(也许我们不太清楚Microsoft的设计意图,一般来说这里的“打印”对话框应该是模态的)。这种情况下如何将“打印”对话框显示为模态的呢(这个对话框对我们来说是Black Box)? 2、简单实现 简单...
标签: 生活常识
如何有效地使用净化器   很多净化器上都有显示器,如果一直显示空气质量不好,就应该查找原因,是机器出了问题,还是传感器被污染了。找到问题后,应及时进行修理或清洁。 空气净化器怎么摆放最合适? 在雾霾的影响下,不少关注健康的消费者,主动为居室添置了空气净化器。那么,如何能够有效地使用净化器,达到更佳...
获取静态控件文本的方法:GetDlgItem函数获得对话框中控件的指针,然后调用GetWindowText获得文本。注意:静态控件的属性必须将Notify选为可能。同理:SetWindowText可以指定文本。 获取编辑框内容:GetDlgItem(ID)-GetWindowText(); 字符内容转换为数值:atoi()把字符串转换为数值;同理:数字到字符串itoa(); GetDlgItemText(ID)可以完成...
自绘对话框 作者:Alon 下载示例源代码 闲来无事,写了一个简单的对话框界面,希望给需要的朋友有所帮助。 界面如下: 界面很单调,我只是想说明一下如何实现界面的自绘。如果有需要,也可以绘制更复杂漂亮的界面。 程序的实现也不复杂,接下来就跟着我一步一步做。...
标签: autocad教程
在执行AutoCAD命令的过程中,用户与AutoCAD之间主要是通过文本窗口和对话框来进行人机交互。 2.3.1 使用文本窗口 AutoCAD的文本窗口与AutoCAD窗口相对独立,用户可通过如下方式来显示该窗口: (1) 在AutoCAD中按F2键 (2) 选择菜单【View(视图)】→【Display(显示)】→【Text Window(文本窗口)】 (3) 在命令...

经验教程

820

收藏

94
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部