OnMouseMoveメッセージ応答の問題(ボタンが押されていない)

原因:

  私はもともとMFCを使用して、押せないボタン(マウスがボタンの上に移動するとボタンが離れる)を作成したかったのですが、WM_MOUSEMOVEメッセージを使用して検索します

  マウスがボタンの上にあるときにWM_MOUSEMOVEメッセージが親ウィンドウに送信されない

解決策:

  SetCapture()関数を使用してマウスメッセージをキャプチャする

  setCaptureは、次のマウスイベントをキャプチャします:onmousedown、onmouseup、onclick、ondblclick、onmouseover、およびonmouseout

  キャプチャする必要のあるメッセージは正確にありますが、この機能は少なからずあり、キャプチャ中に他のイベントを実行できないため、時間内に解放する必要があります

  ReleaseCapture()関数を使用して解放する

注:

  SetCapture()関数には、プログラムに管理者権限が必要なようです

void CBiaoBai1Dlg :: OnMouseMove(UINT nFlags、CPoint point)
{ 
	// TODO:メッセージハンドラーコードを追加するか、デフォルト値を呼び出します
	CDialogEx :: OnMouseMove(nFlags、point); 

	//マウスキャプチャを設定します
	SetCapture(); 

	/ /同意しないボタンの位置を取得します(ディスプレイの左上隅を
	基準CRect rect_disagree; 
	m_Disagree_Button.GetWindowRect(&rect_disagree); 
	//同意ボタンの位置を取得します
	CRect rect_agree; 
	m_agree.GetWindowRect(&rect_agree); 
	//考慮されるボタンの位置を取得
	CRect rect 
	m_think.GetWindowRect(&rect_think); 

	//不一致ボタンの幅と
	高さを取得int height = rect_disagree.Height(); 
	int width = rect_disagree.Width(); 

	//クライアント座標を画面座標に変換
	ClientToScreen(&point); 

	/ /マウスが同意ボタンと検討ボタンの上にあるかどうかを判断する 
	//それらの上にある場合は、マウスキャプチャを解放します
	if(rect_agree.PtInRect(point)|| rect_think.PtInRect(point))
	{ 
		//マウスキャプチャを解放する
		ReleaseCapture(); 
	} 

	rect_disagree.NormalizeRect(); 
	BOOL ret = PtInRect(rect_disagree、point); 
	if(ret)
	{ 
		/ /クライアントサイズを
		取得CRect rect; 
		GetClientRect(&rect); 
		//クライアントでのランダムな動きの範囲を決定
		//同意ボタンと検討ボタンに
		当てはまる場合、再びランダムになるint re_x; 
		int re_y; 
		CPoint point_youxhang; 
		CPoint point_youshang; 
		CPoint point_zuoxia; 
		do 
		{ 
			re_x = rand()%(rect.right-width); 
			re_y = rand()%(rect.bottom-height); 
			point.SetPoint(re_x、re_y); 
			//クライアント座標を画面に変換するコーディネート
			ClientToScreen(&point); 
			point_youxia.SetPoint(point.x + width、point.y + height); 
			point_youshang.SetPoint(point.x + width、point.y); 
			point_zuoxia.SetPoint(point.x、point.y + height); 

		}一方(rect_agree.PtInRect(点)|| rect_think.PtInRect(点)
			|| rect_agree.PtInRect(point_youxia)|| rect_think.PtInRect(point_youxia)
			|| rect_agree.PtInRect(point_youshang)|| rect_think.PtInRect(point_youshang)
			| | rect_agree.PtInRect(point_zuoxia)|| rect_think.PtInRect(point_zuoxia)); 
		rect.SetRect(re_x、re_y、re_x + width、re_y + height); 
		m_Disagree_Button.MoveWindow(&rect、TRUE);	
	} 
}

  

 

おすすめ

転載: www.cnblogs.com/ndyxb/p/12727938.html