006
19.06.2003, 22:08 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo, Die Zuordnung in Deine Liste kannst Du selbst noch implementieren.
C++: |
public: afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnMouseMove(UINT nFlags, CPoint point); private: CPoint m_pointTopLeftC1, m_pointTopLeftC2, m_pointTopLeftC3; const CSize m_sizeEllipse1, m_sizeEllipse2, m_sizeEllipse3; bool m_bCircle1, m_bCircle2, m_bCircle3; CSize m_sizeOffset;
|
C++: |
CAnsichtDlg::CAnsichtDlg(CWnd* pParent /*=NULL*/) : CDialog(CAnsichtDlg::IDD, pParent), m_sizeEllipse1(100, 100), m_sizeEllipse2(80,80), m_sizeEllipse3(170, 170), m_pointTopLeftC1(10, 10), m_pointTopLeftC2(100, 100), m_pointTopLeftC3(150, 150), m_sizeOffset(0, 0) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_bCircle1 = FALSE; m_bCircle2 = FALSE; m_bCircle3 = FALSE; } ........... ........... void CAnsichtDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // Gerätekontext zum Zeichnen
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Symbol in Client-Rechteck zentrieren int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2;
// Symbol zeichnen dc.DrawIcon(x, y, m_hIcon); } else { CBrush *pBrushBlank[3]; CPaintDC dc(this); // device context for painting pBrushBlank[0] = new CBrush(RGB(255,0,0)); pBrushBlank[1] = new CBrush(RGB(0,255,0)); pBrushBlank[2] = new CBrush(RGB(0,0,255));
dc.SelectObject(pBrushBlank[0]); dc.Ellipse(CRect(m_pointTopLeftC1, m_sizeEllipse1)); dc.SelectObject(pBrushBlank[1]); dc.Ellipse(CRect(m_pointTopLeftC2, m_sizeEllipse2)); dc.SelectObject(pBrushBlank[2]); dc.Ellipse(CRect(m_pointTopLeftC3, m_sizeEllipse3));
for(int i = 0; i<=2; i++) delete pBrushBlank[i];
CDialog::OnPaint(); } }
void CAnsichtDlg::OnLButtonDown(UINT nFlags, CPoint point) { CRect rectEllipse1(m_pointTopLeftC1, m_sizeEllipse1); CRgn Circle1; CRect rectEllipse2(m_pointTopLeftC2, m_sizeEllipse2); CRgn Circle2; CRect rectEllipse3(m_pointTopLeftC3, m_sizeEllipse3); CRgn Circle3;
CClientDC dc(this); dc.LPtoDP(rectEllipse1); Circle1.CreateEllipticRgnIndirect(rectEllipse1); if (Circle1.PtInRegion(point)){ SetCapture(); m_bCircle1 = TRUE; CPoint pointTopLeft1(m_pointTopLeftC1); dc.LPtoDP(&pointTopLeft1); m_sizeOffset = point - pointTopLeft1; }
dc.LPtoDP(rectEllipse2); Circle2.CreateEllipticRgnIndirect(rectEllipse2); if (Circle2.PtInRegion(point)){ SetCapture(); m_bCircle2 = TRUE; CPoint pointTopLeft2(m_pointTopLeftC2); dc.LPtoDP(&pointTopLeft2); m_sizeOffset = point - pointTopLeft2; }
dc.LPtoDP(rectEllipse3); Circle3.CreateEllipticRgnIndirect(rectEllipse3); if (Circle3.PtInRegion(point)){ SetCapture(); m_bCircle3 = TRUE; CPoint pointTopLeft3(m_pointTopLeftC3); dc.LPtoDP(&pointTopLeft3); m_sizeOffset = point - pointTopLeft3; }
CDialog::OnLButtonDown(nFlags, point); }
void CAnsichtDlg::OnLButtonUp(UINT nFlags, CPoint point) { if (m_bCircle1){ ::ReleaseCapture(); m_bCircle1 = FALSE; }
if (m_bCircle2){ ::ReleaseCapture(); m_bCircle2 = FALSE; }
if (m_bCircle3){ ::ReleaseCapture(); m_bCircle3 = FALSE; } CDialog::OnLButtonUp(nFlags, point); }
void CAnsichtDlg::OnMouseMove(UINT nFlags, CPoint point) { if (m_bCircle1){ CClientDC dc(this); CRect rectOld(m_pointTopLeftC1, m_sizeEllipse1); dc.LPtoDP(rectOld); InvalidateRect(rectOld, TRUE); m_pointTopLeftC1 = point - m_sizeOffset; dc.DPtoLP(&m_pointTopLeftC1); CRect rectNew(m_pointTopLeftC1, m_sizeEllipse1); dc.LPtoDP(rectNew); InvalidateRect(rectNew, TRUE); }
if (m_bCircle2){ CClientDC dc(this); CRect rectOld(m_pointTopLeftC2, m_sizeEllipse2); dc.LPtoDP(rectOld); InvalidateRect(rectOld, TRUE); m_pointTopLeftC2 = point - m_sizeOffset; dc.DPtoLP(&m_pointTopLeftC2); CRect rectNew(m_pointTopLeftC2, m_sizeEllipse2); dc.LPtoDP(rectNew); InvalidateRect(rectNew, TRUE); }
if (m_bCircle3){ CClientDC dc(this); CRect rectOld(m_pointTopLeftC3, m_sizeEllipse3); dc.LPtoDP(rectOld); InvalidateRect(rectOld, TRUE); m_pointTopLeftC3 = point - m_sizeOffset; dc.DPtoLP(&m_pointTopLeftC3); CRect rectNew(m_pointTopLeftC3, m_sizeEllipse3); dc.LPtoDP(rectNew); InvalidateRect(rectNew, TRUE); }
CDialog::OnMouseMove(nFlags, point); }
|
-- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe |