Creating a window on the title bar produces strange results

  • Thread starter Thread starter Artimonier
  • Start date Start date
A

Artimonier

Guest
Hi,

I am currently trying to create a toolbar that looks like a menu and place it on the title bar/caption using an extended frame but for some reason drawing in the non-client area (which became the client area by extending) produces strange results. The label text is white and system button seem to have a strange dash coming from the toolbar window. There is no way to even see the menu items unless you highlight them by moving the cursor over them. (See screenshot below)

MainMenu.cpp:

VOID MainMenu::wCreate(HWND wMainWindow) {
// CREATE MENU HOST

WNDCLASS wc = { };

wc.lpszClassName = L"MainMenuHost";
wc.lpfnWndProc = DefWindowProc;
wc.hInstance = GetModuleHandle(NULL);
wc.hbrBackground = GetStockBrush(BLACK_BRUSH);
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
RegisterClass(&wc);

HWND wMainMenuHost = CreateWindowEx(NULL,L"MainMenuHost", NULL, WS_CHILD | WS_VISIBLE,
38,
0.6 * GetSystemMetrics(SM_CYCAPTION),
GetSystemMetrics(SM_CXMAXIMIZED),
GetSystemMetrics(SM_CYMENU),
wMainWindow, NULL, GetInstanceModule(NULL), NULL);

HRESULT hr = GetLastError();
// CREATE MENU
HWND wMainMenu = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | /*TBSTYLE_WRAPABLE |*/ TBSTYLE_FLAT | TBSTYLE_LIST,
NULL, NULL, NULL, GetSystemMetrics(SM_CYMENU),
wMainMenuHost, NULL, GetInstanceModule(NULL), NULL);

TCHAR fileButtonS1[] = _T("File");
TCHAR fileButtonS2[] = _T("Edit");
TBBUTTON fileButton[] = { {I_IMAGENONE, NULL, TBSTATE_ENABLED, BTNS_DROPDOWN, {0}, 0, (INT_PTR)fileButtonS1},
{I_IMAGENONE, NULL, TBSTATE_ENABLED, BTNS_DROPDOWN, {0}, 0, (INT_PTR)fileButtonS2} };
SendMessage(wMainMenu, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(wMainMenu, TB_ADDBUTTONS, (WPARAM)2, (LPARAM)&fileButton);
ShowWindow(wMainMenu, SW_SHOW);

hr = GetLastError();

}

MainWindow.cpp Procedure:


LRESULT CALLBACK MainWindow::wProcedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){


struct metrics m;
BOOL dwmHandled;
LRESULT lResult;

dwmHandled = DwmDefWindowProc(hwnd, uMsg, wParam, lParam, &lResult);
getMetrics(&m, hwnd);

switch (uMsg) {
case WM_CREATE:
{
SetWindowPos(hwnd, NULL,
m.windowRect.left, m.windowRect.top,
m.windowRect.right - m.windowRect.left, m.windowRect.bottom - m.windowRect.top,
SWP_FRAMECHANGED);
MainMenu::wCreate(hwnd); // <- Fuct
break;
}

case WM_ACTIVATE:
DwmExtendFrameIntoClientArea(hwnd, &(m.realNonclientInsets));
break;

case WM_NCCALCSIZE:
{
NCCALCSIZE_PARAMS *pncsp = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);

pncsp->rgrc[0].left = pncsp->rgrc[0].left + 0;
pncsp->rgrc[0].top = pncsp->rgrc[0].top + 0;
pncsp->rgrc[0].right = pncsp->rgrc[0].right - 0;
pncsp->rgrc[0].bottom = pncsp->rgrc[0].bottom - 0;

lResult = 0;

// No need to pass the message on to the DefWindowProc.
dwmHandled = true;

}

case WM_NCHITTEST:
if (dwmHandled)
return lResult;

if (defWindowProcFirst) {
lResult = DefWindowProcW(hwnd, uMsg, wParam, lParam);
if (lResult != HTCLIENT) {
return lResult;
}
}
{
POINT p;

p.x = GET_X_LPARAM(lParam);
p.y = GET_Y_LPARAM(lParam);

lResult = HTNOWHERE;
if (p.y >= m.windowRect.top && p.y < (m.windowRect.top + m.resizeFrameInsets.cyTopHeight))
lResult = HTTOP;
else if (p.y >= m.effectiveClientRect.bottom && p.y < m.windowRect.bottom)
lResult = HTBOTTOM;

if (p.x >= m.windowRect.left && p.x < m.effectiveClientRect.left)
switch (lResult) {
case HTNOWHERE:
lResult = HTLEFT;
break;
case HT"white-space:pre;">lResult = HTTOPLEFT;
break;
case HTBOTTOM:
lResult = HTBOTTOMLEFT;
break;
}
else if (p.x >= m.effectiveClientRect.right && p.x < m.windowRect.right)
switch (lResult) {
case HTNOWHERE:
lResult = HTRIGHT;
break;
case HT"white-space:pre;">lResult = HTTOPRIGHT;
break;
case HTBOTTOM:
lResult = HTBOTTOMRIGHT;
break;
}

if (lResult == HTNOWHERE)
if (p.y >= (m.windowRect.top + m.resizeFrameInsets.cyTopHeight) && p.y < m.effectiveClientRect.top)
lResult = HTCAPTION;
if (lResult != HTNOWHERE)
return lResult;
}

break;

case WM_SIZE:
InvalidateRect(hwnd, &(m.relativeClientRect), FALSE);
break;

case WM_PAINT:
{
break;
}

case WM_CLOSE:
PostQuitMessage(0);
break;
}

if (dwmHandled)
return lResult;
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}

1480486
1480833.png

Thank you.

Continue reading...
 
Back
Top