Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnLButtonDown() question

Status
Not open for further replies.

nbgoku

Programmer
May 25, 2004
108
US
Code:
void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	if(nFlags == MK_LBUTTON)
	{
		MessageBox("hi");
	}
	CDialog::OnLButtonUp(nFlags, point);
}

works beautifully, my question is what coding should i use so that the message box appears only if the left click is on a Static Text( ex: IDC_STATIC3) ... i understand how to detect the location of the click using point, but can i also use the point for detecting the actualing ID being clicked on, not just the point on the screen?
 
According to MSDN's page on WM_LBUTTONDOWN it doesn't appear so... can you put the code to handle this inside the static window's procedure? (I don't use MFC) Otherwise you can perhaps try WindowFromPoint since you can get the x/y.
 
Use something like the following:

Code:
[green]//in your header[/green]
CStatic yourStaticControl_IDC_STATIC3; [green]// you need to add a control variable to your static control[/green]

void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
    CRect rect;
    yourStaticControl_IDC_STATIC3.GetWindowRect ( &rect );
    
    [green]// check point is in control rect[/green]
    if ( ( point.x > rect.left ) && ( point.x < rect.right ) && ( point.y > rect.bottom ) && ( point.y < rect.top ) )
    {
      MessageBox ( "Over Static Control" );
    }
    [green]// put this is to check your left button down function is working[/green]
    else MessageBox ( "Not over Static" );
}

Good luck



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top