Creating Menus in Win32 Programming

I am new to Win32 programming and I have been working with a tutorial from a website which teaches the basics of Windows Programming through Win32... I have covered many of the chapters and everything is going almost fine... However there is a little problem I am facing... This tutorial teaches building toolbars through resources. (Below lies the Main,cpp code.) This thins is working fine except that the menus are old style... Windows98 format... I am using Visual Studio 2005 and I want my toolbars to look like standard XP and all...
Here is the Main.cpp Code!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//---------------------------------------------------------------------------
#include <windows.h>
#include <commctrl.h>
#include "resource.h"

//---------------------------------------------------------------------------
char AppCaption[40];
HINSTANCE hInst;
const int NUMBUTTONS = 7;
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;
    LPCTSTR ClsName = L"ResFund";

	LoadString(hInstance, IDS_APP_NAME, AppCaption, 40);

	hInst = hInstance;

	// 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_RESFUND2));
	WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
	WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	WndClsEx.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINFRAME);
	WndClsEx.lpszClassName = ClsName;
	WndClsEx.hInstance     = hInst;
	WndClsEx.hIconSm       = LoadIcon(hInstance,
					  MAKEINTRESOURCE(IDI_RESFUND2));

	// 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

	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_STANDARD,
	                              NUMBUTTONS,
				      hInst,
			              IDB_STANDARD,
				      tbrButtons,
				      NUMBUTTONS,
				      16, 16, 16, 16,
				      sizeof(TBBUTTON));

	// Display the window to the user
	ShowWindow(hWnd, nCmdShow);
	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 0;
}
//---------------------------------------------------------------------------
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;
}
//--------------------------------------------------------------------------- 


First of all I need help about where menus are being created and what defines how are they going to look like? Secondly, please explain to me what if I have built the resource bitmap for toolbar like whatever I want but I need to give it an XP look, with my own specification of size of buttons? Please explain in detail. I shall be very thankful...
There is one thing I must mention... In the very start the tutorial teaches to include the ComCtl32.lib file in the project. I need to know if it is the specific file which determines the visuals of the toolbar?
Thanks a lot Bazzy! But I visited MSDN several times before. There's nothing there for beginner. I couldn't grasp many things from there... Could you provide another option please?

Many Thanks.
Hey! I read that but it's all BLA BLA BLA? I couldn't understand a single phrase...
My query is: When I use this function in C++ MessageBox(NULL,"Message Box","Title",MB_OK|MB_INFORMATION)
in C++, I get a message box with Win9x style...
When I use a similiar function in the same version of VB,
MessageBox("Message Box","Title",MessageBox.Style.VBInformation, VBOKOnly)
I get a message box whcih has pure WinXP theme...

How to do that VB trick in C++...?
Last edited on
Is not just word, it says:
- create a file called manifest.xml and gives the contents that it should have
- add it to the resources of the program with 24 as resource type
- call the function InitCommonControls() to use the XP style
after that all of your controls would have the new style on XP and Vista
Is it that simple? Ok thanks a lot buddy! I shall try.
Hi madmaxsanta, I totaly new to the ideas of Visual C++ can you pass me a link to that tutorial that teaches the basics of Windows Programming through Win32?

Thanks alot!
> can you pass m a link to that tutorial that teaches the basics of Windows Programming through Win32?

Read Petzold and MSDN
@ everlearnin

Hi there!

http://www.functionx.com/win32/index.htm
That's the only one I have for now. Will keep you updated if I come across a new one. Take care!

Good Hunting pal!
Last edited on
Topic archived. No new replies allowed.