Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Meet and Greet (http://www.go4expert.com/community/meet-and-greet/)
-   -   how select the text In MFC (http://www.go4expert.com/community/select-text-mfc-t25064/)

sarfarazfarru10@gmai 25Feb2011 12:16

how select the text In MFC
 
hi
i am very new to MFC. trying to select the particular text of the client area.i have use
OnLButtonDown and OnLButtonup had two points .i am not able change background color of particular text.provid me some example .....
i am not using the editview here is 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);
}



All times are GMT +5.5. The time now is 12:59.