//---------------------------------------------------------------------------
#include <windows.h>
#include <CommCtrl.h> // needed for adding custom toolbar
#include "resource.h"
#pragma hdrstop


//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
LPCTSTR ClsName = L"FundApp";
//LPCTSTR WndName = L"Resources Fundamentals";
const int NUMBUTTONS = 3;

TCHAR AppCaption[40];
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
	WPARAM wParam, LPARAM lParam);
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow)
{
	MSG        Msg;
	HWND       hWnd;
	WNDCLASSEX WndClsEx;

	LoadString(hInstance, IDS_APP_NAME, AppCaption, 40);

	// Create the application window
	WndClsEx.cbSize        = sizeof(WNDCLASSEX);
	WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
	WndClsEx.lpfnWndProc   = WndProcedure;
	WndClsEx.cbClsExtra    = 0;
	WndClsEx.cbWndExtra    = 0;
	WndClsEx.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
	WndClsEx.hCursor       = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR1));
	WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	WndClsEx.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINFRAME);
	WndClsEx.lpszClassName = ClsName;
	WndClsEx.hInstance     = hInstance;
	WndClsEx.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

	// Register the application
	RegisterClassEx(&WndClsEx);

	// Create the window object
	hWnd = CreateWindowEx(0,
		ClsName,
		AppCaption,
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		NULL,
		NULL,
		hInstance,
		NULL);

	// Find out if the window was created
	if( !hWnd ) // If the window was not created,
		return FALSE; // stop the application


	// Used for toolbar
	INITCOMMONCONTROLSEX InitCtrlEx;

	InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
	InitCtrlEx.dwICC  = ICC_BAR_CLASSES;
	InitCommonControlsEx(&InitCtrlEx);

	TBBUTTON tbrButtons[7];

	tbrButtons[0].iBitmap   = 0;
	tbrButtons[0].idCommand = IDM_FILE_NEW;
	tbrButtons[0].fsState   = TBSTATE_ENABLED;
	tbrButtons[0].fsStyle   = TBSTYLE_BUTTON;
	tbrButtons[0].dwData    = 0L;
	tbrButtons[0].iBitmap   = 0;
	tbrButtons[0].iString   = 0;

	tbrButtons[1].iBitmap   = 1;
	tbrButtons[1].idCommand = IDM_FILE_OPEN;
	tbrButtons[1].fsState   = TBSTATE_ENABLED;
	tbrButtons[1].fsStyle   = TBSTYLE_BUTTON;
	tbrButtons[1].dwData    = 0L;
	tbrButtons[1].iString   = 0;

	tbrButtons[2].iBitmap   = 0;
	tbrButtons[2].idCommand = 0;
	tbrButtons[2].fsState   = TBSTATE_ENABLED;
	tbrButtons[2].fsStyle   = TBSTYLE_SEP;
	tbrButtons[2].dwData    = 0L;
	tbrButtons[2].iString   = 0;

	tbrButtons[3].iBitmap   = 2;
	tbrButtons[3].idCommand = IDM_ARROW;
	tbrButtons[3].fsState   = TBSTATE_ENABLED;
	tbrButtons[3].fsStyle   = TBSTYLE_BUTTON;
	tbrButtons[3].dwData    = 0L;
	tbrButtons[3].iString   = 0;

	tbrButtons[4].iBitmap   = 3;
	tbrButtons[4].idCommand = IDM_DRAW_LINE;
	tbrButtons[4].fsState   = TBSTATE_ENABLED;
	tbrButtons[4].fsStyle   = TBSTYLE_BUTTON;
	tbrButtons[4].dwData    = 0L;
	tbrButtons[4].iString   = 0;

	tbrButtons[5].iBitmap   = 4;
	tbrButtons[5].idCommand = IDM_DRAW_RECTANGLE;
	tbrButtons[5].fsState   = TBSTATE_ENABLED;
	tbrButtons[5].fsStyle   = TBSTYLE_BUTTON;
	tbrButtons[5].dwData    = 0L;
	tbrButtons[5].iString   = 0;

	tbrButtons[6].iBitmap   = 5;
	tbrButtons[6].idCommand = IDM_DRAW_ELLIPSE;
	tbrButtons[6].fsState   = TBSTATE_ENABLED;
	tbrButtons[6].fsStyle   = TBSTYLE_BUTTON;
	tbrButtons[6].dwData    = 0L;
	tbrButtons[6].iString   = 0;

	HWND hWndToolbar;
	hWndToolbar = CreateToolbarEx(hWnd,
		WS_VISIBLE | WS_CHILD | WS_BORDER,
		IDB_TOOLBAR,
		NUMBUTTONS,
		hInstance,
		IDB_TOOLBAR,
		tbrButtons,
		NUMBUTTONS,
		16, 16, 16, 16,
		sizeof(TBBUTTON));



	// Display the window to the user
	ShowWindow(hWnd, nCmdShow);// SW_SHOWNORMAL);
	UpdateWindow(hWnd);

	// Decode and treat the messages
	// as long as the application is running
	while( GetMessage(&Msg, NULL, 0, 0) )
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}

	return Msg.wParam;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
	WPARAM wParam, LPARAM lParam)
{
	switch(Msg)
	{
	case WM_DESTROY:
		PostQuitMessage(WM_QUIT);
		break;
	default:
		// Process the left-over messages
		return DefWindowProc(hWnd, Msg, wParam, lParam);
	}
	// If something was not done, let it go
	return 0;
}
//---------------------------------------------------------------------------

