Creating a child CWnd inside a CView paint corruption - c++

I want to create a CWnd derived class inside a CView derived class. I am using also a window splitter to create a tree control menu to the left side and a view area in the right side like the draft below.
------------------------
| tree | View |
| menu | |
| | |
------------------------
The problem is that when CWnd::OnEraseBkgnd is called for the 1st time it erases the background from the Window's most top left corner instead of the view's client area causing a temporary corrupted area. I tried to use the SetWindowPos but didn't solve the problem.
I create the CWnd derived class like this
CRect rect;
m_MediaWindow->GetClientRect(&rect); //Get CSplitterView client area size
if (!m_videoChildWnd.Create(NULL, NULL, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CHILD | WS_VISIBLE , rect, m_MediaWindow, ID_DSHOW_RENDER_WND)) {
// failed to create child
return TRUE;
}
::SetWindowPos(m_videoChildWnd,NULL, rect.left, rect.top, rect.Width(), rect.Height(),
SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
m_videoChildWnd.ShowWindow(SW_SHOW);
Now inside m_videoChildWnd exist the OnEraseBkgnd function
BOOL CWndVideoChild::OnEraseBkgnd(CDC* pDC) {
// TODO: Add your message handler code here and/or call default
CBrush brush;
CRect rect;
GetClientRect(&rect);
brush.CreateStockObject(BLACK_BRUSH);
pDC->FillRect(rect,&brush);
return TRUE;
}
after almost 3 calls from the framework the repaint system restore the corrupted area and everything works just fine.
Any ideas how to solve this ?

Related

How do I refresh MFC dialog before Sleep() call

I have an array of buttons holding bitmap images.
I'm trying to change the image of one of the buttons to a different image for one second, and then change it again - but during the sleep, the UI still displays the older image as if I hadn't changed it - this means I don't see bmp_explosion displayed at all.
void COOPFinalDlg::ShowExplosion(int position)
{
SetButtonImage(position, bmp_explosion);
Sleep(1000);
SetButtonImage(position, bmp_tile);
}
void COOPFinalDlg::SetButtonImage(int buttonId, int imageId)
{
CButton* button = buttons[buttonId - ButtonRangeStart];
CBitmap bmp;
bmp.LoadBitmap(imageId);
button->SetBitmap(bmp);
}
The buttons were initalized to a bitmap the following way:
CBitmap bmp;
bmp.LoadBitmap(bmp_tile);
CRect rect(....);
CButton* button = new CButton;
button->Create(NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | DT_CENTER | WS_BORDER, rect, this, idCounter++);
button->ModifyStyle(0, BS_BITMAP);
button->SetBitmap(bmp);
buttons.Add(button);

Need to Make CDockablePane Background Transparent in c++ MFC

I'm developing an application in MFC C++ and I have derived a CDockablePane object that I can view on the main window. I need the dockable pane's background to be transparent so you can see the main window through the dockable pane.
How would I accomplish this? Thanks.
this how i create the CDockable Pane object:
if (!FeaturePane.Create("Features", this, CSize (400,500), TRUE, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create Program window\n");
//return false; // failed to create
return FALSE;
}
i Know you can clear the background of a CDroDialog using the following code:
BOOL CDroDialog::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd,GWL_EXSTYLE) ^ WS_EX_LAYERED);
SetLayeredWindowAttributes(RGB(255,0,255),0, LWA_COLORKEY);
}
BOOL CDroDialog::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect clientRect ;
GetClientRect(&clientRect) ;
pDC->FillSolidRect(clientRect, RGB(255,0,255)) ; // paint background in magenta
//return CDialog::OnEraseBkgnd(pDC);
return FALSE;
}

how to create or dock dockable pane on full client screen MFC?

i want to create a dockable pane full size on client screen i want it load full size on client screen by default when application load at start point.i have tried with many ways like override setwindowpos() method and setminsize() method but it didn't work window not called this method on cdockable pane here is my code on oncreate() method in parent window
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
BOOL bNameValid;
// Create output window
CString strOutputWnd;
bNameValid = strOutputWnd.LoadString(IDS_OUTPUT_WND);
ASSERT(bNameValid);
if (!m_wndOutput.Create(strOutputWnd, this, CRect(0, 0, 0, 0), TRUE, ID_VIEW_OUTPUTWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create Output window\n");
return FALSE; // failed to create
}
m_wndOutput.EnableDocking(CBRS_ALIGN_ANY );
int screen_height=GetSystemMetrics(SM_CYSCREEN);
int screen_width =GetSystemMetrics(SM_CXSCREEN);
m_wndOutput.SetMinSize(CSize(screen_height,screen_width)
m_wndOutput.CalcFixedLayout(FALSE,TRUE);
DockPane(&m_wndOutput);
}

How to make WS_THICKFRAME invisible, but still functional in MFC?

So, I created a dialog that has a style: WS_THICKFRAME.
This WS_THICKFRAME gives the dialog box the functionality to resize the window, but my problems is that I don't won't a border around my window to be visible. How would I make the border invisible, but still have the re-size capability?
An example would be most helpful! Thanks!
Below, are the styles of the template for the dialog box I created:
IDD_GADGETTRANSLUCENTDIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_ABSALIGN | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | WS_SYSMENU | WS_THICKFRAME
Remove WS_THICKFRAME
Handle WM_NCHITTEST roughly as follows:
UINT CMyClass::OnNcHitTest(CPoint point)
{
CRect rWindow;
GetWindowRect(rWindow);
CRect rInner(rWindow);
rInner.DeflateRect(GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
if (rWindow.PtInRect(point) && !rInner.PtInRect(point))
{
// figure out which of the following codes to return: //
// HTBOTTOM, HTTOP, HTLEFT, HTRIGHT //
// HTBOTTOMLEFT, HTBOTTOMRIGHT, HTTOPLEFT, HTTOPRIGHT //
}
else
{
return CMyBaseClass::OnNcHitTest(point);
}
}

MFC CEdit object in a CDialogEx object

I'd be very grateful if anyone could help me with this? I'm trying to create a dialog box with a text box in it for receiving error messages. I've added ON_WM_CREATE to the message map, and written this function which the debug goes through, but the object doesn't display.
int CImportDatatoAPMDlg::OnCreate(LPCREATESTRUCT LpCreateStruct)
{
if(CWnd::OnCreate(LpCreateStruct) == -1)
{
return -1;
}
CEdit *MessageBox = new CEdit;
MessageBox->Create(WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL,CRect(100, 200, 450, 150), this, 0x1552);
return 0;
}
Do I have to make a dummy box when I'm designing the dialog box. I've already done this for the rest of the controls? I'm also wondering where I give this object a number ID combination?
Thanks,
James
You normally should use VisualStudio resource editor to add controls to your dialog. If you want to do it manually then create and add controls in your overriden OnInitDialog method:
BOOL CImportDatatoAPMDlg::OnInitDialog() {
BOOL bRes = CDialog::OnInitDialog();
CEdit *MessageBox; // !!! put it into class definition
MessageBox = new CEdit
MessageBox->Create(WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL,CRect(100, 200, 450, 150), this, 0x1552);
return bRes;
}