蒋心千金女贼性格:关于windows程序设计

来源:百度文库 编辑:高考问答 时间:2024/05/04 12:56:33
在第二章有如下代码 可是为什么我不能编译通过
/*---------------------------------------------------------------------------
SCRNSIZE.C -- Displays screen size in a message box
(c) Charles Petzold, 1998
----------------------------------------------------------------------------*/
#include <WINDOWS.H>
#include <TCHAR.H>
#include <STDIO.H>
int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
TCHAR szBuffer [1024] ;
va_list pArgList ;
// The va_start macro (defined in STDARG.H) is usually equivalent to:
// pArgList = (char *) &szFormat + sizeof (szFormat) ;
va_start (pArgList, szFormat) ;
// The last argument to wvsprintf points to the arguments
_vsntprintf ( szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
szFormat, pArgList) ;
// The va_end macro just zeroes out pArgList for no good reason
va_end (pArgList) ;
return MessageBox (NULL, szBuffer, szCaption, 0) ;
}

int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
int cxScreen, cyScreen ;
cxScreen = GetSystemMetrics (SM_CXSCREEN) ;
cyScreen = GetSystemMetrics (SM_CYSCREEN) ;
MessageBoxPrintf ( TEXT ("ScrnSize"),
TEXT ("The screen is %i pixels wide by %i pixels high."),
cxScreen, cyScreen) ;
return 0 ;
}
原文复制返回
d:\microsoft visual studio\vc98\include\excpt.h(8) : error C2146: syntax error : missing ';' before identifier 'MessageBoxPrintf'
d:\microsoft visual studio\vc98\include\excpt.h(8) : fatal error C1004: unexpected end of file found
两个错误
调试环境winxp sp2 + vc++sp6

应该是 你 新建项目时 没设对。使用了预编译头吧。把这个选项去掉。

或者

就在这个文件 最前面加一行
#include "stdafx.h"
(如果没使用预编译头就不需要了。)