我在MainFrame类中加入了一个第三方的网格控件,在响应此控件的右击消息中弹出一个Dialog,怎样指定Dialog显示的位置?我以下的代码只显示在第三方控件的中间void CMainFrame::OnGridRClick(NMHDR *pNotifyStruct, LRESULT* /*pResult*/)
{
NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
int Col = pItem->iColumn;
int Row = pItem->iRow;
if(Row > m_Mxl.m_dataList.GetCount()) return;
CPoint pt;
GetCursorPos(&pt); //返回光标的位置
CEditDlg* dlg = new CEditDlg;
dlg->SetWindowPos(this,pt.x,pt.y,30,60,SWP_SHOWWINDOW);
dlg->DoModal(); delete dlg;//
}
{
NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
int Col = pItem->iColumn;
int Row = pItem->iRow;
if(Row > m_Mxl.m_dataList.GetCount()) return;
CPoint pt;
GetCursorPos(&pt); //返回光标的位置
CEditDlg* dlg = new CEditDlg;
dlg->SetWindowPos(this,pt.x,pt.y,30,60,SWP_SHOWWINDOW);
dlg->DoModal(); delete dlg;//
}
也可以动态创建CreateWindow
2。用MoveWindow或SetWindowPos.
3.SetWindowPlacement;
BOOL CDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // TODO: 在此添加额外的初始化
CRect rect;
::GetWindowRect( GetDesktopWindow()->GetSafeHwnd(), rect );
::SetWindowPos( m_hWnd, HWND_TOPMOST, rect.right - 50, rect.top + 50, 34, 34, SWP_SHOWWINDOW );
return TRUE; // return TRUE unless you set the focus to a control
// 异常:OCX 属性页应返回 FALSE
}上面演示了如何把对话框位置放到屏幕右上角。
我试试
MoveWindow(0,0,100,100)
4个参数分别为TOP,BOTTOM,LEFT,RIGHT
更改它们的值就能移到屏幕的任何地方,并且改变大小。