Can't create toolbars

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
#include <Windows.h>
#include "resource.h"
#include <CommCtrl.h>

LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hprevInstance,LPSTR lpCmdLine,int nShowCmd)
{
	TCHAR AddCaption[40];
	MSG Msg;
	HWND HWnd;
	WNDCLASSEX WndClsEx;
	const int NUMBUTTONS = 3;
	HINSTANCE hInst = hInstance;
	LPCTSTR ClsName = TEXT("BasicApp");
	LPCTSTR WndName = TEXT("Cafeteria Shooting");

	LoadString(hInstance,IDS_APP_NAME,AddCaption,40);

	WndClsEx.cbSize = sizeof(WNDCLASSEX);
	WndClsEx.style = CS_HREDRAW || CS_VREDRAW;
	WndClsEx.cbClsExtra = 0;
	WndClsEx.cbWndExtra = 0;
	WndClsEx.lpszClassName = ClsName;
	WndClsEx.lpszMenuName = MAKEINTRESOURCE(IDR_MAINFRAME);
	WndClsEx.lpfnWndProc = WinProc;
	WndClsEx.hCursor = LoadCursor(hInstance,MAKEINTRESOURCE(IDC_CURSOR1));
	WndClsEx.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
	WndClsEx.hIconSm = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
	WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	WndClsEx.hInstance = hInstance;
	

	RegisterClassEx(&WndClsEx);
	
	HWnd = CreateWindowEx(0,ClsName,AddCaption,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);

	

	if(!HWnd)
		return 0;

	INITCOMMONCONTROLSEX InitCtrlEx;

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

	TBBUTTON tbrButtons[3];

	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 = 0;
	tbrButtons[1].idCommand = IDM_FILE_DICT;
	tbrButtons[1].fsState   = TBSTATE_ENABLED;
	tbrButtons[1].fsStyle   = TBSTYLE_BUTTON;
	tbrButtons[1].dwData    = 0L;
	tbrButtons[1].iBitmap   = 0;
	tbrButtons[1].iString   = 0;

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

	HWND HWndToolbar = CreateToolbarEx(HWnd,WS_CHILD || WS_VISIBLE || WS_BORDER,IDB_STANDARD,NUMBUTTONS,hInst,IDB_STANDARD,tbrButtons,NUMBUTTONS,16,16,16,16,sizeof(TBBUTTON));

	ShowWindow(HWnd,SW_SHOWNORMAL);
	UpdateWindow(HWnd);

	while(GetMessage(&Msg,NULL,0,0))
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}

	return Msg.wParam;
}

LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	switch(uMsg)
	{
	case WM_DESTROY:
		PostQuitMessage(WM_QUIT);
		break;
	default:
		return DefWindowProc(hWnd,uMsg,wParam,lParam);
	}

	return 0;
}


Line 52,60,68 said IDM_FILE_NEW,IDM_FILE_DICT,IDM_FILE_CALC are undefined although I put them in the string tables.So the IDB_STANDARD.

But the worst thing is the toolbar didn't show.

Could sb help me with this ? Thanks in advance.
Last edited on
After re-looking,I got this :

WS_CHILD || WS_VISIBLE || WS_BORDER

is wrong,must be : (according to the tutorial) :

WS_CHILD | WS_VISIBLE | WS_BORDER

Whats the difference between these two, OR-ing or sth ?
I also found out some bug and fixed,here's the final program :

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
#include <Windows.h>
#include "resource.h"
#include <CommCtrl.h>

LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hprevInstance,LPSTR lpCmdLine,int nShowCmd)
{
	TCHAR AddCaption[40];
	MSG Msg;
	HWND HWnd;
	WNDCLASSEX WndClsEx;
	const int NUMBUTTONS = 3;
	HINSTANCE hInst = hInstance;
	LPCTSTR ClsName = TEXT("BasicApp");
	LPCTSTR WndName = TEXT("Cafeteria Shooting");

	LoadString(hInstance,IDS_APP_NAME,AddCaption,40);

	WndClsEx.cbSize = sizeof(WNDCLASSEX);
	WndClsEx.style = CS_HREDRAW || CS_VREDRAW;
	WndClsEx.cbClsExtra = 0;
	WndClsEx.cbWndExtra = 0;
	WndClsEx.lpszClassName = ClsName;
	WndClsEx.lpszMenuName = MAKEINTRESOURCE(IDR_MAINFRAME);
	WndClsEx.lpfnWndProc = WinProc;
	WndClsEx.hCursor = LoadCursor(hInstance,MAKEINTRESOURCE(IDC_CURSOR1));
	WndClsEx.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
	WndClsEx.hIconSm = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
	WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	WndClsEx.hInstance = hInstance;
	

	RegisterClassEx(&WndClsEx);
	
	HWnd = CreateWindowEx(0,ClsName,AddCaption,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);

	

	if(!HWnd)
		return 0;

	INITCOMMONCONTROLSEX InitCtrlEx;

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

	TBBUTTON tbrButtons[3];

	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].iString   = 0;

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

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

	HWND HWndToolbar = CreateToolbarEx(HWnd,WS_CHILD | WS_VISIBLE | WS_BORDER,IDB_STANDARD,NUMBUTTONS,hInst,IDB_STANDARD,tbrButtons,NUMBUTTONS,16,16,16,16,sizeof(TBBUTTON));

	ShowWindow(HWnd,SW_SHOWNORMAL);
	UpdateWindow(HWnd);

	while(GetMessage(&Msg,NULL,0,0))
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}

	return Msg.wParam;
}

LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	switch(uMsg)
	{
	case WM_DESTROY:
		PostQuitMessage(WM_QUIT);
		break;
	default:
		return DefWindowProc(hWnd,uMsg,wParam,lParam);
	}

	return 0;
}


I still need explanation on my 2nd post here.Thanks for reading.
|| = Boolean OR operator
| = Bitwise OR operator

Google can fill in the blanks. Basically you need to know what bitwise is and what Boolean is. Once you know, the above will just make sense.
Topic archived. No new replies allowed.