开发者

HWND variable defined in global scope breaks compilation

开发者 https://www.devze.com 2023-03-30 17:38 出处:网络
For some reason when I declare my control in global scope my appication will not compile. When I declare the variable inline everything is fine. The following will not compile:

For some reason when I declare my control in global scope my appication will not compile. When I declare the variable inline everything is fine. The following will not compile:

 //Global
    HWND hEdit;

    ...

    case WM_CREATE:
            {
                // Create an edit box
                 hEdit= CreateWindowEx(WS_EX_CLIENTEDGE,
                    "EDIT",
                    "",
                    WS_CHILD|WS_VISIBLE|
                    ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
                    50,
                    100,
                    200,
                    100,
                    hwnd,
                    (HMENU)IDC_MAIN_EDIT,
开发者_运维问答                    GetModuleHandle(NULL),
                    NULL);
                HGDIOBJ hfDefault = GetStockObject(DEFAULT_GUI_FONT);

...

}
break;

The following will not compile. The error is:

'HGDIOBJ' : illegal use of this type as an expression

However if I define hEdit inline within my switch this error goes away.

So this will compile:

 case WM_CREATE:
        {
            // Create an edit box
            HWND hEdit= CreateWindowEx(WS_EX_CLIENTEDGE,
                "EDIT",
                "",
                WS_CHILD|WS_VISIBLE|
                ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
                50,
                100,
                200,
                100,
                hwnd,
                (HMENU)IDC_MAIN_EDIT,
                GetModuleHandle(NULL),
                NULL);
            HGDIOBJ hfDefault = GetStockObject(DEFAULT_GUI_FONT);
...

} break;

I must be overlooking something simple but I cannot find it. Can someone tell me what I'm overlooking?

Thanks


Argg... I named this file with a .c rather than a .cpp

Not sure why they would result in the problem I was seeing but I noticed I was getting an 'undeclared identifier' error as well. Renaming the file did the trick. I think I'll call it a night :)

Thanks for the comments and replies.


Is your global variable by any chance declared before the #include?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号