I have created a CMFCPropertyGridCtrl on my form, however when setting the "Border" option to "True" in visual studio's Properties window for that control, it has no effects and the property grid always looks like it does in the below screenshot (with no border drawn around the control).
I also tried to enable the border from within my code but with no luck.
What are my options? Is this some kind of bug? I was thinking perhaps manually drawing a rectangle around the control to simulate a border as a last resort.
The border-less control:
http://img818.imageshack.us/img818/6337/8j1l.png
Thanks
So I found a solution myself
In the overridden OnPaint method of your dialog box add the following code:
CMFCPropertyGridCtrl* pPropGrid = (CMFCPropertyGridCtrl*) GetDlgItem(IDC_PROPSYSCHECK);
CPaintDC dc(this);
CPen BluePen(PS_SOLID, 1, RGB(137, 140, 149));
CPen *OldPen = dc.SelectObject(&BluePen);
CRect rect;
pPropGrid->GetWindowRect(&rect);
ScreenToClient(&rect);
dc.Rectangle(&rect);
dc.SelectObject(BluePen);
CDialogEx::OnPaint();
It draws a custom border around the control.
Visaul Studio contains the bug: Resource Editor does not add border style to the control description in dialog resource. So, add this style manually and be lucky :)
BOOL CMyDlg::OnInitDialog() {
CDialogEx::OnInitDialog();
// add WS_BORDER style manualy...
GetDlgItem(IDC_PROPSYSCHECK)->ModifyStyle(0, WS_BORDER);
return TRUE;
}
Related
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.
I don't like how the native sizing border looks like :
I would like to have something like this fancy purple border instead :
Should I implement my own sizing border manually or should I keep using the WS_THICKFRAME window style and customize it ?
And if I can customize it, I'd like it to be done without nasty hacks too...
You may create a window without border and caption bar by specifying the WS_POPUP flag in the window type flags.
Your handler of the WM_NCHITTEST message you must check which part of your window a certain pixel really belongs to (e.g. resinzing frame) and return the code for that part.
The drawback: You'll have to draw the entire window content (including caption etc.) your own.
I think you should implement your own redraw procedure (for example to draw a purple rectangle at the bottom, and then draw an icon in the corner). If you're wanted to make your window similar to VS2013 window, then you should use WS_POPUP style and then implement your own redraw routine. If you wanted to customize your window's form you can use regions (SetWindowRgn(), CreateRectRgn(), CreateRoundRectRgn(), CreateEllipticRgn(), CreatePolygonRgn(), etc.) Broadly speaking, using WinAPI you can do everything, but are you limited to WinAPI only? It is good idea to use MFC or Windows Forms to make window interface creation much easier.
As the title says.
Even with CPaintDC in the derived class the GDI drawing is not cut off.
Thanks in advance.
void CGraph::OnPaint ()
{
CPaintDC dc(this);
dc.SetViewportOrg (0, 400);
dc.SetMapMode(MM_ISOTROPIC);
dc.SetWindowExt(1000, 800);
dc.SetViewportExt(1000, -800);
// MessageBox(L"OnPaint");
ProcessData ();
DrawCoordinateSystem (&dc);
DrawGrid (&dc);
DrawGraph (&dc);
}
So, your CGraph is derived from CStatic, and the drawing code you show draws outside of the CStatic control, onto the dialog it is on? That's impossible, a control can only draw on itself. Are you sure the control isn't bigger than you think it is, and what you think is off-control actually isn't? Use spy++ to select your cstatic, it'll show you the border of the window.
Maybe what you are seeing is improper invalidation. Try dragging another window over your control, see what that does.
Otherwise, the methods to restrict the drawing area are
You manually track where to draw. Tedious.
Use SetClipRgn() to set the area to which to restrict drawing.
Not quite the same, but symptoms sometimes look similar: check the WS_CLIPSIBLINGS and WS_CLIPCHILDREN flags of your control and the dialog it's on.
Here is the way I solved the problem
CDC* pDC = GetDC();
CRect rClient(0,0,1000,800);
//GetClientRect(rClient);
CRgn ClipRgn;
if (ClipRgn.CreateRectRgnIndirect(&rClient))
{
pDC->SelectClipRgn(&ClipRgn);
}
pDC->SelectObject (PenBlack);
pDC->MoveTo (-leftMargin*zoomWidth, setPointsCorrected);
pDC->LineTo (1000*zoomWidth, setPointsCorrected);
pDC->SelectClipRgn(NULL);
ReleaseDC(pDC);
I am using an animation control in my MFC dialog box to display an animation. I want to change the background color of this control to match the background color of my dialog box, which is white. I have tried using the OnCtlColor() method, but apparently the animation control does not invoke OnCtlColor().
Any help on how I can change animation control's background to white? Thanks
I am not sure if this would help or not but surely give this a try.
you have the option of displaying the original background color of the video or seeing through. When creating a video, its author can do it with transparency to allow seeing the color of the host. In this case, to display the color of the host while the video is playing, set the Transparent property to True. If you are creating the control programmatically, add the ACS_TRANSPARENT style:
BOOL CControlsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
RECT Recto = { 5, 5, 360, 360 };
Player->Create(WS_CHILD | WS_VISIBLE |
ACS_TRANSPARENT | ACS_AUTOPLAY,
Recto, this, 0x1884);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
...
For more info, kindly visit the below link and hopefully you should get some idea from this.
Link: http://www.functionx.com/visualc/controls/animation.htm
Hope this helps.
Cheers.
I will try to explain my problem the best i can,
I'm creating a layered window in c++ (using windowsXP), all works fine until i drag my created window near the windows start button, and then when i press the star button of windows taskbar and close it again all the windows beneath of my layered window aren't being painted (only in the area of the start window that pops over my window).
My create window is like this:
CWnd::CreateEx( WS_EX_TOOLWINDOW |
WS_EX_LAYERED,
AfxRegisterWndClass(0),
lpstr_name, WS_POPUP, 0,0,0,0,
pc_parent->GetSafeHwnd(), 0);
...
When i create the window with this styles the problem ocurrs, but if i create with the extended style WS_EX_TRANSPARENT and all the others the problem does not occur any more. And if instead of a WS_POPUP window is a WS_CHILD or WS_OVERLAPPED then this also doesn't occur...
Can anyone please explain why when i create a WS_POPUP window with the WS_EX_LAYERED style all the beneath windows aren't updated, and if i add the style WS_EX_TRANSPARENT this works fine.
Note: why i do not use the WS_EX_TRANSPARENT style if it works right? if i use it then my window can not be dragged and i need it to do it :)
Updated:
alt text http://img17.imageshack.us/img17/586/clipboard01il.jpg
The image above is to describe better what is happening:
The first part of the image you can see my leyered window and beneath is the vs, in the second img i press the start button and then in the last image i already drag my layered window to the right and you can see that the vs window does not updates the affected area.
Note that this situation until now only occurs with the start window?! with other windows it does not happen!?...
Thanks
only in the area of the start window that pops over my window
That's expected. Only that clipping rectangle is obscured by the start menu so only that region will be repainted. What behavior are you expecting? If there are windows covered by more upper level windows, then they won't be repainted either -- why repaint something just to paint over it?
All underneath windows need to get repainted though if you use transparent because GDI can't calculate the final color of the pixel without knowing the area below the window's color.