• 全部
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • 界面
  • 进程
  • 算法
  • 硬件/系统
  • 数据库
  • VC++技术资源

这是《windows程序设计》里的例子。我怎么编译连接的时候出错啊?

qiujianben 2001-12-19 04:28:12
#include <windows.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//WndProc返回对一个窗口的32位指针,HWND窗口句柄,UNIT无符号的整型,WPARAM、LPARAM消息参数返回一个32位的参数)
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR lpCmdLine,int iCmdShow)
{
static TCHAR szAppName[]=TEXT("HelloWin");
HWND hWnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
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(WHITE_BRUSH);//获取一个图形图象,即获得刷子
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName;


if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("This program request WINDOWSNT"),szAppName,MB_ICONERROR);
return 0;
}

hWnd=CreateWindowA(szAppName,TEXT("The Hello Programe!"),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_CREATE:
PlaySound(TEXT("hellowin.wav"),NULL,SND_FILENAME|SND_ASYNC);
return 0;

case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
DrawText(hdc,TEXT("Hello Windows 98!"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);}
--------------------Configuration: HELLOWIN - Win32 Debug--------------------
Linking...
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__DispatchMessageA@4
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__TranslateMessage@4
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__GetMessageA@16
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__UpdateWindow@4
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__ShowWindow@8
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__CreateWindowExA@48
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__MessageBoxA@16
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__RegisterClassA@4
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__GetStockObject@4
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__LoadCursorA@8
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__LoadIconA@8
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__DefWindowProcA@16
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__PostQuitMessage@4
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__EndPaint@8
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__DrawTextA@20
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__GetClientRect@8
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__BeginPaint@8
HELLOWIN.OBJ : error LNK2001: unresolved external symbol __imp__PlaySoundA@12
Debug/HELLOWIN.exe : fatal error LNK1120: 18 unresolved externals
Error executing link.exe.

HELLOWIN.exe - 19 error(s), 0 warning(s)

...全文
101 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
scklotz 2001-12-19
你没有包含库文件。
在project -> setting 里:
link 选项卡里:
object/library 添加如下
kernel32.lib user32.lib gdi32.lib
回复
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2001-12-19 04:28
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……