Click to See Complete Forum and Search --> : Problem with commctrl.h


wish2hate
February 15th, 2009, 04:58 PM
Hi, I'm new to win32 api I have a simple program that I wish to compile and test see how progress bar works. Yet even I included commctrl.h it seems still will not compile.

I read couple forums that people says once they make this project under win32 smart device project it will work. I tried but I have trouble creating a win32 smart device project.

I went to File->New->Project->smart device->win32smart device project, after I enter name I clicked create but the same window just pop to me over and over again. Is this not the way to create smart device project?

So my questions are:
1. How do I make this piece of code work?
2. How to create win32 smart device project?
3. I heard people mentioned commctrl.h is for CE only what does CE stand for?


#include <windows.h>
#include <commctrl.h>
#include "stdafx.h"

#define ID_BUTTON 1
#define ID_TIMER 2

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE g_hinst;


int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

HWND hwnd;
MSG msg ;
WNDCLASS wc = {0};
wc.lpszClassName = TEXT("Application");
wc.hInstance = hInstance ;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc ;
wc.hCursor = LoadCursor(0,IDC_ARROW);

g_hinst = hInstance;

RegisterClass(&wc);
hwnd = CreateWindow(wc.lpszClassName, TEXT("Progress bar"),
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100, 260, 170, 0, 0, hInstance, 0);


while( GetMessage(&msg, NULL, 0, 0)) {
DispatchMessage(&msg);
}
return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

static HWND hwndPrgBar;
static int i = 1;

INITCOMMONCONTROLSEX InitCtrlEx;

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

switch(msg)
{
case WM_CREATE:
hwndPrgBar = CreateWindowEx(0, PROGRESS_CLASS, NULL,
WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
30, 20, 190, 25, hwnd, NULL, g_hinst, NULL);

CreateWindow(TEXT("button"), TEXT("Start"),
WS_CHILD | WS_VISIBLE,
85, 90, 80, 25, hwnd, (HMENU) 1, g_hinst, NULL);

SendMessage(hwndPrgBar, PBM_SETRANGE, 0, MAKELPARAM(0, 150));
SendMessage(hwndPrgBar, PBM_SETSTEP, 1, 0 );
break;


case WM_TIMER:
SendMessage( hwndPrgBar, PBM_STEPIT, 0, 0 );
i++;
if ( i == 150 )
KillTimer(hwnd, ID_TIMER);
break;

case WM_COMMAND:
i = 1;
SendMessage( hwndPrgBar, PBM_SETPOS, 0, 0 );
SetTimer(hwnd, ID_TIMER, 5, NULL);
break;

case WM_DESTROY:
KillTimer(hwnd, ID_TIMER);
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}

JohnCz
February 16th, 2009, 09:45 PM
Has it ever crossed your mind to place all header files after stdafx.h?

Do it and recompile.

Now just for demonstration:
type any raw text before stdafx.h. do not comment it. Compile again and see if anything happens.

ANyway, why "wish to hate"?

wish2hate
February 17th, 2009, 02:21 AM
Yes, tried that still won't compile but now i realized it was because common control header wasn't added. Now that I included the common control header I received something really weird!

"error LNK2019: unresolved external symbol _imp_InitCommonControlsEx@4 referenced in function "long_stdcall WndProc(struct HWND_*, unsigned int, unsigned int, long)" (?WndPRoc@@YGJPAUHWND_@@IIJ@Z)

fatal error LNK1120: 1 unresolved externals"

any clue how to solve this problem and make it compile?

Respond to your question, why "wish to hate"...
wish2hate = I wish to hate you guys but I can't.... means I love you guys no matter what =P
it's a screen name i've been using ever since 10 years+ ago, just too late to change it to something new. I got in trouble once with wikipedia caz they just won't accept this name (it sounds like hater?) lol

Notsosuperhero
February 17th, 2009, 04:31 AM
You need to link to the comctl32.lib library

JohnCz
February 17th, 2009, 08:54 PM
Despite a fact that a header was missing you had to move all #include after stdafx.h if you use precompiled headers. Did you?

wish2hate
February 17th, 2009, 09:26 PM
You need to link to the comctl32.lib library

May I ask where can I find comctl32.lib? I included cmmctrl.h path and recieved those errors.

And to JohnCz, wat header exactly do I need? and No you don't have to place all headers after stdafx.h. The only thing matters is (this is what I heard) you need to include window.h before common control header

Rasble
February 17th, 2009, 09:43 PM
Perhaps in lib folder of your installed VSIDE
add #pragma comment(lib,"comctl32.lib") below the #include of your code.

Notsosuperhero
February 18th, 2009, 03:49 AM
You will get the linker errors if you include the header but not the library. The header contains declarations, the library contains the actual implementation of the functions.

comctl32.lib should reside inside the lib folder of the Platform SDK folder, for example mine is:

C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib
This is with Visual Studio 2005 Standard so it may be a little different with 2008 and Express Edition.

If you can link to the windows stuff, and include windows.h you're compiler should be set up already, since comctl32.lib is part of the Platform SDK.