Click here to Skip to main content
15,895,011 members
Articles / Desktop Programming / MFC

AppBar - How to implement a sliding desktop bar with a simple MFC class and a DLL

Rate me:
Please Sign up or sign in to vote.
4.58/5 (25 votes)
10 Jul 2008CPOL4 min read 154.2K   6.4K   95  
An alternative to standard Windows AppBars with minimal changes to your application.
// AppBarDemo.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "AppBarDemo.h"
#include "MainFrm.h"
#include "AppBarMngr.h"

/////////////////////////////////////////////////////////////////////////////
// CAppBarDemoApp

BEGIN_MESSAGE_MAP(CAppBarDemoApp, CWinApp)
	//{{AFX_MSG_MAP(CAppBarDemoApp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAppBarDemoApp construction

CAppBarDemoApp::CAppBarDemoApp()
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CAppBarDemoApp object

CAppBarDemoApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CAppBarDemoApp initialization

BOOL CAppBarDemoApp::InitInstance()
{
	CMainFrame* pFrame = new CMainFrame;
	m_pMainWnd = pFrame;

	// creates a simple frame, without caption, icon or menu
	pFrame->Create(NULL, "AppBarDemo", WS_POPUP);
	
	// avoid taskbar button to appear, also removes 3D edge
	pFrame->ModifyStyleEx(WS_EX_APPWINDOW|WS_EX_CLIENTEDGE, WS_EX_TOOLWINDOW);
	// Don't show, AppBar Manager class will do
	pFrame->ShowWindow(SW_HIDE);
	pFrame->UpdateWindow();

	// Create AppBar manager thread
	CAppBarMngr *appbar = (CAppBarMngr *)::AfxBeginThread(RUNTIME_CLASS(CAppBarMngr));

	// Init AppBar Manager, right sided
	int result = appbar->Init(pFrame->m_hWnd, 150, false);
 
	// Check if hooking has been successful
	if (result==APPBARHOOK_SUCCESS)
		return TRUE;
	else if (result==APPBARHOOK_DLLERROR)
		::AfxMessageBox("Error loading AppBarHook.dll");
	// else should be APPBARHOOK_ALREADYHOOKED, close application

	return FALSE;
}

/////////////////////////////////////////////////////////////////////////////
// CAppBarDemoApp message handlers

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Peru Peru


Computer Electronics professional, Software Architect and senior Windows C++ and C# developer with experience in many other programming languages, platforms and application areas including communications, simulation systems, PACS/DICOM (radiology), GIS, 3D graphics and HTML5-based web applications.
Currently intensively working with Visual Studio and TFS.

Comments and Discussions