admin管理员组文章数量:1125462
Code:
void CPublicTalksDatabaseDlg::AdjustFindDialogPosition(const CRect& rectControl)
{
CRect rectDlg;
m_pFindDlg->GetWindowRect(rectDlg);
// Calculate the new Y position to move the dialog
int newY = rectControl.bottom + GetSystemMetrics(SM_CYHSCROLL); // Use vertical scrollbar width
// Move the dialog to the new Y position, keeping the same X position
rectDlg.MoveToY(newY);
m_pFindDlg->MoveWindow(&rectDlg);
}
It is not working correctly. The rectControl
represents the child control on the main window in screen coordinates. I now want to move the m_pFindDlg
(if needed) so that atleast part of the control will be visible. Right now it is not working correctly.
It ends up here:
But I thought it might up up here:
Code:
void CPublicTalksDatabaseDlg::AdjustFindDialogPosition(const CRect& rectControl)
{
CRect rectDlg;
m_pFindDlg->GetWindowRect(rectDlg);
// Calculate the new Y position to move the dialog
int newY = rectControl.bottom + GetSystemMetrics(SM_CYHSCROLL); // Use vertical scrollbar width
// Move the dialog to the new Y position, keeping the same X position
rectDlg.MoveToY(newY);
m_pFindDlg->MoveWindow(&rectDlg);
}
It is not working correctly. The rectControl
represents the child control on the main window in screen coordinates. I now want to move the m_pFindDlg
(if needed) so that atleast part of the control will be visible. Right now it is not working correctly.
It ends up here:
But I thought it might up up here:
Share Improve this question edited 2 days ago Andrew Truckle asked 2 days ago Andrew TruckleAndrew Truckle 19k17 gold badges82 silver badges214 bronze badges 2- Which is the child control on the main window? The list box starting with "001 -- How Well Do You Know God?"? – Jabberwocky Commented 2 days ago
- @Jabberwocky In that instance the child is the selected item of the list box you refer to, yes. – Andrew Truckle Commented yesterday
1 Answer
Reset to default 0Ironically, something as simple as this seems better:
void CPublicTalksDatabaseDlg::AdjustFindDialogPosition(CRect &rectControl)
{
CRect rectDlg;
m_pFindDlg->GetWindowRect(rectDlg);
m_pFindDlg->SetWindowPos(nullptr, rectControl.CenterPoint().x, rectControl.CenterPoint().y, 0, 0, SWP_NOSIZE | SWP_NOZORDER |
SWP_SHOWWINDOW);
}
Update
I stumbled on the solution (not explanation) quite by chance by making the function static
:
// Adjusts the position of the find dialog relative to a specified control or a list box item
static void AdjustFindDialogPosition(CMyFindDialog* pFindDialog, CWnd * pFocusControl, const int itemIndex = -1) {
if (pFindDialog && pFocusControl) {
CRect rectControl{};
if (itemIndex != -1) {
// Get rectangle of the list box item corresponding to itemIndex
CListBox* pListBox = dynamic_cast<CListBox*>(pFocusControl);
if (pListBox) {
pListBox->GetItemRect(itemIndex, &rectControl);
pListBox->ClientToScreen(&rectControl);
}
}
else {
// Get window rectangle of the specified control
pFocusControl->GetWindowRect(rectControl);
}
CRect rectDlg;
pFindDialog->GetWindowRect(rectDlg);
// Set the find dialog position to the center of the control's rectangle
const auto centerPoint = rectControl.CenterPoint();
pFindDialog->SetWindowPos(nullptr,
centerPoint.x,
centerPoint.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
}
}
Now:
本文标签: visual cAdjusting popup window position is working incorrectlyStack Overflow
版权声明:本文标题:visual c++ - Adjusting popup window position is working incorrectly - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736627294a1945702.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论