zoukankan
html css js c++ java
【MFC】 ClientToScreen 和ScreenToClient 【转】
ClientToScreen( )是把窗口坐标转换为屏幕坐标
ScreenToClient( )是把屏幕坐标转换为窗口坐标
屏幕坐标是相对于屏幕左上角的,而窗口坐标是相对于窗口用户区左上角的
VC下,有些函数使用窗口坐标,有些使用屏幕坐标,使用时要分清。
一个窗体分为两部分:系统区和客户区
象标题和菜单之类的是系统区,由系统来控制,客户区就是你的地盘喽!!!
Width, Height 是指整体的,ClientWidth, ClientHeight是指客户区的,两者相减就是
系统区的啦!!!
ClientToScreen是把坐标从当前窗体转化成全屏幕的!!!
ScreenToClient是把屏幕坐标转化成相对当前窗体的坐标!!!!
bool
m_bIsLButtonDawn
=
false
;
void
CDrawDlg::OnMouseMove(UINT nFlags, CPoint point)
{
//
TODO: Add your message handler code here and/or call default
CWnd
*
pwnd
=
GetDlgItem(IDC_EDIT1);
CDC
*
pdc
=
pwnd
->
GetDC();
CRect rect;
this
->
ClientToScreen(
&
point);
pwnd
->
ScreenToClient(
&
point);
pwnd
->
GetClientRect(
&
rect);
//
HCURSOR hcur=::LoadCursorFromFile("pen.cur");
//
SetClassLong(GetSafeHwnd(),GCL_HCURSOR,(LONG)hcur);
//
CPen pen(PS_INSIDEFRAME,-1,RGB(255,255,255));
//
CPen* olePen=pdc->SelectObject(&pen);
if
(rect.PtInRect(point)
&&
m_bIsLButtonDawn )
{
pdc
->
DPtoLP(
&
m_fp);
pdc
->
MoveTo(m_fp);
pdc
->
DPtoLP(
&
point);
pdc
->
LineTo(point);
}
m_fp
=
point;
//
pdc->SelectObject(olePen);
ReleaseDC(pdc);
CDialog::OnMouseMove(nFlags, point);
}
void
CDrawDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bIsLButtonDawn
=
false
;
//
TODO: Add your message handler code here and/or call default
/**/
/**/
/**/
/*
CWnd *pwnd=GetDlgItem(IDC_EDIT1);
CDC *pdc=pwnd->GetDC();
CRect rect;
this->ClientToScreen(&point);
pwnd->ScreenToClient(&point);
pwnd->GetClientRect(&rect);
if(rect.PtInRect(point))
{
pdc->DPtoLP(&m_fp);
pdc->MoveTo(m_fp);
pdc->DPtoLP(&point);
pdc->LineTo(point);
}
ReleaseDC(pdc);
*/
CDialog::OnLButtonUp(nFlags, point);
}
void
CDrawDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
//
TODO: Add your message handler code here and/or call default
CWnd
*
pwnd
=
GetDlgItem(IDC_EDIT1);
CDC
*
pDC
=
pwnd
->
GetDC();
CRect rect;
this
->
ClientToScreen(
&
point);
pwnd
->
ScreenToClient(
&
point);
pwnd
->
GetClientRect(
&
rect);
if
(rect.PtInRect(point))
{
m_fp.x
=
point.x;
m_fp.y
=
point.y;
}
ReleaseDC(pDC);
m_bIsLButtonDawn
=
true
;
CDialog::OnLButtonDown(nFlags, point);
}
CTreeCtrl
*
pTree
=
(CTreeCtrl
*
)pDropWnd;
//
pTree->ShowWindow(SW_HIDE);
CScheduleDlg
*
pDlg
=
(CScheduleDlg
*
)AfxGetMainWnd();
ClientToScreen(
&
pt2);
pTree
->
ScreenToClient(
&
pt2);
CString strText;
strText.Format(
"
%d - %d
"
, pt2.x, pt2.y);
pDlg
->
SetWindowText(strText);
//
CTreeCtrl *pTree = & (pDlg->m_tcMyWorks);
HTREEITEM hItem
=
pTree
->
HitTest(pt2,
&
flags);
//
鼠标经过时高亮显示
CImageList::DragShowNolock(
false
);
//
避免鼠标经过时留下难看的痕迹
if
(hItem
/**/
/*
&& (flags & TVHT_ONITEM) || (flags & TVHT_ONITEMRIGHT)
*/
)
{
//
m_tc.SetFocus();
//
m_tc.SelectItem(hItem);
pTree
->
SelectDropTarget( hItem );
//
m_tc.Invalidate();
//
flag tree needs to be redrawn
//
m_tc.UpdateWindow();
//
redraw tree
//
AfxMessageBox(m_tc.GetItemText(hItem));
}
CImageList::DragShowNolock(
true
);
查看全文
相关阅读:
简单计算器
dfs(通过控制点的编号来得出每个点的坐标)
dfs(通过控制点的编号来得出每个点的坐标)
神奇的 组合数
神奇的 组合数
B. Light It Up
B. Light It Up
Python 字符串
Python radians() 函数
Python degrees() 函数
原文地址:https://www.cnblogs.com/shengshuai/p/1450668.html
最新文章
Java实现 LeetCode 748 最短完整词(字母拆分+暴力)
Java实现 LeetCode 748 最短完整词(字母拆分+暴力)
Java实现 LeetCode 748 最短完整词(字母拆分+暴力)
Java实现 LeetCode 747 至少是其他数字两倍的最大数(暴力)
Java实现 LeetCode 747 至少是其他数字两倍的最大数(暴力)
Java实现 LeetCode 747 至少是其他数字两倍的最大数(暴力)
Java实现 LeetCode 746 使用最小花费爬楼梯(递推)
Java实现 LeetCode 746 使用最小花费爬楼梯(递推)
134. Gas Station
128. Longest Consecutive Sequence
热门文章
116. Populating Next Right Pointers in Each Node
125. Valid Palindrome
122. Best Time to Buy and Sell Stock II
108. Convert Sorted Array to Binary Search Tree
111. Minimum Depth of Binary Tree
105. Construct Binary Tree from Preorder and Inorder Traversal
104. Maximum Depth of Binary Tree
堆的建立
堆的建立
简单计算器
Copyright © 2011-2022 走看看