Thread: Tree-View Control

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    35

    Tree-View Control

    I'm developing a simple Window application which tries to use Tree-View Control (http://msdn.microsoft.com/library/de...w/treeview.asp).

    The main routines are (I don't write the full code because it would make the post a little bit unreadable):
    Code:
    hwndDialog = CreateDialog(GetModuleHandle(NULL), "DIALOG_0", hwnd, dialogProc);
    CreateATreeView(hwndDialog, "");
    ...
    ...
    HWND CreateATreeView(HWND hwndParent, LPSTR lpszFileName)
    {
        RECT rcClient;
        HWND hwndTreeView;
        
        InitCommonControls();
        GetClientRect(hwndParent, &rcClient);
    
        hwndTreeView = CreateWindowEx(
            0,
            WC_TREEVIEW,
            "Tree View",
            WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES, 
            0, 
            0, 
            rcClient.right, 
            rcClient.bottom,
            hwndParent, 
            (HMENU)ID_TREEVIEW, 
            hInstance, 
            NULL);
        
        return hwndTreeView;   
    }    
    
    BOOL InitTreeViewImageLists(HWND hwndTreeView)
    {
        HIMAGELIST himl;
        HICON hIcon;
        
        if ((himl = ImageList_Create(32, 32, FALSE, 2, 0)) == NULL) 
        return FALSE; 
        
        hIcon = LoadIcon(NULL, "folder.ico");
        if (hIcon==NULL) return FALSE;
        ImageList_AddIcon(himl, hIcon);
        
        hIcon = LoadIcon(NULL, "folder_closed.ico");
        if (hIcon==NULL) return FALSE;
        ImageList_AddIcon(himl, hIcon);
    
        TreeView_SetImageList(hwndTreeView, himl, TVSIL_NORMAL);
        
        return TRUE;
    }
    I'm using Dev-C++ 5.0 beta 9 (4.9.9.0) with Mingw/GCC 3.3.1.

    After including commctrl.h I tried to build de proyect and I got the following error:
    Code:
    Compilador: Default compiler
    Building Makefile: "C:\Mis C\treeviewcontrol01\Makefile.win"
    Ejecutando  make clean
    rm -f treeviewcontrol01.o wutil.o treeviewcontrol01_private.res treeviewcontrol01.exe
    gcc.exe -c treeviewcontrol01.c -o treeviewcontrol01.o -I"C:/Dev-Cpp/include"    -fexceptions -O3
    gcc.exe -c wutil.c -o wutil.o -I"C:/Dev-Cpp/include"    -fexceptions -O3
    windres.exe -i treeviewcontrol01_private.rc -I rc -o treeviewcontrol01_private.res -O coff 
    gcc.exe treeviewcontrol01.o wutil.o treeviewcontrol01_private.res -o "treeviewcontrol01.exe" -L"C:/Dev-Cpp/lib" -mwindows   
    treeviewcontrol01.o(.text+0x261):treeviewcontrol01.c: undefined reference to `InitCommonControls@0'
    treeviewcontrol01.o(.text+0x30d):treeviewcontrol01.c: undefined reference to `InitCommonControls@0'
    treeviewcontrol01.o(.text+0x3e1):treeviewcontrol01.c: undefined reference to `ImageList_Create@20'
    treeviewcontrol01.o(.text+0x421):treeviewcontrol01.c: undefined reference to `ImageList_ReplaceIcon@12'
    treeviewcontrol01.o(.text+0x455):treeviewcontrol01.c: undefined reference to `ImageList_ReplaceIcon@12'
    make.exe: *** [treeviewcontrol01.exe] Error 1
    Ejecución Terminada
    Somehow I concluded (I don't remember why, because I spent a lot of time trying and trying different things and reading tutorials and articles) that I had to add the comctl32.lib to the proyect. Was I right? I don't know. The first problem was that I had no idea about where I could find comctl32.lib. I searched my PC, just for trying, and since I got installed Microsoft Platform SDK (http://www.microsoft.com/msdownload/...sdk/sdkupdate/), I found out that comctl32.lib was in the "\Microsoft SDK\Lib" folder.

    After including comctl32.lib to my proyect I got the following errors:
    Code:
    Compilador: Default compiler
    Building Makefile: "C:\Mis C\treeviewcontrol01\Makefile.win"
    Ejecutando  make clean
    rm -f treeviewcontrol01.o wutil.o treeviewcontrol01_private.res treeviewcontrol01.exe
    gcc.exe -c treeviewcontrol01.c -o treeviewcontrol01.o -I"C:/Dev-Cpp/include"    -fexceptions -O3
    gcc.exe -c wutil.c -o wutil.o -I"C:/Dev-Cpp/include"    -fexceptions -O3
    windres.exe -i treeviewcontrol01_private.rc -I rc -o treeviewcontrol01_private.res -O coff
    gcc.exe treeviewcontrol01.o wutil.o treeviewcontrol01_private.res -o "treeviewcontrol01.exe" -L"C:/Dev-Cpp/lib" -mwindows "../../Archivos de programa/Microsoft SDK/Lib/ComCtl32.Lib"
    treeviewcontrol01.o(.text+0x3e1):treeviewcontrol01.c: undefined reference to `ImageList_Create@20'
    treeviewcontrol01.o(.text+0x421):treeviewcontrol01.c: undefined reference to `ImageList_ReplaceIcon@12'
    treeviewcontrol01.o(.text+0x455):treeviewcontrol01.c: undefined reference to `ImageList_ReplaceIcon@12'
    make.exe: *** [treeviewcontrol01.exe] Error 1
    Ejecución Terminada
    Then I said to myself that maybe I had to use the CommCtrl.h within the Platform SDK so I changed:
    Code:
    #include <commctrl.h>
    and I wrote:
    [code]#include "..\..\Archivos de programa\Microsoft SDK\include\CommCtrl.h"[code]
    ...and I got more and more errors:
    Code:
    Compilador: Default compiler
    Building Makefile: "C:\Mis C\treeviewcontrol01\Makefile.win"
    Ejecutando  make clean
    rm -f treeviewcontrol01.o wutil.o treeviewcontrol01_private.res treeviewcontrol01.exe
    gcc.exe -c treeviewcontrol01.c -o treeviewcontrol01.o -I"C:/Dev-Cpp/include"  -I"C:/Archivos de programa/Microsoft SDK/include"    -fexceptions -O3
    In file included from treeviewcontrol01.h:6,
                     from treeviewcontrol01.c:1:
    ../../Archivos de programa/Microsoft SDK/include/CommCtrl.h:352:1: warning: "CDN_FIRST" redefined
    In file included from C:/Dev-Cpp/include/windows.h:86,
                     from treeviewcontrol01.h:4,
                     from treeviewcontrol01.c:1:
    C:/Dev-Cpp/include/commdlg.h:27:1: warning: this is the location of the previous definition
    In file included from treeviewcontrol01.h:6,
                     from treeviewcontrol01.c:1:
    ../../Archivos de programa/Microsoft SDK/include/CommCtrl.h:353:1: warning: "CDN_LAST" redefined
    In file included from C:/Dev-Cpp/include/windows.h:86,
                     from treeviewcontrol01.h:4,
                     from treeviewcontrol01.c:1:
    C:/Dev-Cpp/include/commdlg.h:28:1: warning: this is the location of the previous definition
    In file included from treeviewcontrol01.h:6,
                     from treeviewcontrol01.c:1:
    ../../Archivos de programa/Microsoft SDK/include/CommCtrl.h:477:1: warning: "CLR_NONE" redefined
    In file included from C:/Dev-Cpp/include/windows.h:52,
                     from treeviewcontrol01.h:4,
                     from treeviewcontrol01.c:1:
    C:/Dev-Cpp/include/wingdi.h:772:1: warning: this is the location of the previous definition
    In file included from treeviewcontrol01.h:6,
                     from treeviewcontrol01.c:1:
    ../../Archivos de programa/Microsoft SDK/include/CommCtrl.h:478:1: warning: "CLR_DEFAULT" redefined
    In file included from C:/Dev-Cpp/include/windows.h:52,
                     from treeviewcontrol01.h:4,
                     from treeviewcontrol01.c:1:
    C:/Dev-Cpp/include/wingdi.h:774:1: warning: this is the location of the previous definition
    gcc.exe -c wutil.c -o wutil.o -I"C:/Dev-Cpp/include"  -I"C:/Archivos de programa/Microsoft SDK/include"    -fexceptions -O3
    windres.exe -i treeviewcontrol01_private.rc -I rc -o treeviewcontrol01_private.res -O coff
    gcc.exe treeviewcontrol01.o wutil.o treeviewcontrol01_private.res -o "treeviewcontrol01.exe" -L"C:/Dev-Cpp/lib" -mwindows "../../Archivos de programa/Microsoft SDK/Lib/ComCtl32.Lib"
    treeviewcontrol01.o(.text+0x3e2):treeviewcontrol01.c: undefined reference to `_imp__ImageList_Create@20'
    treeviewcontrol01.o(.text+0x427):treeviewcontrol01.c: undefined reference to `_imp__ImageList_ReplaceIcon@12'
    treeviewcontrol01.o(.text+0x45c):treeviewcontrol01.c: undefined reference to `_imp__ImageList_ReplaceIcon@12'
    make.exe: *** [treeviewcontrol01.exe] Error 1
    Ejecución Terminada
    What am I missing? Can't Tree-View control be used?

    As you can see by the length of my post, I'm going a little bit crazy. Any help would be wellcomed. Thanks in advance.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    If using MinGW(devcpp) then use its headers and libs; don't mix and match from different compilers as you'll almost certainly run into problems. For common controls, something like:
    Code:
    #if defined __MINGW_H
    #define _WIN32_IE 0x0400
    #endif
    #include <commctrl.h>
    ensures that most common controls and their associated structs and macros are available for use with MinGW (devcpp). You must also link with libcomctl32.a (-lcomctl32).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. Tree View control not appearing
    By Garfield in forum Windows Programming
    Replies: 1
    Last Post: 03-07-2004, 01:47 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM