遮天 发表于 2014-5-24 19:58:49

我把甲鱼老师的代码自己敲了一下,结果出错了,帮我找一下,谢谢

错误提示:错误        1        error LNK2019: 无法解析的外部符号 "long __stdcall WinProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WinProc@@YGJPAUHWND__@@IIJ@Z),该符号在函数 _WinMain@16 中被引用        C:\Users\1065609785\Desktop\作业\Windows\Win32Project1\Mywindows1\main.obj        Mywindows1
错误        2        error LNK1120: 1 个无法解析的外部命令        C:\Users\1065609785\Desktop\作业\Windows\Win32Project1\Debug\Mywindows1.exe        1        1        Mywindows1


#include<windows.h>
LRESULT CALLBACK WinProc(HWND , UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, intiCmdShow)
{
        static TCHAR szAPPName[] = TEXT("我的第一个窗口");
        HWND hwnd;
        MSG msg;
        WNDCLASS wndclass;
        wndclass.style = CS_VREDRAW | CS_HREDRAW;
        wndclass.lpfnWndProc = WinProc;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 0;
        wndclass.hInstance = hInstance;
        wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
        wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
        wndclass.lpszMenuName = NULL;
        wndclass.lpszClassName = szAPPName;

        if (!RegisterClass(&wndclass))
        {
                MessageBox(NULL, TEXT("这个只能在windowsNT才能用"), szAPPName, MB_ICONINFORMATION);
                return 0;
        }

        hwnd = CreateWindow(szAPPName,
                TEXT("3#105"),
                WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                NULL,
                NULL,
                hInstance,
                NULL
                );
        ShowWindow( hwnd, iCmdShow);
        UpdateWindow(hwnd);

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

        return msg.wParam;

}   
LRESULT CALLBACK WndProc(HWND hwnd,UINT message , WPARAM wparam,LPARAM lparam )
{
        HDC hdc;
        PAINTSTRUCT ps;
        RECT rect;


        switch (message)
        {
        case WM_PAINT:
                hdc = BeginPaint(hwnd ,&ps);
                GetClientRect(hwnd ,&rect);
                DrawText(hdc, TEXT("这是第一个窗口"), -1, &rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
                EndPaint(hwnd,&ps);
                return 0;
        case WM_DESTROY:
               PostQuitMessage(0);
                return0;
        }
        return DefWindowProc(hwnd, message, wparam, lparam);
}

mmic 发表于 2014-5-24 20:57:02

rmb788520 发表于 2014-5-24 22:31:18

本帖最后由 rmb788520 于 2014-5-24 22:32 编辑

#include<windows.h>

LRESULT CALLBACK WinProc(HWND , UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
{
      static TCHAR szAPPName[] = TEXT("我的第一个窗口");
      HWND hwnd;
      MSG msg;
      WNDCLASS wndclass;

      wndclass.style = CS_VREDRAW | CS_HREDRAW;
      wndclass.lpfnWndProc = WinProc;
      wndclass.cbClsExtra = 0;
      wndclass.cbWndExtra = 0;
      wndclass.hInstance = hInstance;
      wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
      wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
      wndclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
      wndclass.lpszMenuName = NULL;
      wndclass.lpszClassName = szAPPName;

      if (!RegisterClass(&wndclass))
      {
                MessageBox(NULL, TEXT("这个只能在windowsNT才能用"), szAPPName, MB_ICONINFORMATION);
                return 0;
      }

      hwnd = CreateWindow(szAPPName,
                TEXT("3#105"),
                WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                NULL,
                NULL,
                hInstance,
                NULL
                );
      ShowWindow( hwnd, iCmdShow);
      UpdateWindow(hwnd);

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

      return msg.wParam;

}   
LRESULT CALLBACK WinProc(HWND hwnd,UINT message , WPARAM wparam,LPARAM lparam )   //名字错了
{
      HDC hdc;
      PAINTSTRUCT ps;
      RECT rect;


      switch (message)
      {
      case WM_PAINT:
                hdc = BeginPaint(hwnd ,&ps);
                GetClientRect(hwnd ,&rect);
                DrawText(hdc, TEXT("这是第一个窗口"), -1, &rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
                EndPaint(hwnd,&ps);
                return 0;
      case WM_DESTROY:
               PostQuitMessage(0);
                return0;
      }
      return DefWindowProc(hwnd, message, wparam, lparam);
}

更正完毕。
这种情况。如果 建立(bulid) 没有问题,但运行出错。。请把代码复制。重新新建一个win32Application 粘贴代码再建立-->运行 就可以了

遮天 发表于 2014-5-25 13:53:49

rmb788520 发表于 2014-5-24 22:31 static/image/common/back.gif
#include

LRESULT CALLBACK WinProc(HWND , UINT,WPARAM,LPARAM);


谢谢.刚接触windows编程,把winproc敲成wndproc了,

viincy 发表于 2014-5-26 20:18:58

同是菜鸟。。共勉之。。。{:7_182:}

智商是硬伤 发表于 2015-8-19 07:57:22

{:7_146:}
页: [1]
查看完整版本: 我把甲鱼老师的代码自己敲了一下,结果出错了,帮我找一下,谢谢