2013-12-14 60 views
0

我想在控制台应用程序中使用ChooseColor函数。 http://msdn.microsoft.com/en-us/library/windows/desktop/ms646912(v=vs.85).aspx使用windows.h时未定义的引用

我使用他们的示例代码来测试它,我已经包括WINDOWS.H像他们告诉我,但我得到的错误:

undefined reference to '[email protected]' 
undefined reference to '[email protected]' 

我使用的代码::块,我试过包括“Windows.h”和“Commdlg.h”,但没有运气。我是否需要使用链接器设置才能使用windows.h?我的代码:

#include <windows.h> 

int main() 
{ 
    CHOOSECOLOR cc;     // common dialog box structure 
    static COLORREF acrCustClr[16]; // array of custom colors 
    HWND hwnd;      // owner window 
    HBRUSH hbrush;     // brush handle 
    static DWORD rgbCurrent;  // initial color selection 

    // Initialize CHOOSECOLOR 
    ZeroMemory(&cc, sizeof(cc)); 
    cc.lStructSize = sizeof(cc); 
    cc.hwndOwner = hwnd; 
    cc.lpCustColors = (LPDWORD) acrCustClr; 
    cc.rgbResult = rgbCurrent; 
    cc.Flags = CC_FULLOPEN | CC_RGBINIT; 

    if (ChooseColor(&cc)==TRUE) 
    { 
     hbrush = CreateSolidBrush(cc.rgbResult); 
     rgbCurrent = cc.rgbResult; 
    } 
    return 0; 
} 
+0

看看这些功能的文档。它应该说:*库:gdi32.lib *和*库:comdlg32.lib *。是的,链接是一件好事。编译windows.h会花费比编译时间长得多的时间。 – chris

+1

还要注意,您正在错误地测试ChooseColor的结果。请仔细阅读文档。 –

+1

打算在控制台应用程序中使用画笔做什么? –

回答