| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1850 人关注过本帖
标题:自己写了个练习类的代码,出现了连接错误,请各位大侠帮忙,在下感激不尽!!
只看楼主 加入收藏
纯黑色
Rank: 1
等 级:新手上路
帖 子:347
专家分:0
注 册:2009-4-16
结帖率:91.43%
收藏
已结贴  问题点数:0 回复次数:4 
自己写了个练习类的代码,出现了连接错误,请各位大侠帮忙,在下感激不尽!!
错误:Compiling...
winmain.cpp
Linking...
winmain.obj : error LNK2001: unresolved external symbol "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
Debug/cash.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错
.
代码如下:请各位帮忙啊,在下感激不尽!~
#include <windows.h>
//#include <windef.h>
#include <stdio.h>
class create
{
public:
    BOOL CreateWindow2(         
                        LPCTSTR lpClassName,
                        LPCTSTR lpWindowName,
                        DWORD dwStyle,
                        int x,
                        int y,
                        int nWidth,
                        int nHeight,
                        HWND hWndParent,
                        HMENU hMenu,
                        HINSTANCE hInstance,
                        LPVOID lpParam
                    );
    BOOL ShowWindow2(
                      //HWND hWnd,
                      int nCmdShow
                    );
    BOOL UpdateWindow2(
                    //HWND hWnd   // handle to window
                    );
public:
    HWND hWnd2;

};
//.....................................................................
BOOL create::CreateWindow2(         
                        LPCTSTR lpClassName,
                        LPCTSTR lpWindowName,
                        DWORD dwStyle,
                        int x,
                        int y,
                        int nWidth,
                        int nHeight,
                        HWND hWndParent,
                        HMENU hMenu,
                        HINSTANCE hInstance,
                        LPVOID lpParam
                    )
{
    hWnd2=::CreateWindow(lpClassName,lpWindowName,
                        dwStyle,x,y,nWidth,nHeight,
                        hWndParent,hMenu, hInstance, lpParam
                    );
    if(hWnd2!=NULL)
        return TRUE;
    else
        return FALSE;
}

BOOL create::ShowWindow2(
                      //HWND hWnd,
                      int nCmdShow
                    )
{
    return ::ShowWindow(hWnd2,nCmdShow);
}

BOOL create::UpdateWindow2()
{
    return ::UpdateWindow(hWnd2);
}
//....................................................................

LRESULT CALLBACK WindowProc(
  HWND hwnd,
  UINT uMsg,
  WPARAM wParam,
  LPARAM lParam
);
//.....................................................................
int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{
    WNDCLASS window;
    window.cbClsExtra=0;
    window.cbWndExtra=0;
    window.hbrBackground=(HBRUSH )COLOR_WINDOW;
    window.hCursor=0;
    window.hIcon=LoadIcon(NULL,IDI_WINLOGO);
    window.hInstance=hInstance;
    window.lpfnWndProc=WindowProc;
    window.lpszClassName="classone";
    window.lpszMenuName=0;
    window.style=CS_VREDRAW | CS_HREDRAW;
    RegisterClass(&window);

    create mainwindow;
    mainwindow.CreateWindow2("classone","mainwindow",WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,CW_USEDEFAULT,600,400,NULL,NULL,hInstance,NULL);
    mainwindow.ShowWindow2(nCmdShow);
    mainwindow.UpdateWindow2();
        MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

LRESULT CALLBACK WinProc(
  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 code is %d",wParam);
        MessageBox(hwnd,szChar,"char",0);
        break;
    case WM_LBUTTONDOWN:
        MessageBox(hwnd,"mouse clicked","message",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,"是否真的结束?","message",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return 0;
}

[ 本帖最后由 纯黑色 于 2010-5-10 22:58 编辑 ]
搜索更多相关主题的帖子: 练习 感激不尽 代码 
2010-05-10 22:43
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:10 
不应该写成这样吧!!!LRESULT CALLBACK WinProc(。。。){。。。}

★★★★★为人民服务★★★★★
2010-05-11 07:17
纯黑色
Rank: 1
等 级:新手上路
帖 子:347
专家分:0
注 册:2009-4-16
收藏
得分:0 
回复 2楼 cnfarer
是应该换下函数名吗?
2010-05-11 07:31
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:0 
回复 3楼 纯黑色
要与下面的对应(一样的名称啊)。
window.lpfnWndProc=WindowProc;

★★★★★为人民服务★★★★★
2010-05-18 16:38
ygp_sfec
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:87
专家分:115
注 册:2009-9-8
收藏
得分:0 
老兄,函数声明和函数实现的函数名不一致啊
声明
LRESULT CALLBACK WindowProc(
  HWND hwnd,
  UINT uMsg,
  WPARAM wParam,
  LPARAM lParam
);
实现
LRESULT CALLBACK WinProc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
 
2010-10-07 12:26
快速回复:自己写了个练习类的代码,出现了连接错误,请各位大侠帮忙,在下感激不尽 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020924 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved