刚学API,学者书上打了一段代码,可是总是有问题,可和书上是一样的啊。
#include<windows.h>
int CALLBACK wnproc(HWND,UINT,WPARAM,LPARAM);
char szclassname[]="windowclass";
char szapptitle[]="windows api";
int PASCAL winmain(HINSTANCE hinstance,HINSTANCE hprevistance,LPSTR lpszsmdparam,int ncmdshow)
{
HWND hmainwnd;
MSG msg;
WNDCLASS mywc;
if(!hprevistance)
{
mywc.style=CS_HREDRAM|CS_VREDRAM;
mywc.lpfnWndProc =wnproc;
mywc.cbClsExtra =0;
mywc.cbWndExtra=0;
mywc.hInstance=hinstance;
mywc.hIcon=LoadIcon(0,IDI_APPLIICATION);
mywc.hbrBackground=GetStockObject(WHITE_BRUSH);
mywc.lpszMenuName=0;
mywc.lpszClassName=szclassname;
RegisterClass(&mywc);
}
hmainwnd=CreateWindow(
szclassname,
szapptitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hinstance,NULL);
ShowWindow(hmainwnd,SW-SHOWMAXIMIZED);
UpdateWindow(hmainwnd);
while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
int CALLBACK Wndproc (HWND hmainwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
char messageleft[]="the left button have pubshed";
char messageright[]="the right button have been pubshed";
switch(message)
{
case WM_RBUTTONDOWN:
{
message(GetFocus(),messageleft,"RBUTTONpushdown",
MB_OK|MB_ICONFROMARION);
break;
}
case WM_LBUTTONDOWN:
{
message(GetFocus(),messageleft,"LBUTTONPUSHDOWN",
MB_OK|MB_ICONINFORMATION);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:break;
}
return DefWindowProc(hmainwnd,message,wparam,lparam);
}
提示的错误是
i.cpp
D:\c++例&my think\wozj\api\api.cpp(12) : error C2065: 'CS_HREDRAM' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(12) : error C2065: 'CS_VREDRAM' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(13) : error C2440: '=' : cannot convert from 'int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\c++例&my think\wozj\api\api.cpp(17) : error C2065: 'IDI_APPLIICATION' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(18) : error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
D:\c++例&my think\wozj\api\api.cpp(30) : error C2065: 'SW' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(30) : error C2065: 'SHOWMAXIMIZED' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(48) : error C2065: 'MB_ICONFROMARION' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(48) : error C2064: term does not evaluate to a function
D:\c++例&my think\wozj\api\api.cpp(54) : error C2064: term does not evaluate to a function
Error executing cl.exe.
愿高手帮忙解决。
#include<windows.h>
int CALLBACK wnproc(HWND,UINT,WPARAM,LPARAM);
char szclassname[]="windowclass";
char szapptitle[]="windows api";
int PASCAL winmain(HINSTANCE hinstance,HINSTANCE hprevistance,LPSTR lpszsmdparam,int ncmdshow)
{
HWND hmainwnd;
MSG msg;
WNDCLASS mywc;
if(!hprevistance)
{
mywc.style=CS_HREDRAM|CS_VREDRAM;
mywc.lpfnWndProc =wnproc;
mywc.cbClsExtra =0;
mywc.cbWndExtra=0;
mywc.hInstance=hinstance;
mywc.hIcon=LoadIcon(0,IDI_APPLIICATION);
mywc.hbrBackground=GetStockObject(WHITE_BRUSH);
mywc.lpszMenuName=0;
mywc.lpszClassName=szclassname;
RegisterClass(&mywc);
}
hmainwnd=CreateWindow(
szclassname,
szapptitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hinstance,NULL);
ShowWindow(hmainwnd,SW-SHOWMAXIMIZED);
UpdateWindow(hmainwnd);
while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
int CALLBACK Wndproc (HWND hmainwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
char messageleft[]="the left button have pubshed";
char messageright[]="the right button have been pubshed";
switch(message)
{
case WM_RBUTTONDOWN:
{
message(GetFocus(),messageleft,"RBUTTONpushdown",
MB_OK|MB_ICONFROMARION);
break;
}
case WM_LBUTTONDOWN:
{
message(GetFocus(),messageleft,"LBUTTONPUSHDOWN",
MB_OK|MB_ICONINFORMATION);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:break;
}
return DefWindowProc(hmainwnd,message,wparam,lparam);
}
提示的错误是
i.cpp
D:\c++例&my think\wozj\api\api.cpp(12) : error C2065: 'CS_HREDRAM' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(12) : error C2065: 'CS_VREDRAM' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(13) : error C2440: '=' : cannot convert from 'int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\c++例&my think\wozj\api\api.cpp(17) : error C2065: 'IDI_APPLIICATION' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(18) : error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
D:\c++例&my think\wozj\api\api.cpp(30) : error C2065: 'SW' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(30) : error C2065: 'SHOWMAXIMIZED' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(48) : error C2065: 'MB_ICONFROMARION' : undeclared identifier
D:\c++例&my think\wozj\api\api.cpp(48) : error C2064: term does not evaluate to a function
D:\c++例&my think\wozj\api\api.cpp(54) : error C2064: term does not evaluate to a function
Error executing cl.exe.
愿高手帮忙解决。
解决方案 »
- 用VS2010的MFC关于添加菜单项目出现的错误,求解啊!谢谢
- 请教SkinMagic换肤后出现的问题,谢谢~!
- 菜单编程问题!!
- 使用了_time64() __time64_t _localtime64() 后不知道找不到符号 环境vc6 sp6,psdk 2003
- 请问如何在edit控件里添加checkbox控件?
- vc怎样把long转变为CString
- 请问:onDraw函数与onPaint函数有什么区别?多谢了!
- 激活上下文式菜单是哪个消息事件呀!
- 请大家垂手帮忙-“视频监控系统”的原代码
- 关于如何动态创建对话框的问题
- 视频压缩vfw函数ICDecompress的离奇问题!高手救命!!!
- 为什么 给vc的日期时间选择器 关联变量以后 初始显示的时间不对了?
--》
CS_HREDRAW
LRESULT CALLBACK wnproc(HWND,UINT,WPARAM,LPARAM);
char szclassname[]="windowclass";
char szapptitle[]="windows api";
int PASCAL WinMain(HINSTANCE hinstance,HINSTANCE hprevistance,LPSTR lpszsmdparam,int ncmdshow)
{
HWND hmainwnd;
MSG msg;
WNDCLASS mywc;
if(!hprevistance)
{
mywc.style=CS_HREDRAW|CS_VREDRAW;
mywc.lpfnWndProc =wnproc;
mywc.cbClsExtra =0;
mywc.cbWndExtra=0;
mywc.hInstance=hinstance;
mywc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
mywc.hCursor = LoadCursor(NULL, IDC_ARROW);
mywc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
mywc.lpszMenuName=0;
mywc.lpszClassName=szclassname;
RegisterClass(&mywc);
}
hmainwnd=CreateWindow(
szclassname,
szapptitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hinstance,NULL);
ShowWindow(hmainwnd,SW_SHOWMAXIMIZED);
UpdateWindow(hmainwnd);
while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}LRESULT CALLBACK wnproc (HWND hmainwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
char messageleft[]="the left button have pubshed";
char messageright[]="the right button have been pubshed";
switch(message)
{
case WM_RBUTTONDOWN:
{
MessageBox(GetFocus(),messageleft,"RBUTTONpushdown",
MB_OK|MB_ICONINFORMATION);
break;
}
case WM_LBUTTONDOWN:
{
MessageBox(GetFocus(),messageleft,"LBUTTONPUSHDOWN",
MB_OK|MB_ICONINFORMATION);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:break;
}
return DefWindowProc(hmainwnd,message,wparam,lparam);
}
//#include "stdafx.h"
#include "resource.h"#define MAX_LOADSTRING 100// Global Variables:
//#include<windows.h>
long CALLBACK Wndproc(HWND,UINT,WPARAM,LPARAM);
char szclassname[]="windowclass";
char szapptitle[]="windows api";
int PASCAL WinMain(HINSTANCE hinstance,HINSTANCE hprevistance,LPSTR lpszsmdparam,int ncmdshow)
{
HWND hmainwnd;
MSG msg;
WNDCLASS mywc;
if(!hprevistance)
{
//mywc.style=CS_HREDRAM|CS_VREDRAM;
mywc.style=CS_HREDRAW|CS_VREDRAW;
mywc.lpfnWndProc =Wndproc;
mywc.cbClsExtra =0;
mywc.cbWndExtra=0;
mywc.hInstance=hinstance;
mywc.hIcon=LoadIcon(0,IDI_APPLICATION);
mywc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
mywc.lpszMenuName=0;
mywc.lpszClassName=szclassname;
RegisterClass(&mywc);
}
hmainwnd=CreateWindow(
szclassname,
szapptitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hinstance,NULL);
ShowWindow(hmainwnd,SW_SHOWMAXIMIZED);
UpdateWindow(hmainwnd);
while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
long CALLBACK Wndproc (HWND hmainwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
char messageleft[]="the left button have pubshed";
char messageright[]="the right button have been pubshed";
switch(message)
{
case WM_RBUTTONDOWN:
{
MessageBox(GetFocus(),messageleft,"LButtonPushDown",MB_OK|MB_ICONINFORMATION); break;
}
case WM_LBUTTONDOWN:
{
MessageBox(GetFocus(),messageright,"RButtonPushDown",MB_OK|MB_ICONINFORMATION);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:break;
}
return DefWindowProc(hmainwnd,message,wparam,lparam);
}WIn32对大小写是区分的,很多宏定义打错了,以后注意点这些。