I Want To Fade-in, Fade-out a particular region created by me. but when i use animatewindow()
It fades out entire window which is not visible earlier when i created polygon region.
how do i do this? help can be appreciated.
Try this:
Use the SetLayeredWindowAttributes like this :
for (int opacity = 0; opacity <= 255; opacity++)
{
::SetLayeredWindowAttributes(hWnd, RGB(0,0,0), opacity, LWA_ALPHA);
Sleep(20) ;
}
This will fade out the hWnd window in approximately 5 seconds. The hWnd window must be created with the WS_EX_LAYERED extended style.
Related
I'm looking for a way to paint my custom controls into both the client and non-client area of a dialog. More or less the white area below
I used DwmExtendFrameIntoClientArea and I managed to get that effect by extending the client area on the entire window with
MARGINS mar = {-1, -1, -1, -1};
DwmExtendFrameIntoClientArea ( hWnd, &mar );
but now every control which I set with a transparent background
SetBkMode(hdc, TRANSPARENT);
have their colors blended with the aero stuff (the same problem you can see here).
Is there a way for the controls to retain their right color and avoid blending with the background?
It is because the window treated the black colour as the transparency key.
You just need to set another value:
SetWindowLong(hWnd,GWL_EXSTYLE,WS_EX_LAYERED);
// Choose a colour that you will not use in the program, eg RGB(200,201,202)
SetLayeredWindowAttributes(hWnd,RGB(200,201,202),0,LWA_COLORKEY);
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 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;
}
I am quite desperate to resolve this very annoying issue :(
I am trying to display a child window on parent window. Some time the window need to be resized. But for some reason, when I using MoveWindow function it leaves blank space on the top of the parent window. I would like to present a picture here but I can not post a picture.
Here is the code example:
HWND hwnd // Comes from external function. Was defined as WS_CHILD previously
HWND hwndParent = ::GetParent(hwnd);
RECT parentRect = {0,0,0,0};
RECT childRect = {0,0,0,0};
::GetClientRect(hwndParent, &parentRect); // Suppose it returns {0,0,600,300}
BOOL ok = ::MoveWindow(hwnd, 0, 0, 600, 300, true);
::GetClientRect(hwnd, &childRect); // Will return {0,0,584,297}
WHY ?????
What am I doing wrong? Did I forgot some flags with window initialization?!
Rather than use GetClientRect, use GetWindowRect and MapWindowPoints(NULL,hwndParent,&parentRect,2) to adjust it to the parent window coordinates. GetWindowRect will include the non-client area that MoveWindow requires.
Edit: If you want a window that doesn't have a non-client area so the window rect and the client rect are the same size, you need to trim the window styles that you apply to the window. Avoid the WS_BORDER, WS_CAPTION, WS_DLGFRAME, WS_OVERLAPPED, WS_SIZEBOX, and WS_THICKFRAME styles.
MoveWindow updates window position, while GetClientRect gets a client-area part of the window, which does not have to be the same. If your window has non-client area, then everything is fine and works as expected.
If you are still under impression that child window does not fully cover parent's client area, then the spacing belongs to the child control/window, and you need to look for ways to remove it there (control flags, parameters etc).
MoveWindow operates on window coordinates -- including non-client area (borders, title bar, etc).
GetClientRect gets the area of the client portion of the window, ignoring borders, title bar, etc.
This is where the mismatch is. If you want to MoveWindow to a desired client size, you need to just AdjustWindowRect to try and predict what to pass into MoveWindow. Note that it's not always possible, and not always accurate. For example minimum / maximum sizes of windows, menus (which can wrap to multiple lines), etc.
The problem was WS_POPUP flag to the parent window.
Very strange. As far as I know it was not suppose to have such an effect.
Thanks for everyone!
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);