求助

zcw_ease 2005-11-16 10:45:35
#include <stdio.h>
#include <windows.h>
LRESULT CALLBACK WinSunProc(
WNDPROC lpPrevWndFunc, // pointer to previous procedure
HWND hWnd, // handle to window
UINT Msg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wincls;
wincls.cbClsExtra=0;
wincls.cbWndExtra=0;
wincls.hbrBackground=(HBRUSH)GetStockObject(COLOR_WINDOW);
wincls.hCursor=LoadCursor(NULL,IDC_CROSS);
wincls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wincls.hInstance=hInstance;
wincls.lpfnWndProc=WinSunProc;
wincls.lpszClassName="winmain";
wincls.lpszMenuName=NULL;
wincls.style=CS_VREDRAW|CS_HREDRAW;
RegisterClass(&wincls);
HWND hwnd;
CreateWindow("winmain","pro1",WS_OVERLAPPED,0,0,30,60,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(
WNDPROC lpPrevWndFunc, // pointer to previous procedure
HWND hWnd, // handle to window
UINT Msg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(Msg)
{
case WM_CHAR:
char *me;
sprintf(me,"你按了%d",wParam);
MessageBox(hWnd,me,"按呀",MB_OK);
break;
case WM_LBUTTONDOWN:
HDC hdc;
hdc=GetDC(hWnd);
TextOut(hdc,0,10,"lbuttondown",strlen("lbuttondown"));
ReleaseDC(hWnd,hdc);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hWnd,"结束吗?","确认",MB_YESNO))
{
DestroyWindow(hWnd);
}
break;
case WM_PAINT:
HDC hdc1;
PAINTSTRUCT p;
BeginPaint(hWnd,&p);
TextOut(hdc1,10,20,"paint",strlen("paint"));
EndPaint(hWnd,&p);
break;
default:
return DefWindowProc(hWnd,Msg,wParam,lParam);
}
return 0;
}
编译时一直有这个错误error C2440: '=' : cannot convert from 'long (__stdcall *)(long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long),struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(str
uct HWND__ *,unsigned int,unsigned int,long)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
问如何改正?什么原因?
...全文
66 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
菜牛 2005-11-16
  • 打赏
  • 举报
回复
就是你这个WinSunProc定义不符合需要的格式。看看基础吧。

LRESULT CALLBACK WindowProc( HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
菜牛 2005-11-16
  • 打赏
  • 举报
回复
编译器错误 C2440

“conversion”: 无法从“type1”转换为“type2”
编译器无法从“type1”转换为“type2”。
将用“UDT 返回值的不兼容调用约定”消息限定此示例代码 15 和 16 行的 C2440 错误。(UDT 指用户定义的类型,如类、结构或联合。)在前向声明的返回类型中指定的 UDT 调用约定与该 UDT 的实际调用约定有冲突,而且涉及函数指针时,会导致上述类型的不兼容错误。
在该示例中,我们首先拥有某结构和返回该结构的函数的前向声明;编译器假定该结构使用 C++ 调用约定。然后我们生成该结构的定义,默认情况下,该结构定义使用 C 调用约定。因为编译器在读完整个结构前,不知道该结构的调用约定,所以也假定在 get_c2 的返回类型中该结构的调用约定为 C++。
该结构后面跟有另一个返回该结构的函数声明,但在此时,编译器知道该结构的调用约定为 C++。同样,返回该结构的函数指针在结构定义之后定义,所以编译器知道该结构使用 C++ 调用约定。
因为将应使用 C 调用约定返回类型的函数指针赋予了应使用 C++ 调用约定返回类型的函数,所以发生错误。
若要解决由于不兼容的调用约定而产生的 C2440,请在 UDT 定义之后声明返回 UDT 的函数。
// C2440.cpp
struct MyStruct;

MyStruct get_c1();

struct MyStruct
{
int i;
static MyStruct get_C2();
};

MyStruct get_C3();

typedef MyStruct (*FC)();

FC fc1 = &get_c1; // C2440, line 15
FC fc2 = &MyStruct::get_C2; // C2440, line 16
FC fc3 = &get_C3;

class CMyClass {
public:
explicit CMyClass( int iBar)
throw() {
}

static CMyClass get_c2();
};

int main() {

CMyClass myclass = 2; // C2440
// try one of the following
// CMyClass myclass(2);
// CMyClass myclass = (CMyClass)2;

int *i;
float j;
j = (float)i; // C2440, cannot cast from pointer to int to float
}

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