Hey,
To get the logical coords of a mouse click in a veiw class i have ended up creating a new DC and duplicting the OnDraw() setup
Is there an easier way??
Code:
// ----------------------------------------------------------------------------------------
//
// ----------------------------------------------------------------------------------------
void CWindowDesignerView::OnLButtonDown(UINT nFlags, CPoint point) {
CPoint VirtualPoint=point;
/////////////////////////////////////////////////////////////////////////
// Create a new Device Context
CDC* tDC=(CPaintDC*)new CDC;
// Store existing Framework variables to avoid failing the ASSERT command
tDC->m_hDC=GetDC()->m_hDC;
tDC->m_hAttribDC=GetDC()->m_hAttribDC;
// Set the DC up the same as the original CPaintDC
PrepareDevice(tDC); // SETUP THE VIEWING PORT
tDC->SetWindowExt(windy.width()+200,windy.height()+200);
// translate to click coordinates to logcial coords
tDC->DPtoLP(&VirtualPoint);
// Viewport bottom is minus to accomodate CWindowClass - reverse this
VirtualPoint.y=abs(VirtualPoint.y);
// Free memory for Device Context
delete tDC;
/////////////////////////////////////////////////////////////////////////
I have tried storing the DC as a pointer but because the original is destroyed after painting this (obviusly) causes errors.
I had thought that using GetDC()->DPtoLP(&VirtualPoint) would work but it has no effect (because the windowExt() aren't set)
Cheers