国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
vc編程如何實(shí)現(xiàn)'十字線隨光標(biāo)移動(dòng)'
C/C++ code
.h頭文件 

#pragma once

class CCrossDrawer
{
public:
CCrossDrawer(void);
~CCrossDrawer(void);

void Restart();

void OnMouseMove(UINT nFlag, CPoint pt, CView* pView);
void Render(CDC* pDC);

void AddLine(CString strText);
void ClearTexts();

protected:
CPoint m_ptPre; // 鼠標(biāo)點(diǎn)
CRect m_rectClient; // 客戶區(qū)區(qū)域矩形

UINT m_nTextHeight; // 文字總高度
UINT m_nTextWidth; // 文字總寬度
CPoint m_ptTextPos; // 文字的輸出位置

public:
COLORREF m_clrLine; // 十字線顏色
int m_nDstX; // 文字邊框到鼠標(biāo)的橫向距離
int m_nDstY; // 文字邊框到鼠標(biāo)的縱向距離
int m_nExtText; // 文字到文字邊框的距離
std::vector <CString> m_Texts; // 文字提示信息
};





C/C++ code
.cpp實(shí)現(xiàn)文件#include "StdAfx.h"#include ".\crossdrawer.h"CCrossDrawer::CCrossDrawer(void):m_ptPre(-999,-999),m_ptTextPos(-999,-999){ m_clrLine = RGB(0,0,0); m_nDstX = 8; m_nDstY = 16; m_nExtText = 3; m_nTextHeight = m_nTextWidth = 0; CString strInit = _T("文字提示信息......第01行"); m_Texts.push_back(strInit); strInit.Format(_T("文字提示信息......第02行")); m_Texts.push_back(strInit); strInit.Format(_T("文字提示信息......第XXX行")); m_Texts.push_back(strInit);}CCrossDrawer::~CCrossDrawer(void){}void CCrossDrawer::OnMouseMove( UINT nFlag, CPoint pt, CView* pView ){ pView->GetClientRect(&m_rectClient); CClientDC dc(pView); pView->OnPrepareDC(&dc); dc.DPtoLP(&m_rectClient); m_rectClient.NormalizeRect(); m_ptPre = pt; dc.DPtoLP(&m_ptPre); // 計(jì)算文字的寬高 // 找到最長(zhǎng)字符串的下標(biāo) int nMaxIndex = 0; int nLines = m_Texts.size(); for (UINT i = 0; i < nLines; i++) { if (m_Texts[nMaxIndex].GetLength() < m_Texts[i].GetLength()) nMaxIndex = i; } // 選入字體 LOGFONT logfont = { -18,0,0,0,400,0,0,0,134,3,2,1,2, _T("宋體") }; //logfont.lfHeight = Sim2DHelper::FontSizeToLP(&dc, logfont.lfHeight); CSize szHeight(0, logfont.lfHeight); dc.DPtoLP(&szHeight); logfont.lfHeight = szHeight.cy; CFont font; font.CreateFontIndirect(&logfont); CFont* pOldFont = dc.SelectObject(&font); CSize szTextExtent; if (!m_Texts.empty()) szTextExtent = dc.GetTextExtent(m_Texts[nMaxIndex]); else szTextExtent = dc.GetTextExtent(_T("")); m_nTextWidth = szTextExtent.cx; m_nTextHeight = szTextExtent.cy*nLines; // 計(jì)算文字輸出位置 CSize sizeOffset(m_nDstX, m_nDstY); dc.DPtoLP(&sizeOffset); sizeOffset.cy *= -1; m_ptTextPos.x = m_ptPre.x + sizeOffset.cx; m_ptTextPos.y = m_ptTextPos.y = m_ptPre.y + sizeOffset.cy; if ( (LONG)(m_ptPre.x + sizeOffset.cx + m_nTextWidth) >= m_rectClient.right) { m_ptTextPos.x = m_ptPre.x - sizeOffset.cx - m_nTextWidth; } if ((LONG)(m_ptPre.x - sizeOffset.cx - m_nTextWidth) <= m_rectClient.left ) { m_ptTextPos.x = m_ptPre.x + sizeOffset.cx; } if ((LONG)(m_ptPre.y + sizeOffset.cy - m_nTextHeight) <= m_rectClient.top) { m_ptTextPos.y = m_ptPre.y - sizeOffset.cy + m_nTextHeight; } if ((LONG)(m_ptPre.y - sizeOffset.cy + m_nTextHeight) >= m_rectClient.bottom) { m_ptTextPos.y = m_ptPre.y + sizeOffset.cy; } pView->Invalidate(FALSE);}void CCrossDrawer::Restart(){ m_ptPre.SetPoint(-999,-999);}void CCrossDrawer::Render( CDC* pDC ){ if (m_ptPre.x != -999) { CPen pen(PS_DOT, 0, m_clrLine); CPen* pOldpen = pDC->SelectObject(&pen); pDC->MoveTo(CPoint(m_ptPre.x, m_rectClient.top)); pDC->LineTo(CPoint(m_ptPre.x, m_rectClient.bottom)); pDC->MoveTo(CPoint(m_rectClient.left, m_ptPre.y)); pDC->LineTo(CPoint(m_rectClient.right, m_ptPre.y)); pDC->SelectObject(pOldpen); if (!m_Texts.empty()) { // 以下繪制文字提示框 //// 計(jì)算文字左上角 //CSize sizeOffset(m_nDstX, m_nDstY); //pDC->DPtoLP(&sizeOffset); sizeOffset.cy *= -1; //CPoint m_ptTextPos = m_ptPre + sizeOffset; // 計(jì)算文本矩形框并繪制 // 找到最長(zhǎng)字符串的下標(biāo) int nMaxIndex = 0; int nLines = m_Texts.size(); for (UINT i = 0; i < nLines; i++) { if (m_Texts[nMaxIndex].GetLength() < m_Texts[i].GetLength()) nMaxIndex = i; } // 選入字體 LOGFONT logfont = { -13,0,0,0,400,0,0,0,134,3,2,1,2, _T("宋體") }; //logfont.lfHeight = Sim2DHelper::FontSizeToLP(pDC, logfont.lfHeight); CSize szHeight(0, logfont.lfHeight); pDC->DPtoLP(&szHeight); logfont.lfHeight = szHeight.cy; CFont font; font.CreateFontIndirect(&logfont); CFont* pOldFont = pDC->SelectObject(&font); // 計(jì)算矩形 CSize szTextExtent = pDC->GetTextExtent(m_Texts[nMaxIndex]); CRect rtTexts(m_ptTextPos.x, m_ptTextPos.y, m_ptTextPos.x + szTextExtent.cx, m_ptTextPos.y - szTextExtent.cy*nLines); rtTexts.NormalizeRect(); CSize szDstText(m_nExtText, m_nExtText); pDC->DPtoLP(&szDstText); rtTexts.InflateRect(szDstText); CBrush brh(RGB(238,245,201)); CBrush* pOldBrh = pDC->SelectObject(&brh); pDC->Rectangle(rtTexts); pDC->SelectObject(pOldBrh); // 繪制文字信息 int nOldBkMode = pDC->SetBkMode(TRANSPARENT); for (UINT i = 0; i < nLines; i++) { pDC->TextOut(m_ptTextPos.x, m_ptTextPos.y - i*szTextExtent.cy, m_Texts[i]); } pDC->SetBkMode(nOldBkMode); pDC->SelectObject(pOldFont); } }}void CCrossDrawer::AddLine( CString strText ){ if (strText.GetLength() < 4) return; m_Texts.push_back(strText);}void CCrossDrawer::ClearTexts(){ m_Texts.clear();}
使用方法:
void CXXXXView::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_bShowCross)
{
m_CrossDrawer.OnMouseMove(nFlags, point, this);
return;
}
}

