#include "windows.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{
static TCHAR szAppName[]=TEXT("hello win");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=szAppName;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
hwnd=CreateWindow(szAppName,TEXT("Hello Windows"),WS_OVERLAPPEDWINDOW,30,30,800,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowCmd);
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("hellow.wav"),NULL,SND_FILENAME | SND_ASYNC);
// return 0;
/* 错误 1 error LNK2019: 无法解析的外部符号 __imp__PlaySoundA@12,该符号在函数 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用 HelloWin.obj HelloWin
错误 2 fatal error LNK1120: 1 个无法解析的外部命令 D:\Visual Studio 2008\Projects\HelloWin\Debug\HelloWin.exe 1 HelloWin
*/
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
GetClientRect(hWnd,&rect);
DrawText(hdc,TEXT("Hello,Windows XP"),-1,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
EndPaint(hWnd,&ps);
return 0;
case WM_LBUTTONDBLCLK:
MessageBox(hWnd,"LeftButton Clicked!","Info",0);
HDC hdc;
hdc=GetDC(hWnd);
TextOut(hdc,0,50,TEXT("leftbutton Clicked!"),strlen("leftbutton Clicked!"));
ReleaseDC(hWnd,hdc);
return 0;
case WM_CLOSE:
if(IDOK==MessageBox(hWnd,TEXT("是否退出"),TEXT("Info"),MB_YESNO))
{
DestroyWindow(hWnd);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,message,wParam,lparam);错误信息:
错误 1 error LNK2019: 无法解析的外部符号 __imp__PlaySoundA@12,该符号在函数 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用 HelloWin.obj HelloWin
错误 2 fatal error LNK1120: 1 个无法解析的外部命令 D:\Visual Studio 2008\Projects\HelloWin\Debug\HelloWin.exe 1 HelloWin开发环境:
VS2008
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{
static TCHAR szAppName[]=TEXT("hello win");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=szAppName;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
hwnd=CreateWindow(szAppName,TEXT("Hello Windows"),WS_OVERLAPPEDWINDOW,30,30,800,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowCmd);
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("hellow.wav"),NULL,SND_FILENAME | SND_ASYNC);
// return 0;
/* 错误 1 error LNK2019: 无法解析的外部符号 __imp__PlaySoundA@12,该符号在函数 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用 HelloWin.obj HelloWin
错误 2 fatal error LNK1120: 1 个无法解析的外部命令 D:\Visual Studio 2008\Projects\HelloWin\Debug\HelloWin.exe 1 HelloWin
*/
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
GetClientRect(hWnd,&rect);
DrawText(hdc,TEXT("Hello,Windows XP"),-1,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
EndPaint(hWnd,&ps);
return 0;
case WM_LBUTTONDBLCLK:
MessageBox(hWnd,"LeftButton Clicked!","Info",0);
HDC hdc;
hdc=GetDC(hWnd);
TextOut(hdc,0,50,TEXT("leftbutton Clicked!"),strlen("leftbutton Clicked!"));
ReleaseDC(hWnd,hdc);
return 0;
case WM_CLOSE:
if(IDOK==MessageBox(hWnd,TEXT("是否退出"),TEXT("Info"),MB_YESNO))
{
DestroyWindow(hWnd);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,message,wParam,lparam);错误信息:
错误 1 error LNK2019: 无法解析的外部符号 __imp__PlaySoundA@12,该符号在函数 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用 HelloWin.obj HelloWin
错误 2 fatal error LNK1120: 1 个无法解析的外部命令 D:\Visual Studio 2008\Projects\HelloWin\Debug\HelloWin.exe 1 HelloWin开发环境:
VS2008
#pragma comment(lib, "Winmm.lib")
#include "windows.h"
#pragma comment(lib, "Winmm.lib")
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{
static TCHAR szAppName[]=TEXT("hello win");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=szAppName;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
hwnd=CreateWindow(szAppName,TEXT("Hello Windows"),WS_OVERLAPPEDWINDOW,30,30,800,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lparam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch(message)
{
case WM_CREATE:
PlaySound(TEXT("hellow.wav"),NULL,SND_FILENAME | SND_ASYNC);
return 0;
/* 错误 1 error LNK2019: 无法解析的外部符号 __imp__PlaySoundA@12,该符号在函数 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用 HelloWin.obj HelloWin
错误 2 fatal error LNK1120: 1 个无法解析的外部命令 D:\Visual Studio 2008\Projects\HelloWin\Debug\HelloWin.exe 1 HelloWin
*/
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
GetClientRect(hWnd,&rect);
DrawText(hdc,TEXT("Hello,Windows XP"),-1,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
EndPaint(hWnd,&ps);
break;
case WM_LBUTTONDOWN:
MessageBox(hWnd,"LeftButton Clicked!","Info",0);
HDC hdc;
hdc=GetDC(hWnd);
TextOut(hdc,0,50,TEXT("leftbutton Clicked!"),strlen("leftbutton Clicked!"));
ReleaseDC(hWnd,hdc);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hWnd,"test","test",MB_YESNO))
{
DestroyWindow(hWnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lparam);
}
return 0;
}
请问为什么需要#pragma comment(lib, "Winmm.lib")呢?
但是在VC6下不用也可以运行