void Main_OnCommand(HWND hwnd, int id, HWND /* hwndCtl */, UINT /* codeNotify */) { switch (id) { case ID_FILE_EXIT: // The user wants to exit, so send our window a close message SendMessage(hwnd, WM_CLOSE, 0, 0L); break; case ID_HELP_ABOUT: // Display the "About" dialog DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc); break; case ID_PROPERTIES: ShowOptions(hwnd); break; case ID_APPBAR_REGISTER: AppBar_Register(hwnd); break; case ID_APPBAR_UNREGISTER: AppBar_UnRegister(hwnd); break; case ID_APPBAR_AUTOHIDE: AppBar_SetAutoHide(hwnd, TRUE); break; case ID_APPBAR_NOAUTOHIDE: AppBar_SetAutoHide(hwnd, FALSE); break; case ID_APPBAR_TOP: AppBar_SetSide(hwnd, ABE_TOP); break; case ID_APPBAR_BOTTOM: AppBar_SetSide(hwnd, ABE_BOTTOM); break; case ID_APPBAR_LEFT: AppBar_SetSide(hwnd, ABE_LEFT); break; case ID_APPBAR_RIGHT: AppBar_SetSide(hwnd, ABE_RIGHT); break; } }
BOOL Main_OnCreate(HWND hwnd, LPCREATESTRUCT /* lpCreateStruct */) { // Initialize the common control DLL InitCommonControls(); // Allocate an OPTIONS struct and attach to the appbar POPTIONS pOptions = (POPTIONS)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OPTIONS)); if (pOptions) { SetWindowLongPtr(hwnd, 0,(LONG_PTR)pOptions); } else { return FALSE; } pOptions->fAutoHide = FALSE; pOptions->fOnTop = FALSE; pOptions->uSide = ABE_TOP; pOptions->cxWidth = CX_DEFWIDTH; pOptions->cyHeight = CY_DEFHEIGHT; // Register the appbar and attach it to the top by default AppBar_Register(hwnd); AppBar_SetSide(hwnd, ABE_TOP); // Create the fonts for drawing in the client area LOGFONT lf; ZeroMemory(&lf,sizeof(LOGFONT)); lf.lfHeight = 45; lf.lfEscapement = 2700; lf.lfOrientation = 0; StringCchCopy(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), L"Arial"); s_hFontLeft = CreateFontIndirect(&lf); lf.lfEscapement = 0; s_hFontTop = CreateFontIndirect(&lf); return TRUE; }
BOOL CAppBar::AppBar_SetSide(UINT uSide) { if(!g_fAppRegistered) AppBar_Register(); BOOL fAutoHide = FALSE; // Calculate the size of the screen so we can occupy the full width or // height of the screen on the edge we request. m_rc.top = 0; m_rc.left = 0; m_rc.right = GetSystemMetrics(SM_CXSCREEN); m_rc.bottom = GetSystemMetrics(SM_CYSCREEN); // Fill out the APPBARDATA struct with the basic information abd.cbSize = sizeof(APPBARDATA); abd.hWnd = pHandler; // If the appbar is autohidden, turn that off so we can move the bar if (m_pOptions->fAutoHide) { fAutoHide = m_pOptions->fAutoHide; // Turn off the redrawing of the desktop while we move things around. // If you put any breakpoints in this area you will lock up the desktop // Since turning off the desktop repaints turns it off for all the apps // in the system SetWindowRedraw(GetDesktopWindow(), FALSE); AppBar_SetAutoHide(FALSE); } // Adjust the rectangle to set our height or width depending on the // side we want. switch (uSide) { case ABE_TOP: m_rc.bottom = m_rc.top + m_pOptions->cyHeight; break; case ABE_BOTTOM: m_rc.top = m_rc.bottom - m_pOptions->cyHeight; break; case ABE_LEFT: m_rc.right = m_rc.left + m_pOptions->cxWidth; break; case ABE_RIGHT: m_rc.left = m_rc.right - m_pOptions->cxWidth; break; } // Move the appbar to the new screen space. AppBar_QuerySetPos(uSide, &m_rc, &abd, TRUE); // If the appbar was hidden, rehide it now if (fAutoHide) { AppBar_SetAutoHide(TRUE); SetWindowRedraw(GetDesktopWindow(), TRUE); RedrawWindow(GetDesktopWindow(), NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN); } return (TRUE); }