The download button opens the Documents folder and you select an image from the documents. The “Show” button displays horizontal scrolling and an image. If the dialog box is larger than the image, then scrolling is not needed and will not be displayed. The problem is that horizontal scrolling behaves like vertical scrolling (i.e. scrolling up and down instead of scrolling left and right).
Help, please!
//When you click on the Load button, you can select an image from the files and upload it to the dialog box
void CНадеюсьЭтоСохранитьсяDlg::OnBnClickedLoad()
{
CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, _T(
"Image Files (*.bmp;*.jpg;*.png)|*.bmp;*.jpg;*.png|All Files (*/*)|*.*||"));
if (dlg.DoModal() == IDOK) {
CString path = dlg.GetPathName();
m_Image.Destroy();
HRESULT hr = m_Image.Load(path);
if (SUCCEEDED(hr)) {
AfxMessageBox(_T("Изображение загружено"));
}
else {
AfxMessageBox(_T("Не удалось загрузить изображение"));
}
}
}
//When you click on the Show button, scrollbars appear and an image (loaded using the Load button) is displayed
void CНадеюсьЭтоСохранитьсяDlg::OnBnClickedShow()
{
if (!m_Image.IsNull()) {
int width = m_Image.GetWidth();
int height = m_Image.GetHeight();
CRect rect;
GetClientRect(&rect);
if (width > rect.Width()) {
m_pScroll1->SetScrollRange(0, width - rect.Width());
m_pScroll1->SetScrollPos(0);
m_pScroll1->ShowWindow(SW_SHOW);
}
else {
m_pScroll1->ShowWindow(SW_HIDE);
}
Invalidate();
}
}
//Horizontal Scrollbar Handler
void CНадеюсьЭтоСохранитьсяDlg::OnHScroll(UINT nSBCode1, UINT nPos1, CScrollBar* pScrollBar1)
{
CScrollBar* p1 = (CScrollBar*)GetDlgItem(IDC_SCROLLBAR1);
if (pScrollBar1->GetDlgCtrlID() == IDC_SCROLLBAR1) {
int pos = m_pScroll1->GetScrollPos();
switch (nSBCode1) {
case SB_LEFT:
pos = 0; break;
case SB_LINELEFT:
pos -= 1; break;
case SB_LINERIGHT:
pos += 1; break;
case SB_PAGELEFT:
pos -= 5; break;
case SB_PAGERIGHT:
pos += 5; break;
case SB_RIGHT:
pos = 100; break;
case SB_THUMBTRACK:
pos = nPos1; break;
defalt: break;
}
m_pScroll1->SetScrollPos(pos);
Invalidate();
}
CDialog::OnHScroll(nSBCode1, nPos1, pScrollBar1);
}
//Надеюсь Это СохранитьсяDlg.h
// Реализация
protected:
HICON m_hIcon;
// Созданные функции схемы сообщений
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedLoad();
afx_msg void OnBnClickedShow();
afx_msg void OnHScroll(UINT nSBCode1, UINT nPos1, CScrollBar* pScrollBar1);
CScrollBar* m_pScroll1;
CImage m_Image;
};
Where is the error? I just can’t figure it out
Med is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.