void CXXXView::OnDraw(CDC* pDC)
{
  m_CrossDrawer.Render(pDC);
}


=================================================

添加onMouseMove事件
然后在里面添加代碼
[code=C/C++][/ShowCursor(FALSE);
Invalidate();
UpdateWindow();
CDC* pDC = GetDC();
pDC->MoveTo(point.x-m_Halflength,point.y);
pDC->LineTo(point.x+m_Halflength,point.y);
pDC->MoveTo(point.x,point.y-m_Halflength);
pDC->LineTo(point.x,point.y+m_Halflength);
ReleaseDC(pDC);]

其中m_Halflength為十字線的半長(zhǎng)度,如果嫌閃爍的話就用內(nèi)存DC


=================================================

View類中添加一成員變量CPoint m_PtMove;
構(gòu)造函數(shù)中初始化m_PtMove=CPoint(-1,-1);
OnMouseMove中處理消息
C/C++ code
CRect rect; GetClientRect(&rect); CClientDC dc(this); //翻轉(zhuǎn)顏色 dc.SetROP2(R2_NOT); //擦除原來(lái)的線 dc.MoveTo(m_ptTemp.x,rect.top); dc.LineTo(m_ptTemp.x,rect.bottom); dc.MoveTo(rect.left,m_ptTemp.y); dc.LineTo(rect.right,m_ptTemp.y); //繪制現(xiàn)在的線 dc.MoveTo(point.x,rect.top); dc.LineTo(point.x,rect.bottom); dc.MoveTo(rect.left,point.y); dc.LineTo(rect.right,point.y); m_ptTemp=point; CView::OnMouseMove(nFlags, point);
(###) 
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
VC/MFC如何設(shè)置對(duì)話框背景顏色_paul的夢(mèng)想天堂
編程中國(guó) - 積累的VC編程小技巧之按鈕
(74條消息) MFC使用 CImage貼圖失真
VC防止窗口和控件閃爍的方法
進(jìn)度條相關(guān)
深入淺出 CPropertySheet
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服