CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2009
    Posts
    11

    Problem with commctrl.h

    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);
    }

  2. #2
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Problem with commctrl.h

    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"?
    Last edited by JohnCz; February 18th, 2009 at 12:15 AM. Reason: Missing tag
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  3. #3
    Join Date
    Jan 2009
    Posts
    11

    Re: Problem with commctrl.h

    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

  4. #4
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    Re: Problem with commctrl.h

    You need to link to the comctl32.lib library
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

  5. #5
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Problem with commctrl.h

    Despite a fact that a header was missing you had to move all #include after stdafx.h if you use precompiled headers. Did you?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  6. #6
    Join Date
    Jan 2009
    Posts
    11

    Re: Problem with commctrl.h

    Quote Originally Posted by Notsosuperhero View Post
    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

  7. #7
    Join Date
    Feb 2009
    Posts
    8

    Re: Problem with commctrl.h

    Perhaps in lib folder of your installed VSIDE
    add #pragma comment(lib,"comctl32.lib") below the #include of your code.
    It's the origin of W on earth -Rasble

  8. #8
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    Re: Problem with commctrl.h

    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:
    Code:
    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.
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured