VC++ SDI text

Started by
2 comments, last by TwisteR 22 years, 9 months ago
Hi, i was wondering how i would go about writing text on the screen whe the user clicks there. I am using Microsotf Visual C++ 6.0 and have made a Single-document-interface and need to place my name where the user clicks on the screen. i am sorta confused...please help. ----------------------------- -------Mitch Mulholland------ ----A.K.A.= TwisteR---------- -----------------------------
------------------------------------Mitch Mulholland----------A.K.A.= TwisteR---------------------------------------
Advertisement
I assume you are using MFC. In your CView class, keep some member variables like x, y and clickflag. Initialize clickflag to false in your CView constructor.

Then use ClassWizard to create a handler for WM_LBUTTONDOWN.

Now in your OnLButtonDown method do something like this:

  void CNameClickView::OnLButtonDown(UINT nFlags, CPoint point) {	CView::OnLButtonDown(nFlags, point); //point is the point within your view area that the user clicked the mouse	x = point.x;	y = point.y;// we have finally clicked on the view so set our flag	clickflag = true;// Inalidate the view area so that it will be redrawn next OnDraw	Invalidate();//Mark the window as updated	UpdateWindow();}  


Finally, in your OnDraw you can do this:

  void CNameClickView::OnDraw(CDC* pDC){// standard OnDraw stuff.	CTestclickDoc* pDoc = GetDocument();	ASSERT_VALID(pDoc);// if the user has clicked on the view, draw his name at the mouse pointer	if (clickflag)	{                char* yourname = "Your Name";//pDC is your device context, which you should use for all your drawing with MFC		pDC->TextOut( x, y, yourname, strlen(yourname) );	}}  


and that should about cover it

Hope this helps

Seeya,
Krippy
thank you sooooooooooooooooooo soooooooooooooooooo sooooooooooooooooooooo soooooooooooooooo Much!!!

it worked absolutely perfectly. I would have been lost with out it...Thank you again!!!

-----------------------------
-------Mitch Mulholland------
----A.K.A.= TwisteR----------
-----------------------------
------------------------------------Mitch Mulholland----------A.K.A.= TwisteR---------------------------------------
Anytime

This topic is closed to new replies.

Advertisement