Margin like MSWord in CView
-
Hi, I want to have margins like MSWord in my CView, i.e there should be Grey area around the document , in which we cannot type anything. Can someone tell me how it can be done. Thanks Sansky:-D God is Good, all the Time. All the Time, God is Good.
-
Hi, I want to have margins like MSWord in my CView, i.e there should be Grey area around the document , in which we cannot type anything. Can someone tell me how it can be done. Thanks Sansky:-D God is Good, all the Time. All the Time, God is Good.
-
How about
CBrush* pBrush = CDC::GetHalftoneBrush();
CBrush* pBrushOld = pDC->SelectObject(pBrush);
CRect rc;
GetClientRect(&rc);
pDC->PatBlt(rc.left, rc.top, rc.Width(), rc.Height(), PATCOPY);pDC->SelectObject(pBrushOld);
in your view's OnEraseBkGnd()?
Hi, Thanks for the Reply, Actually how it should be is , The user has to be restricted to part of CView, he cannot type anything in the margin. Example MSWord, or Print Preview Thanks Sansky :-D God is Good, all the Time. All the Time, God is Good.
-
Hi, Thanks for the Reply, Actually how it should be is , The user has to be restricted to part of CView, he cannot type anything in the margin. Example MSWord, or Print Preview Thanks Sansky :-D God is Good, all the Time. All the Time, God is Good.
The easisest way to make this work would be to overide your frame class and position the view X pixels to the left of the frame left. Then, in your frame class (OnPaint), paint the left area the color your want. In its simplest form it would look something like:
BOOL CMyFrame::OnCreateClient(bla.bla.bla)
{
if (!CBaseFrameClass::OnCreateClient(bla.bla.bla))
return FALSE;PostMessage(WM_SIZE);
}BOOL CMyFrame::OnSize(bla.bla.bla)
{
if (m_pViewActive)
{
CRect ClientRect;
GetClientRect(ClientRect);m\_pViewActive->SetWindowPos(NULL, \[margin-width\], 0, ClientRect.Widht()-\[margin-width\], ClientRect.Height(), 0);
}
}void CMyFrame::OnPaint()
{
CPaintDC dc(this);
CRect ClientRect;
GetClientRect(ClientRect);dc.FillSolidRect(0,
0, [margin-width],
ClientRect.Height(),
[some-color]);
}I did this code from memory so there are probably some errors, but basically should work.
-
The easisest way to make this work would be to overide your frame class and position the view X pixels to the left of the frame left. Then, in your frame class (OnPaint), paint the left area the color your want. In its simplest form it would look something like:
BOOL CMyFrame::OnCreateClient(bla.bla.bla)
{
if (!CBaseFrameClass::OnCreateClient(bla.bla.bla))
return FALSE;PostMessage(WM_SIZE);
}BOOL CMyFrame::OnSize(bla.bla.bla)
{
if (m_pViewActive)
{
CRect ClientRect;
GetClientRect(ClientRect);m\_pViewActive->SetWindowPos(NULL, \[margin-width\], 0, ClientRect.Widht()-\[margin-width\], ClientRect.Height(), 0);
}
}void CMyFrame::OnPaint()
{
CPaintDC dc(this);
CRect ClientRect;
GetClientRect(ClientRect);dc.FillSolidRect(0,
0, [margin-width],
ClientRect.Height(),
[some-color]);
}I did this code from memory so there are probably some errors, but basically should work.
Hi, Thanks for the answer, I tried the code, which runs fine , but one problem remains is , How do I find the Height of the View, because if there are multiple Toolbars, ( esp. which can be dynamically aligned ), how do I calculate the height, also I have to consider the StatusBar. Because when I do GetClientRect(...), then it gives me the top, left as 0 (Zero ). Please can you help me here Thanks, Sanksy :-D God is Good, all the Time. All the Time, God is Good.
-
Hi, Thanks for the answer, I tried the code, which runs fine , but one problem remains is , How do I find the Height of the View, because if there are multiple Toolbars, ( esp. which can be dynamically aligned ), how do I calculate the height, also I have to consider the StatusBar. Because when I do GetClientRect(...), then it gives me the top, left as 0 (Zero ). Please can you help me here Thanks, Sanksy :-D God is Good, all the Time. All the Time, God is Good.
So you have a toolbar and status bar on your view's frame? Or just on your main frame window? If you are using traditional MDI you probably just have it on your main frame window and the GetClientRect call in your child's frame window will return the correct values. If you are using MTI, FDI or have toolbars on your child frame you will need to look at the RepositionBars function (CWnd? member I think?). I don't have access to my development PC at the moment, but I think this is right.
-
So you have a toolbar and status bar on your view's frame? Or just on your main frame window? If you are using traditional MDI you probably just have it on your main frame window and the GetClientRect call in your child's frame window will return the correct values. If you are using MTI, FDI or have toolbars on your child frame you will need to look at the RepositionBars function (CWnd? member I think?). I don't have access to my development PC at the moment, but I think this is right.
Thanks, I will check and let you know. Regards, Sansky :-D God is Good, all the Time. All the Time, God is Good.
-
Hi, Thanks for the answer, I tried the code, which runs fine , but one problem remains is , How do I find the Height of the View, because if there are multiple Toolbars, ( esp. which can be dynamically aligned ), how do I calculate the height, also I have to consider the StatusBar. Because when I do GetClientRect(...), then it gives me the top, left as 0 (Zero ). Please can you help me here Thanks, Sanksy :-D God is Good, all the Time. All the Time, God is Good.
check RecalcLayout and use the range 0 to 0xFFFF for the control bars... and check the flags in MSDN to calculate the total client rect and not actually do the GUI
- Roman -
-
check RecalcLayout and use the range 0 to 0xFFFF for the control bars... and check the flags in MSDN to calculate the total client rect and not actually do the GUI
- Roman -
Thanks for the reply, but please can you give more details . Regards, Sansky :-D God is Good, all the Time. All the Time, God is Good.