TextOut in OCX writes in container window
Manish -- manish@answer.com Friday, March 28, 1997 Environment: VC++4.2b,VC++5.0 Win95 Hello Everyone. I found an interesting behavior in OCX when I used function TextOut. I created a new OCX using the AppWizard. I modifies the code in the OnDraw function (generated by the AppWizard). I used TextOut to just print a line of text. It works fine, but only for the first time. It writes the line in the bounded rectangle area given to the OCX's. The problem is that if I switch to another application running on the Win95 desktop and come back to the container application with my OCX I find that the line of text is painted in the containers client area rather than the OCX's area (the bounded rectangle). I used the test container testcon32.exe shipped with VC++. In other words the device context seem to point to the container's window rather than the rectangle area given to the OCX. Here is my code : ///////////////////////////////////////////////////////////////////////////// // CTestAX4Ctrl::OnDraw - Drawing function void CTestAX4Ctrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) { pdc->TextOut(10,10,"Hello"); // the only line written by me } Is it a bug ? There is no compile time or run time error. C++C++C++C++C++C++C++C++C++C++C++ C++ C++ C++ Manish Mulchandani C++ C++ C++ C++ Email : manish@answer.com C++ C++ C++ C++C++C++C++C++C++C++C++C++C++C++
Mike Blaszczak -- mikeblas@nwlink.com Sunday, March 30, 1997 [Mini-digest: 2 responses] At 14:53 3/28/97 -0800, Manish wrote: >Environment: VC++4.2b,VC++5.0 Win95 >In other words the device context seem to point to the container's >window rather than the rectangle area given to the OCX. In some containers, in some containment modes, this can be the case. >Here is my code : >///////////////////////////////////////////////////////////////////////////// >// CTestAX4Ctrl::OnDraw - Drawing function > >void CTestAX4Ctrl::OnDraw( > CDC* pdc, const CRect& rcBounds, const CRect& >rcInvalid) >{ > > pdc->TextOut(10,10,"Hello"); // the only line written by me > >} > > >Is it a bug ? There is no compile time or run time error. The bug is all yours: you're completely ignoring the rcBounds you were given. All of your painting needs to be relative to that rectangle. By just blindly painting at (10, 10), you're asking for trouble--and you got it! .B ekiM http://www.nwlink.com/~mikeblas/ These words are my own. I do not speak on behalf of Microsoft. One is too many and a million is not enough. -----From: spal@statestreet.com Manish, There is no bug, however you are missing a small point here. CTestAX4Ctrl::OnDraw () provides a CDC object, which will be mapped to the control's window when the control is active. However, When the control is inactive, the CDC will represent a metafile which the container uses to present a picture of your control. This presentation stuff is done by MFC beautifully. Point is this, in a control you cannot assume that the control's drawing area starts at coordinates (0,0). Sometime CDC is mapped to control's windows, sometime it is simply a metafile DC with different bounding rectangle. Hence, rcBounds CRect parameter is very important in this case, and you MUST use the bounding rectangle rcBounds, whatsoever while drawing operation in the control. If you change your code as: pdc->TextOut(rcBounds.TopLeft ().x+10, rcBounds.TopLeft ().y+10,"Hello"); // the only line written by me then it will be okay. Good luck, Sukhram //-------------------------------------------------------------------- -------------------------------------------- Sukhram Pal State Street Bank & Trust Company, Boston spal@statestreet.com 617.985.1348 (W) //-------------------------------------------------------------------- -------------------------------------------- ---------- From: manish To: mfc-l Subject: TextOut in OCX writes in container window Date: Friday, March 28, 1997 5:53PM Environment: VC++4.2b,VC++5.0 Win95 Hello Everyone. I found an interesting behavior in OCX when I used function TextOut. I created a new OCX using the AppWizard. I modifies the code in the OnDraw function (generated by the AppWizard). I used TextOut to just print a line of text. It works fine, but only for the first time. It writes the line in the bounded rectangle area given to the OCX's. The problem is that if I switch to another application running on the Win95 desktop and come back to the container application with my OCX I find that the line of text is painted in the containers client area rather than the OCX's area (the bounded rectangle). I used the test container testcon32.exe shipped with VC++. In other words the device context seem to point to the container's window rather than the rectangle area given to the OCX. Here is my code : ///////////////////////////////////////////////////////////////////////////// // CTestAX4Ctrl::OnDraw - Drawing function void CTestAX4Ctrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) { pdc->TextOut(10,10,"Hello"); // the only line written by me } Is it a bug ? There is no compile time or run time error. C++C++C++C++C++C++C++C++C++C++C++ C++ C++ C++ Manish Mulchandani C++ C++ C++ C++ Email : manish@answer.com C++ C++ C++ C++C++C++C++C++C++C++C++C++C++C++
Become an MFC-L member | Вернуться в корень Архива |