Pour dessiner l'icône sur la barre de titre de légende, j'ai référencé this MSDN article et utilisé l'API DWM pour créer ma zone client personnalisée en appelant DwmExtendFrameIntoClientArea.Un problème de barre de titre de légende Aero utilisant l'API DWM sur les fenêtres 10
mon code:
CMainFrame::CMainFrame()
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
BOOL fDwmEnabled = FALSE;
if (SUCCEEDED(DwmIsCompositionEnabled(&fDwmEnabled)))
TRACE0("DWM is enabled\n");
TCHAR szLogoPath[MAX_PATH];
GetModuleFileName (GetModuleHandle(NULL), szLogoPath, _countof(szLogoPath) );
PathRemoveFileSpec (szLogoPath);
PathAppend (szLogoPath, _T("lena.bmp"));
m_pLogoImage = m_pLogoImage->FromFile (CT2CW(szLogoPath));
if(NULL == m_pLogoImage)
TRACE0("load image fail\n");
}
void CMainFrame::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
int xFrame = 2;
int yFrame = 2;
int nTHight = 30;
NCCALCSIZE_PARAMS * p;
RECT * rc;
RECT aRect;
RECT bRect;
RECT acRect;
p = (NCCALCSIZE_PARAMS *)lpncsp;
CopyRect(&bRect,&p->rgrc[1]);
CopyRect(&aRect,&p->rgrc[0]);
acRect.left = aRect.left + xFrame;
acRect.top = aRect.top - nTHight;
acRect.right = aRect.right - xFrame;
acRect.bottom = aRect.bottom - yFrame;
CopyRect(&p->rgrc[0],&acRect);
CopyRect(&p->rgrc[1],&aRect);
CopyRect(&p->rgrc[2],&bRect);
CFrameWnd::OnNcCalcSize(TRUE, lpncsp);
}
LRESULT CMainFrame::OnNcHitTest(CPoint p)
{
BOOL dwm_enabled = FALSE;
if (SUCCEEDED(DwmIsCompositionEnabled(&dwm_enabled)))
{
LRESULT result = 0;
if (!DwmDefWindowProc(m_hWnd, WM_NCHITTEST, 0, MAKELPARAM(p.x, p.y), &result))
result = HitTestNCA(m_hWnd, p);
if (result == HTNOWHERE && GetForegroundWindow() != this)
{
return HTCAPTION;
}
return result;
}
return CWnd::OnNcHitTest(p);
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if(cs.hMenu!=NULL)
{
::DestroyMenu(cs.hMenu);
cs.hMenu = NULL ;
}
if(!CFrameWnd::PreCreateWindow(cs))
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style = WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_OVERLAPPED| WS_SYSMENU | WS_THICKFRAME;
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.lpszClass = AfxRegisterWndClass(0);
return TRUE;
}
void CMainFrame::OnActivate(UINT nState,CWnd* pWndOther,BOOL bMinimized)
{
CFrameWnd::OnActivate(nState,pWndOther,bMinimized);
BOOL fDwmEnabled = FALSE;
if (SUCCEEDED(DwmIsCompositionEnabled(&fDwmEnabled)))
{
if(nState == WA_ACTIVE)
{
MARGINS margins = {-1};
/*margins.cyTopHeight = 30;
margins.cxLeftWidth = 0;
margins.cxRightWidth = 0;
margins.cyBottomHeight = 0;*/
HRESULT hr = DwmExtendFrameIntoClientArea(m_hWnd, &margins);
if (!SUCCEEDED(hr))
TRACE0("Failed in DwmExtendFrameIntoClientArea\n");
}
}
}
void CMainFrame::OnNcPaint()
{
CFrameWnd::OnPaint();
CDC* dc = GetWindowDC();
RECT rcClient;
GetWindowRect(&rcClient);
dc->FillSolidRect(0,0,RECTWIDTH(rcClient),RECTHEIGHT(rcClient),RGB(255,0,0));
CPaintDC gdc(this); // device context for painting
Graphics gr(gdc.m_hDC);
gr.DrawImage (m_pLogoImage, 0, 0);
ReleaseDC(dc);
}
Le résultat sous Windows 7 est très bien.
Cependant, ma fenêtre apparaît une autre barre de titre de légende inconnue sous Windows 10.
J'ai découvert la légende inconnue est causée par WS_THICKFRAME dans le cs.style. Si je supprime WS_THICKFRAME, la barre de cation inconnue disparaîtra, mais je ne peux pas redimensionner la bordure de ma fenêtre. De plus, mon programme ne peut plus capturer les messages de minimum, maximum et de bouton de fermeture de ma barre de légende personnalisée. Je souhaite supprimer la barre de titre inconnue sans aucun effet secondaire. Quelqu'un peut-il me fournir une bonne solution ou une suggestion?
Cordialement,
* « Est-ce que quelqu'un pourrait me fournir une bonne solution ou une suggestion? » * - À moins que vous nous dites, ce que vous avez besoin, c'est probablement pas se passer. Vous avez beaucoup parlé de ce que vous ne voulez pas, mais n'avez jamais produit une description succincte de ce dont vous avez vraiment besoin. – IInspectable
Je veux supprimer la barre de titre inconnue sans aucun effet secondaire. Merci – user2365346