注册 登录
编程论坛 VC++/MFC

大吓们帮忙看下,这个api窗口错误在哪里,帮我改下谢谢!

hg2625811 发布于 2012-03-11 14:59, 758 次点击
#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK WinSunProc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
);

int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
    wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
    wndcls.hInstance=hInstance;
    wndcls.lpfnWndProc=WinSunProc;
    wndcls.lpszClassName="Weixin2003";
    wndcls.lpszMenuName=NULL;
    wndcls.style=CS_HREDRAW | CS_VREDRAW;
    RegisterClass(&wndcls);

    HWND hwnd;
    hwnd=CreateWindow("Weixin2003","我日日日日日日日",WS_OVERLAPPEDWINDOW,
        0,0,600,400,NULL,NULL,hInstance,NULL);

    ShowWindow(hwnd,SW_SHOWNORMAL);
    UpdateWindow(hwnd);

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

LRESULT CALLBACK WinSunProc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
)
{
    switch(uMsg)
    {
    case WM_CHAR:
        char szChar[20];
        sprintf(szChar,"char is %d",wParam);
        MessageBox(hwnd,szChar,"weixin",0);
        break;
    case WM_LBUTTONDOWN:
        MessageBox(hwnd,"mouse clicked","weixin",0);
        HDC hdc;
        hdc=GetDC(hwnd);
        TextOut(hdc,0,50,"我的神啊",strlen("我的神啊"));
        ReleaseDC(hwnd,hdc);
        break;
    case WM_PAINT:
        HDC hDC;
        PAINTSTRUCT ps;
        hDC=BeginPaint(hwnd,&ps);
        TextOut(hDC,0,0,"电脑专卖",strlen("电脑专卖"));
        EndPaint(hwnd,&ps);
        break;
    case WM_CLOSE:
        if(IDYES==MessageBox(hwnd,"我晕?","weixin",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return 0;
};
不知道错在哪里,提示为
--------------------Configuration: 0 - Win32 Debug--------------------
Compiling...
0.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/0.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

0.exe - 2 error(s), 0 warning(s)
6 回复
#2
hg26258112012-03-11 15:24
没有人帮我看下吗?
还是我的问题太幼稚了。
#3
Vincent_CZW2012-03-11 23:16
这是建立VC程序的错误,Win32Aplication程序和Win32ConsoleApplication程序的区别。
可以看看这个http://apps.hi.baidu.com/share/detail/23326076
#4
yuccn2012-03-12 09:38
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
就这句,应该你是在一个cui程序中写了一个gui程序,
也就是说你在一个控台程序中来写一个窗口应用程序程序。重新建立个工程吧,或者你也可以在配置里面改,就是有点点的麻烦而已。

在新建工程中记得要选win32 项目 而非win32控台程序
如下:
只有本站会员才能查看附件,请 登录
#5
BianChengNan2012-03-12 10:04
楼主看来是建错工程了,楼上正解。我也遇到过,我baidu,google然后解决了,而且我有额外的收获,楼主加油哦
#6
hg26258112012-03-12 10:51
谢谢了
让我们一起加油吧
#7
donggegege2012-03-13 11:04
这个我以前也遇到过,不过好像你关闭后,重新打开还是可以运行的。
1