在对话框中建立一个trackbar
我添加了头文件和导入了lib库,可是还是出现错误,不知道怎么解决。我给出部分代码#include <commctrl.h>
#pragma   comment(lib,"comctl32.lib") int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{
MSG msg;
HWND hDlg;
hIns=hInstance;
hDlg=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DLG),NULL,
(DLGPROC)DialogFunc);
HWND hwndTrack;

INITCOMMONCONTROLSEX cc;
cc.dwICC=ICC_BAR_CLASSES;
cc.dwSize=sizeof(INITCOMMONCONTROLSEX);
    InitCommonControls(&cc); // loads common control's DLL     hwndTrack = CreateWindowEx( 
        0,                             // no extended styles 
        TRACKBAR_CLASS,                // class name 
        "Trackbar Control",            // title (caption) 
        WS_CHILD | WS_VISIBLE | 
        TBS_AUTOTICKS | TBS_ENABLESELRANGE,  // style 
        10, 300,                        // position 
        200, 22,                       // size 
        hDlg,                       // parent window 
        (HMENU)ID_TRACKBAR,             // control identifier 
        hIns,                       // instance 
        NULL                           // no WM_CREATE parameter 
        ); 

ShowWindow(hDlg,SW_SHOWNORMAL);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}错误提示是
--------------------配置: MinGW3.4.5 - GUI Debug, 编译器类型: MinGW--------------------检查文件依赖性...
正在编译 C:\Documents and Settings\Administrator\My Documents\C-Free\Projects\mp_05\mp_01.cpp...
[Error] C:\Documents and Settings\Administrator\My Documents\C-Free\Projects\mp_05\mp_01.cpp:75: error: `INITCOMMONCONTROLSEX' was not declared in this scope
[Error] C:\Documents and Settings\Administrator\My Documents\C-Free\Projects\mp_05\mp_01.cpp:75: error: expected `;' before "cc"
[Error] C:\Documents and Settings\Administrator\My Documents\C-Free\Projects\mp_05\mp_01.cpp:76: error: `cc' was not declared in this scope构建中止 mp_01: 3 个错误

解决方案 »

  1.   

    INITCOMMONCONTROLSEX 不识别这个类型,包含相关的头文件
      

  2.   

    MSDN的定义如下
    typedef struct tagINITCOMMONCONTROLSEX {
        DWORD dwSize;
        DWORD dwICC;
    } INITCOMMONCONTROLSEX, *LPINITCOMMONCONTROLSEX;
      

  3.   

    包含上windows 头文件,如下代码(示例)在vc6  下编译通过了#include <windows.h>
    #include <commctrl.h>
    #include "resource.h"
    // #pragma   comment(lib,"comctl32.lib") 
    int WINAPI DialogFunc(HWND wnd, UINT uMsg, WPARAM wp, LPARAM lp);
    #define ID_TRACKBAR 1
    int WINAPI WinMain(
       HINSTANCE hInstance,      // handle to current instance
       HINSTANCE hPrevInstance,  // handle to previous instance
       LPSTR lpCmdLine,          // command line
       int nCmdShow              // show state
       )
    {
        MSG msg;
        HWND hDlg;
        HINSTANCE hIns=hInstance;
        hDlg=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DLG),NULL,
    (DLGPROC)DialogFunc);
        HWND hwndTrack;
        
        INITCOMMONCONTROLSEX cc;
        cc.dwICC=ICC_BAR_CLASSES;
        cc.dwSize=sizeof(INITCOMMONCONTROLSEX);
        InitCommonControls(); // loads common control's DLL 

        hwndTrack = CreateWindowEx( 
            0,                             // no extended styles 
            TRACKBAR_CLASS,                // class name 
            "Trackbar Control",            // title (caption) 
            WS_CHILD | WS_VISIBLE | 
            TBS_AUTOTICKS | TBS_ENABLESELRANGE,  // style 
            10, 300,                        // position 
            200, 22,                       // size 
            hDlg,                       // parent window 
            (HMENU)ID_TRACKBAR,             // control identifier 
            hIns,                       // instance 
            NULL                           // no WM_CREATE parameter 
            ); 
        
        ShowWindow(hDlg,SW_SHOWNORMAL);
        while(GetMessage(&msg,NULL,0,0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        return 0;
    }int WINAPI DialogFunc(HWND wnd, UINT uMsg, WPARAM wp, LPARAM lp)
    {
    return true;
    }