How to increase thickness of slider conrol in mfc? - c++

How can I increase the thickness of a CSliderCtrl (slider control) in MFC?

MoveWindow() can be used for any MFC control. Try this:
CRect rc;
slider.GetWindowRect(rc); // Get the slider rectangle in absolute corrdinates
rc.InflateRect(30, 30); // Do whatever you want with your rectangle;
ScreenToClient (rc); // Convert to dialogs's coordinates
slider.MoveWindow(rc); // Move it!
Update:
For further customization you have to make an owner-drawn CListCtrl. You may take this article as a good start for that

Related

Want to show colored box around Richedit control in MFC at runtime

I have an mfc application. I have some richedit controls on the dialog. I want to show a yellow colored filled frame around the controls. What is the way to do this?
I tried to create one more rich edit ctrl around the existing richedit ctrl and use SetBackgroundColor on its variable, but it colors the entire area and other richedit ctrls become invisible. Also, I want to change the surrounding color at run time.
Please help me. I am stuck with this.
There may be a better way to accomplish this, but, the following should work. If you derive your own class from CRichEditCtrl, you can leverage the WM_NCPAINT message to render the border. Something like…
void RichEdit::OnNcPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetWindowRect(&rect);
ScreenToClient(rect);
CPen pen;
pen.CreatePen(PS_SOLID, 10, RGB(255, 255, 0));
dc.SelectObject(pen);
dc.Rectangle(&rect);
CHARFORMAT cf = { 0 };
int txtLen = GetTextLength();
cf.cbSize = sizeof(cf);
cf.dwMask = CFM_ITALIC;
SetSel(txtLen, -1); ReplaceSel("Some text");
// Apply formating to the just inserted text.
SetSel(txtLen, GetTextLength());
SetSelectionCharFormat(cf);
SetFocus();
// Do not call CRichEditCtrl::OnNcPaint() for painting messages
}
Will render the border as Yellow, and, write the corresponding text. Here’s what it will look like.

MFC selection of a user drawn rectangle on picture control

I'm trying to create an interface that allows the user to draw a rectangle over a picture control box. I have a picture control class and used CRectTracker to allow the user to draw a rectangle. I want the user to also be able to select a previously drawn rectangle but I don't know how to handle the selection of a drawn rectangle.
I want to be able to select the rectangle and also add resize handlers on it.
Here is my code for drawing the rect.
void PictureCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
// If mouse click is outside of rectangle
if(m_drawRect.m_tracker.HitTest(point) < 0 ) {
if(m_drawRect.m_tracker.TrackRubberBand(this, point, TRUE)) {
CDC* pDC = GetDC();
m_drawRect.m_tracker.m_nStyle &= CRectTracker::resizeInside;
// Paint transparent rectangle
pDC->SelectStockObject(NULL_BRUSH);
pDC->Rectangle(m_drawRect.m_tracker.m_rect);
ReleaseDC(pDC);
}
}
CStatic::OnLButtonDown(nFlags, point);
}
Any help would be appreciated. Thank you.
You will need to store the coordinates of the rectangle in your class (also save/load) and perform a HitTest during mouse-down.
To implement the resize handles, you will need a boolean to denote that the rectangle is selected (set boolean to FALSE if the click is not on the rectangle) and draw grab handles during paint if the boolean is TRUE; if the mouse moves over the grab handles, change the mouse-cursor, perform the resize during mouse-down and mouse-up in this case.
It's all quite complicated and gets more so if you have more than just one rectangle!
Here is a DrawCLI MSDN example which does all of that with rectangles, rounded rectangles, ellipses, lines and polylines plus support for OLE -- maybe this will help, it's probably easier to delete classes/functions from DrawCLI before it's in a state to merge with your application...

Rectangle in MFC

I try to draw a rectangle on a mfc window using the instructions by: http://msdn.microsoft.com/en-US/library/8w4fzfxf%28v=VS.80%29.aspx . Much though I tried, the Rectangle appears on the border of the window covering the whole of it. What is the problem with the following code int the function OnDraw(CDC* pDC) ? What can be done to draw a Rectangle with particular coordinates in the window?
CPen penBlack;
penBlack.CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
CPen* pOldPen = pDC->SelectObject(&penBlack);
CPoint pt(10, 10);
CSize sz(100, 50);
CRect myRect(pt, sz);
GetClientRect(&myRect);
pDC->Rectangle(&myRect);
Drop the call to GetClientRect.
That function will write to the rectangle object passed to it, so by calling, you're overwriting your specific coordinates that you set up just before the call using pt and sz.
As #stakx suggested you should remove the GetClientRect, which gets the whole window client area, and overwrites your own rectangle.
As to the instruction, it first gets the whole client area, and shrinks the rectangle to get the rectangle to draw, so GetClientRect is needed there.
This site will help you to draw the rectangle in mfc Dialog-based-application.
http://cboard.cprogramming.com/windows-programming/37788-drawing-mfc.html
http://cboard.cprogramming.com/cplusplus-programming/102490-cplusplus-mfc-rectangle-class.html
Don't use GetClientRect().It will override your previous coordinates.

draw in picturebox with scorll mfc c++

I want to draw in Picture Box control my purpose is picture box have scroll bar that I can draw in it bigger than what It's size I mean have scroll to move It's picture,
I try to draw something more than picturebox's size, It went to main frame panel my code is below.
void Cex133Dlg::OnBnClickedOk()
{
CDC *myDC = GetDlgItem(IDC_DRAWBOX)->GetDC();
myDC->Rectangle(10, 10, 20, 20);
}
You can draw with in the picture box. Definitely it will go outside the picture box frame, if you draw something more than picturebox's size. For that you can calculate the picture box Size, According to that you will draw your object.
You don't draw to the control -- you give it a bitmap, and it does its own drawing.
Hi you can look for http://www.codeguru.com/cpp/cpp/cpp_mfc/general/article.php/c14765 and mfc CScrollView

Does overriding OnNcPaint() affect the painting of the client area of a window?

I want to change the appearance of a window's caption bar, so I decided to override the OnNcPaint() method of CMainFrame. But when I did this, I found a problem. If there is another window covering my window, and I drag the window quickly, the content of the client area of my window disappeared, which came to sight only when I stopped the dragging.
My overridden OnNcPaint() is like below:
void CMainFrame::OnNcPaint()
{
CDC* pWinDC = GetWindowDC();
//do some drawing
ReleaseDC(pWinDC);
}
Is there something wrong with my approach?
Thank you!
Unless you use a clipping region set up to exclude the client area, you can paint over it from OnNcPaint(). So... if your drawing logic can't be modified to exclude the client in some other way, set up an appropriate clipping region first:
CRect rect;
GetWindowRect(&rect);
ScreenToClient(&rect);
CRect rectClient;
GetClientRect(&rectClient);
rectClient.OffsetRect(-rect.left, -rect.top);
rect.OffsetRect(-rect.left, -rect.top);
pWinDC->ExcludeClipRect(&rectClient);
// ...
// draw stuff here
// ...
pWinDC->SelectClipRgn(NULL);