Issues initializing common controls

I'm trying to make a toolbar with the winAPI, but I keep getting this weird error message:

error: `INITCOMMONCONTROLSEX' was not declared in this scope

Yes, I have included commctrl.h and linked to comctl32.a

Does anyone know why it won't work?
Doesn't anyone know? I can't find the error on Google...
show us your code.

windows programming.
I know INITCOMMONCONTROLSEX is a structure that is declaredin commctrl.h and you
need to pass a pointer of that type to the InitCommonControlsEx function.

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
#include <windows.h>
#include <shlwapi.h>//for the open file dialog
#include <commctrl.h>//MSDN documentation says that INITCOMMONCONTROLSEX is declared here

int WINAPI WinMain(HINSTANCE hinst,HINSTANCE hprev,LPSTR cmdline,int cmdshow){
	//variable declaration
	WNDCLASSEX wndclass;
	HWND hwnd;
	MSG msg;
	//register the class
	wndclass.cbSize=sizeof(WNDCLASSEX);
	wndclass.style=0;
	wndclass.lpfnWndProc=piproc;
	wndclass.cbClsExtra=0;
	wndclass.cbWndExtra=0;
	wndclass.hInstance=hinst;
	wndclass.hIcon=(HICON)LoadImage(hinst,MAKEINTRESOURCE(MAINICON),IMAGE_ICON,48,48,0);
	wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
	wndclass.hbrBackground=(HBRUSH)GetStockObject(LTGRAY_BRUSH);
	wndclass.lpszMenuName=MAKEINTRESOURCE(PIPAINT_MENU);
	wndclass.lpszClassName="PiPaint";
	wndclass.hIconSm=(HICON)LoadImage(hinst,MAKEINTRESOURCE(MAINICON),IMAGE_ICON,16,16,0);
	if(!RegisterClassEx(&wndclass)){
		MessageBox(0,"ERROR: Window registration failed","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return 1;}
	//create the window
	if((hwnd=CreateWindow("PiPaint","PiPaint",WS_OVERLAPPEDWINDOW,
	CW_USEDEFAULT,CW_USEDEFAULT,640,480,NULL,NULL,hinst,NULL))==NULL){
		MessageBox(0,"ERROR: Window creation failed","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return 2;}
	ShowWindow(hwnd,cmdshow);
	UpdateWindow(hwnd);
	InvalidateRect(hwnd,NULL,true);
	//inititialize common controls
	//vvv This is apparently not declared, even though MSDN documentation says it is in commctrl.h
	INITCOMMONCONTROLSEX icex;
	icex.dwSize=sizeof(INITCOMMONCONTROLSEX);
	icex.dwICC=ICC_BAR_CLASSES;
	InitCommonControlsEx(&icex);
	//main loop
	while(GetMessage(&msg,NULL,0,0)){
		TranslateMessage(&msg);
		DispatchMessage(&msg);}
	return msg.wParam;}


Here it is
Last edited on
You have to #define _WIN32_IE 0x301 // (or any number larger that 0x300 ) before you include windows.h
It finally compiled! Thanks!
Topic archived. No new replies allowed.