Linker Errors
1>WinMain.obj : error LNK2019: unresolved external symbol __imp__CreateToolbarEx@52 referenced in function _WinMain@16
1>WinMain.obj : error LNK2019: unresolved external symbol __imp__InitCommonControlsEx@4 referenced in function _WinMain@16
1>D:\Programming\Visual Studio 2010\Projects\Win32Test\Debug\Win32Test.exe : fatal error LNK1120: 2 unresolved externals

Any ideas?

Check your defines for _WIN32_IE?

Needs to be defined >= 0x0400 for
TBSTYLE_SEP
TBSTYLE_BUTTON

You can do this in your Resource.h file

#define _WIN32_IE >= 0x0400

Also, Microsoft recommends using the CreateWindowEx over using the deprecated CreateToolbarEx. Use TOOLBARCLASSNAME in the second parameter with CreateWindowEx

I tried compiling the TOOLBAR using the CreateWindowEx function and was able to
make it work using similar headers to yours. Only I didn't use the hdrstop pragma and I included wingdi.h
I don't think that first suggestion I gave you will work.

But I looked into one of my resource.h header file I was using to compile
some of the controls with and this is what I found inside:

#define WINVER	    0x0501
#define _WIN32_WINNT	0x0501

I recall having some similar message a couple weeks ago. And after looking through the header files, I had found some defines and had to add these to get the status bar I was adding to compile. I think I was using some of the newer constants for the status bar display: SBARS_SIZEGRIP and they weren't recognized unless setting WINVER or _WIN32_WINNT to a higher version number.

I didn't use the IDE. I compiled straight from the command line using my own custom Makefile.

My darli, im lookin too for informations-guides about controls in C/C++
all controls in C/C++ created using CreateWindowEx? just you change name of parameter e?

Use TOOLBARCLASSNAME in the second parameter with CreateWindowEx

i would like to learn about all control, not only buttons and msgbox :) thats for nobs :)

lpClassName [in, optional]
Type: LPCTSTR

A null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero. If lpClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, provided that the module that registers the class is also the module that creates the window. The class name can also be any of the predefined system class names(MSDN 2010).

Here's a partial list. Apparently, there may be others since you can use the TOOLBARCLASSNAME constant in the second parameter for the second parameter.

But with the following you just need to enter this as a string value: e.g. "Button", "ComboBox", etc.:

Class Description
Button The class for a button.
ComboBox The class for a combo box.
Edit The class for an edit control.
ListBox The class for a list box.
MDIClient The class for an MDI client window.
ScrollBar The class for a scroll bar.
Static The class for a static control.

you missed comctl32.lib, add it to list of additional dependencies to the linker input or add #pragma comment(lib, "comctl32.lib") at the beggining of the file or in a header file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.