|
thanks ....
but i am not using any one CDialog, OnDraw and doc/view architecture.
i am using app class & mainframe in SD i removed all other classes and what ever text is there i had display in paint only CMainFrame::OnPaint().............
trying to develop the editor kind of application without using editview ..
i have drawn the rectangle mouse event i want change the color what ever text comes under the rectangle should not hide text that is my problem .....
|
|
|
|
|
I understand, but I don't see the difference really. You can still use the code I gave you, just put it in CMainFrame::OnPaint() instead. Unless the text in there is a bitmap image, you can should be able to query the window for its text.
|
|
|
|
|
i tried but i confused where to write code of your ......
once you check my code
CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){
HANDLE hfile;
hfile=CreateFile(_T("\\\\.\\C:"),GENERIC_READ,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hfile == INVALID_HANDLE_VALUE)
{
MessageBox(_T("Fail to open the drive"),_T(" "),MB_OK | MB_ICONERROR);
return -1;
}
m_lpData = new BYTE[1024];
DWORD dwNumberofByteToRead =0;
if(!ReadFile(hfile,m_lpData,1024,&dwNumberofByteToRead,NULL))
{
MessageBox(_T("Fail to read the drive"),_T(" "),MB_OK | MB_ICONERROR);
return -2
}
and onpaintcode:
{
CPaintDC dc(this); // device context for painting
CString szFormatted;
CRect rect;
CDC m_pDC;
CBrush m_Brush,m_brush1;
GetClientRect(&rect);
m_pDC.CreateCompatibleDC(&dc);
m_bitmap.CreateBitmap (rect.Width(), rect.Height(),0,0,NULL);
m_pDC.SelectObject(&m_bitmap);
m_Brush.CreateSolidBrush(RGB(255,255,255));
m_pDC.SelectObject(&m_Brush);
m_pDC.FillRect(rect,&m_Brush);
TRACE("\n Left: %d, Top: %d Right: %d Bottom: %d",rect.left, rect.top, rect.right, rect.bottom);
//TRACE("\n Start Line: %d End Line: %d", rect.top /cyChar, rect.bottom / cyChar);
m_pDC.SelectObject(GetStockObject(OEM_FIXED_FONT ));
memset (&si, 0, sizeof (SCROLLINFO));
si.cbSize = sizeof (SCROLLINFO);
si.fMask = SIF_POS | SIF_PAGE |SIF_RANGE;
GetScrollInfo(SB_VERT, &si, SIF_POS | SIF_PAGE | SIF_RANGE);
m_nVScrollBarPos = si.nPos;
GetScrollInfo(SB_HORZ, &si, SIF_POS | SIF_PAGE |SIF_RANGE);
m_nHScrollBarPos = si.nPos;
int Start = rect.top / m_cyChar;
int End = rect.bottom / m_cyChar;
TRACE ("\nStart: %u, End: %u YCord: %d", Start, End);
for(int i = Start; i<= End; i++)
{
GetFormattedData(m_lpData, (i + m_nVScrollBarPos )*BYTE_OFFSET, szFormatted);
m_pDC.TextOut((1 - m_nHScrollBarPos) * m_cxChar , i * m_cyChar, szFormatted);
}
m_bitmap.DeleteObject();
dc.BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&m_pDC,rect.left,rect.top,SRCCOPY);
CPen pen;
dc.SelectObject(GetStockObject(NULL_BRUSH));
dc.Rectangle(start_pt.x, start_pt.y, end_pt.x, end_pt.y);
rect.SetRect(start_pt,end_pt);
ReleaseDC(&m_pDC);
}
|
|
|
|
|
You should put it where the for-loop is.
Also, you're deleting the m_bitmap object before you have unselected it from the DC, and before the BitBlt call. Delete it after BitBlt, and after you have unselected it (using SelectObject with the result you got from the first call when you selected the bitmap into the DC).
Is there a good reason for not using an edit control?
Although the Crystal Edit - syntax coloring text editor[^] article isn't exactly what you need, you might get some ideas there.
|
|
|
|
|
|
Which part is not working? The code snippet I posted above works in my sample application for drawing selections.
Also, if you're dealing with non-client area painting, are you doing it in the OnNcPaint[^] handler?
|
|
|
|
|
i am dealing with client area now i have created the rectangular region by the points which i had from Lbuttondown and Lbuttonup. and then i inverted the region which gives the color but the color wont remain when i scroll the text .............
|
|
|
|
|
Maybe you could respond to the scroll messages from your window, and save the offset to use in the painting routine?
|
|
|
|
|
How to use PostMessage function to Close the Recorder of MS-Window-XP
I'v tried following codes, but they do not work.
::PostMessage(hWnd, WM_SYSCOMMAND, ........
or
::PostMessage(hWmd, WM_CLOSE, 0, 0);
or
::PostMessage(hWnd, WM_DESTROY, 0, 0);
Reply·Email·View Thread·Link·Bookmark | Edit·Delete
|
|
|
|
|
WM_CLOSE is the best way. Most applications do some confirmations like "do you want to save or not?" before closing. To forcefully close the app without popping up these kind of messages, try WM_DESTROY directly.
|
|
|
|
|
The window messages you send are correct, so the problem should be something else. Is your window handle hWnd correct? How did you obtain it?
modified 13-Sep-18 21:01pm.
|
|
|
|
|
cerne1840@yahoo.com wrote: I'v tried following codes, but they do not work.
I didn't notice it. As Thaddeus Jones already told, the problem can be of the window handle.
|
|
|
|
|
when a combo-box closed up (with drop-down or drop-down-list style), I need to get its outside height.
GetWindowRect() works normally, but, when its parent window is in min (icon) state then to restore or max state, the function doesn't work - gets rect including drop-down part.
I use this way:
int iItemH=MyComboBox.GetItemHeight(-1);
int iFrmH=::GetSystemMetrics(SM_CYEDGE);
int iCmbH=iItemH+iFrmH*2+2;
The iCmbH is what I need, but code looks no good,do you have a trusted and better idea to get its height?
|
|
|
|
|
|
Thanks, but the function is not working on Win2K - our users may use win2k.
|
|
|
|
|
i did'n got what your saying
|
|
|
|
|
GetComboBoxInfo[^] does essentially the same and is supported by Windows 2000. I can't find the OS requirements of CComboBox::GetComboBoxInfo[^] but if you are sure it isn't supported in Windows 2000, you could give that one a shot.
modified on Thursday, February 10, 2011 11:29 AM
modified 13-Sep-18 21:01pm.
|
|
|
|
|
i do a HMI software, need on canvas into a text, the text can be through user operations to change size ,
It required text font will adapt to the text frame's size change, to fill the whole text frame's purpose
OnSize
{
CString title="我是中国人";
CRect rect=GetRect();
int len=title.GetLength();
m_logFont.lfHeight=LONG(rect.bottom-rect.top);//LOGFONT m_logFont;
m_logFont.lfWidth=LONG(rect.right-rect.left)//len;
}
OnDraw()
{
CFont Font;
Font.CreateFontIndirect(&m_logFont);
dc->SelectObject(Font);
dc->DrawText( GetTitle(), GetRect(), DT_WORDBREAK );
}
When drag rectangle sometimes can be complete shows the whole string, sometimes only display several characters, behind of appears not to come out, high is no problem,width sometimes is small,why???
|
|
|
|
|
Cannot you use DrawRect with DT_CALCRECT format specifier (see MSDN[^]) to obtain the correct size for the rectangle?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Can say the concrete spot ???
|
|
|
|
|
Use DrawText with the DT_CALCRECT format flag to just obtain the rectangle dimensions (the [in,out] lpRect parameter) then use again the function to actually write the string in the properly sized rectangle.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks you, but, when the rectangle increases toward right ,rect.left is Fixed ,rect.right is changed,it's good, but increases toward left time, the rect.left and rect.right has had the change,why???
|
|
|
|
|
You could try to draw in a calculated (CDC::GeTextExtent(..) ) rectangle with a some fixed font and...
...in an applied zooming transformation (CDC::SetWorldTransform(..) ) to the context.
So you can stretch the rectangle (with its content) like a gummi bear...
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
Hi guys,
I wanted to find out whether one can set up a test fixture to apply all tests to the same instance of the fixture object ?
Let's us take for an example the following Testclass implemented.
class SampleTest:: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( SampleTest);
CPPUNIT_TEST( doTest1);
CPPUNIT_TEST( doTest2);
public:
void doTest1();
void doTest2();
}
For each test in a test fixture, CppUnit creates a new instance of SampleTest class.
Thus for fixture SampleTest containing tests doTest1() and doTest2(), CppUnit will
create 2 instances of SampleTest class and calls doTest1 on the first instance, doTest2 on the second instance.
I would like to know if it is possible to create only one instance of SampleTest class that can call both the test functions?
Thanks in advance.
|
|
|
|
|
cydd wrote: For each test in a test fixture, CppUnit creates a new instance of SampleTest class.
Correct, but it is not just before the test case function is called. The cpp unit is designed to collect all the test cases initially (this happens with macro CPPUNIT_TEST - see its definition), and map them against the an instance created for them. This is to make each test case purely independent. You have to set all the possible preconditions in each test case method in such a way that the testing will be meaningful for the context.
|
|
|
|
|