首页 新闻 赞助 找找看

win32编程

0
悬赏园豆:5 [待解决问题]

用dev-c++写win32程序时出现undefined reference to "winmain"怎么解决?

问题补充:

ifndef UNICODE

define UNICODE

endif

include <windows.h>

include <stdlib.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";

WNDCLASS wc = { };

wc.lpfnWndProc   = WindowProc;
wc.hInstance	 = hInstance;
wc.lpszClassName = CLASS_NAME;

RegisterClass(&wc);

// Create the window.

HWND hwnd = CreateWindowEx(
    0,                              // Optional window styles.
    CLASS_NAME,                     // Window class
    L"Learn to Program Windows",    // Window text
    WS_OVERLAPPEDWINDOW,            // Window style

    // Size and position
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

    NULL,       // Parent window    
    NULL,       // Menu
    hInstance,  // Instance handle
    NULL        // Additional application data
    );

if (hwnd == NULL)
{
    return 0;
}

ShowWindow(hwnd, nCmdShow);

// Run the message loop.

MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

return 0;

}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;

case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);



        FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));

        EndPaint(hwnd, &ps);
    }
    return 0;

}
return DefWindowProc(hwnd, uMsg, wParam, lParam);

}
这是全部代码

andor_not的主页 andor_not | 初学一级 | 园豆:199
提问于:2020-12-08 22:40

建议把代码粘出来

Conan-jine 3年前
< >
分享
所有回答(1)
1

如果你写的是windows程序,入口函数是
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
而不是
int main()

这个是windows程序需要注意的

2012 | 园豆:21228 (高人七级) | 2020-12-09 08:07

你这问题定位是对的,所以你的解决方法是?

支持(0) 反对(0) andor_not | 园豆:199 (初学一级) | 2020-12-09 12:30

@andor_not: 如果是WIN32编程,你可以安装VC建个工程对照下,dev-c++可能是存在差别的
涉及的点
1 unicode模式
2 链接时windows库的设置

支持(0) 反对(0) 2012 | 园豆:21228 (高人七级) | 2020-12-09 16:51

@2012: 我再其它论坛中找到的解决方法是,再dev-c++中的编译器配置中加入-c命令就能解决这个问题,但又有新问题产生,可正常编译但运行不了,弹窗提示“不支持的16位应用程序”

支持(0) 反对(0) andor_not | 园豆:199 (初学一级) | 2020-12-09 22:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册