CWnd *pWnd=GetDlgItem(IDC_STATIC_T);
pWnd->Invalidate();
pWnd->UpdateWindow();
CDC *pDC = pWnd->GetDC();
pDC->Rectangle(0, 0,580,660);//矩形外框
CPen *pPenRed = new CPen(); //創建畫筆物件
CGdiObject *pOldPen = pDC ->SelectObject(pPenRed); //選中當前紅色畫筆,并保存以前的畫筆
pDC ->MoveTo(40, 20); //繪制坐標軸
pDC ->LineTo(40, 620); //豎起軸
pDC ->LineTo(540,620); //水平軸
uj5u.com熱心網友回復:
獲得當前滑鼠位置,并判斷是否在坐標軸上就行啦。在的話就顯示,沒有就不顯示啊!uj5u.com熱心網友回復:
別忘了洗掉畫筆指標……uj5u.com熱心網友回復:
您好,我現在滑鼠在這個坐標系中可以輸出坐標,可是我把坐標系移動一個位置,坐標就變了,我怎么把坐標轉換成相對于這個控制元件的坐標uj5u.com熱心網友回復:
"可是我把坐標系移動一個位置,坐標就變了"記住坐標系在客戶區的相對位置
uj5u.com熱心網友回復:
void CXqDlg::OnMouseMove(UINT nFlags, CPoint point){
}
我想問下這個OnMouseMove里面的point坐標,是相對于哪個的,我怎么把這個坐標轉換到我這個坐標系里面來
uj5u.com熱心網友回復:
計算前后兩個坐標系的相對位置~
uj5u.com熱心網友回復:
pointSpecifies the x- and y-coordinate of the cursor. These coordinates are always relative to the upper-left corner of the window.
uj5u.com熱心網友回復:
These coordinates are always relative to the upper-left corner of the window.uj5u.com熱心網友回復:
Coordinate Space and Transformation FunctionsThe following functions are used with coordinate spaces and transformations.
ClientToScreen
CombineTransform
DPtoLP
GetCurrentPositionEx
GetGraphicsMode
GetMapMode
GetViewportExtEx
GetViewportOrgEx
GetWindowExtEx
GetWindowOrgEx
GetWorldTransform
LPtoDP
MapWindowPoints
ModifyWorldTransform
OffsetViewportOrgEx
OffsetWindowOrgEx
ScaleViewportExtEx
ScaleWindowExtEx
ScreenToClient
SetGraphicsMode
SetMapMode
SetViewportExtEx
SetViewportOrgEx
SetWindowExtEx
SetWindowOrgEx
SetWorldTransform
uj5u.com熱心網友回復:
void CXqTestDlg::OnMouseMove(UINT nFlags, CPoint point){
CRect rct;
GetDlgItem(IDC_STATIC_T)->GetWindowRect(rct); //GetWindowRect函式是獲取控制元件坐標 相對于螢屏左上角
rct.TopLeft().x+=110;
rct.TopLeft().y+=30;
rct.BottomRight().x=rct.TopLeft().x+500;
rct.BottomRight().y=rct.TopLeft().y+600;
CPoint pt;
GetCursorPos(&pt); //GetCursorPos獲取游標在螢屏坐標中的位置
if(PtInRect(&rct,pt)) //PtInRect函式是Point是否在Rect內(點是否在矩形區域內)
{
HCURSOR hCur = LoadCursor(NULL,IDC_CROSS);
::SetCursor(hCur);
float zx,zy;
zx=(300.0/497.0)*point.x-588.83;
zy=(-600.0/598.0)*point.y+608.026;
m_x.Format("%.2f",zx);
m_y.Format("%.2f",zy);
UpdateData(FALSE);
}
else
{
HCURSOR hCur = LoadCursor(NULL,IDC_ARROW);
::SetCursor(hCur);
}
CDialog::OnMouseMove(nFlags, point);
}
這是我的OnMouseMove陳述句,在我的電腦上可以把坐標輸出的很準,可是同樣的程式換了臺電腦就不行了,坐標輸出的右亂了
uj5u.com熱心網友回復:
rct.TopLeft().x+=110;rct.TopLeft().y+=30;
rct.BottomRight().x=rct.TopLeft().x+500;
rct.BottomRight().y=rct.TopLeft().y+600;
zx=(300.0/497.0)*point.x-588.83;
zy=(-600.0/598.0)*point.y+608.026;
這么多立即數 ,與 電腦 有關 !
uj5u.com熱心網友回復:
不如 IDC_STATIC_T 派生為 你的 Staticuj5u.com熱心網友回復:
@ schlafenhamster 您好,接觸沒多久,你說的“不如 IDC_STATIC_T 派生為 你的 Static”“ 沒有理解,能指個方向怎么弄么uj5u.com熱心網友回復:
1 加一個新類class CMyStatic : public CStatic
2. IDC_STATIC_T 的關聯 改為 CMyStatic
uj5u.com熱心網友回復:
應該是捕獲位置訊息,然后獲取坐標系原點的坐標,還要確定每個單位長度多少個像素點吧!具體怎么實作沒想清楚!!轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/131311.html
標籤:界面
上一篇:是一個關于輸入法的問題,我弄了很久了,希望大家能幫助我
下一篇:MFC 對話框邊界問題
