才开始用Vc,,不知道怎么回事
而且错误搜速过了,按别的帖子解决办法不行啊,大多是说加上#include "stdafx.h"之类解决的
源代码(从书上抄的)
// wnd.cpp : Defines the entry point for the console application.
//#include "stdafx.h"#include "windows.h"LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
HWND hwnd;
MSG msg;
WndClass wndclass;
char lpszClassName[]="窗口";
char lpszTitle[]="窗口标题"; wndclass.style=0; //default type
wndclass.lpfnWndProc=WndProc; //窗口处理函数为WndProc
wndclass.cbClsExtra=0; //窗口类无扩展
wndclass.cbWndExtra=0; //窗口实例无扩展
wndclass.hInstance=hinstance; //当前实例句柄
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);//窗口最小化图标为默认图标
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);//窗口采用箭头光标
wndclass.hbBackground=GetStockObject(WHITE_BRUSH);//窗口背景为白色
wndclass.lpszMenuName=NULL;//窗口中无菜单
wndclass.lpszClassName=lpszClassName; if(!RegisterClass(&wndclass))//如果注册失败,发出警告声音
{
MessageBeep(0);
return FALSE;
}
//创建窗口
hwnd=CreatWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,//窗口左上坐标默认值
CW_USEDEFAULT,
CW_USEDEFAULT,//窗口高宽默认值
NULL,//窗口无父窗口
NULL,//窗口无主菜单
hInstance,
NULL);//不使用该值
//显示窗口
ShowWindow(hwnd,nCmdShow);//nCmdShow??????
UpdateWindow(hwnd); //进入消息循环
while(GetMessage(&msg,NULL,0,0))//null???
{
TranslateMessage(&msg);//将虚拟键转化为字符
DispatchMessage(&msg);//把消息送往MSG结构为窗口定制的消息处理器
}
return msg.wParam;//消息循环结束即程序终止时将信息返回系统
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY: PostQuitMessage(0);//发出WM_QUIT
default:
return DefWindowProc(hwnd,message,wParam,lParam);//与处理函数参数相同
} return 0;
}出错信息:
e:\vc++\mypro\wnd\wnd.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/wnd.pch': No such file or directory
Error executing cl.exe.wnd.obj - 1 error(s), 0 warning(s)
请大家指教
而且错误搜速过了,按别的帖子解决办法不行啊,大多是说加上#include "stdafx.h"之类解决的
源代码(从书上抄的)
// wnd.cpp : Defines the entry point for the console application.
//#include "stdafx.h"#include "windows.h"LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
HWND hwnd;
MSG msg;
WndClass wndclass;
char lpszClassName[]="窗口";
char lpszTitle[]="窗口标题"; wndclass.style=0; //default type
wndclass.lpfnWndProc=WndProc; //窗口处理函数为WndProc
wndclass.cbClsExtra=0; //窗口类无扩展
wndclass.cbWndExtra=0; //窗口实例无扩展
wndclass.hInstance=hinstance; //当前实例句柄
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);//窗口最小化图标为默认图标
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);//窗口采用箭头光标
wndclass.hbBackground=GetStockObject(WHITE_BRUSH);//窗口背景为白色
wndclass.lpszMenuName=NULL;//窗口中无菜单
wndclass.lpszClassName=lpszClassName; if(!RegisterClass(&wndclass))//如果注册失败,发出警告声音
{
MessageBeep(0);
return FALSE;
}
//创建窗口
hwnd=CreatWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,//窗口左上坐标默认值
CW_USEDEFAULT,
CW_USEDEFAULT,//窗口高宽默认值
NULL,//窗口无父窗口
NULL,//窗口无主菜单
hInstance,
NULL);//不使用该值
//显示窗口
ShowWindow(hwnd,nCmdShow);//nCmdShow??????
UpdateWindow(hwnd); //进入消息循环
while(GetMessage(&msg,NULL,0,0))//null???
{
TranslateMessage(&msg);//将虚拟键转化为字符
DispatchMessage(&msg);//把消息送往MSG结构为窗口定制的消息处理器
}
return msg.wParam;//消息循环结束即程序终止时将信息返回系统
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY: PostQuitMessage(0);//发出WM_QUIT
default:
return DefWindowProc(hwnd,message,wParam,lParam);//与处理函数参数相同
} return 0;
}出错信息:
e:\vc++\mypro\wnd\wnd.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/wnd.pch': No such file or directory
Error executing cl.exe.wnd.obj - 1 error(s), 0 warning(s)
请大家指教
解决一
新添加的类的.cpp文件开头没包含stdafx.h,在该文件最前面加上即可解决二
使用右键点击项目工程中的该cpp文件,选择setting,在c/c++栏,选择PreCompiled headers,然后设置第一选项,选择不使用预编译头,解决这个问题
e:\vc++\mypro\1\1.cpp(13) : error C2065: 'WndClass' : undeclared identifier
e:\vc++\mypro\1\1.cpp(13) : error C2146: syntax error : missing ';' before identifier 'wndclass'
e:\vc++\mypro\1\1.cpp(13) : error C2065: 'wndclass' : undeclared identifier
e:\vc++\mypro\1\1.cpp(17) : error C2228: left of '.style' must have class/struct/union type
e:\vc++\mypro\1\1.cpp(18) : error C2228: left of '.lpfnWndProc' must have class/struct/union type
e:\vc++\mypro\1\1.cpp(19) : error C2228: left of '.cbClsExtra' must have class/struct/union type
e:\vc++\mypro\1\1.cpp(20) : error C2228: left of '.cbWndExtra' must have class/struct/union type
e:\vc++\mypro\1\1.cpp(21) : error C2228: left of '.hInstance' must have class/struct/union type
e:\vc++\mypro\1\1.cpp(21) : error C2065: 'hinstance' : undeclared identifier
e:\vc++\mypro\1\1.cpp(22) : error C2228: left of '.hIcon' must have class/struct/union type
e:\vc++\mypro\1\1.cpp(23) : error C2228: left of '.hCursor' must have class/struct/union type
e:\vc++\mypro\1\1.cpp(24) : error C2228: left of '.hbBackground' must have class/struct/union type
e:\vc++\mypro\1\1.cpp(25) : error C2228: left of '.lpszMenuName' must have class/struct/union type
e:\vc++\mypro\1\1.cpp(26) : error C2228: left of '.lpszClassName' must have class/struct/union type
e:\vc++\mypro\1\1.cpp(36) : error C2065: 'CreatWindow' : undeclared identifier
e:\vc++\mypro\1\1.cpp(46) : error C2440: '=' : cannot convert from 'int' to 'struct HWND__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.1.obj - 16 error(s), 0 warning(s)
根本没找到windows.h嘛就,