Ozz*_*zah 10 c++ windows winapi
我正在尝试使用WinApi编写这个win32程序而且我被卡住了,因为我正在关注的教程似乎有问题.
MainWindow.h:
class MainWindow
{
public:
MainWindow(HINSTANCE);
~MainWindow(void);
LRESULT CALLBACK WndProcedure(HWND, UINT, WPARAM, LPARAM);
// [...]
Run Code Online (Sandbox Code Playgroud)
MainWindow.cpp:
MainWindow::MainWindow(HINSTANCE hInstance) : hwnd(0)
{
WNDCLASSEX WndClsEx;
// [...]
WndClsEx.lpfnWndProc = &MainWindow::WndProcedure;
// [...]
}
LRESULT CALLBACK MainWindow::WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
// [...]
}
Run Code Online (Sandbox Code Playgroud)
我必须错误引用的MainWindow :: WndProcedure因为我下面完全一样的教程说的签名,但是在构造函数中的lpfnWndProc行给出一个编译时错误:
错误C2440:'=':无法从'LRESULT(__stdcall MainWindow ::*)(HWND,UINT,WPARAM,LPARAM)'转换为'WNDPROC'
小智 15
更换
LRESULT CALLBACK WndProcedure(HWND, UINT, WPARAM, LPARAM);
Run Code Online (Sandbox Code Playgroud)
通过
static LRESULT CALLBACK WndProcedure(HWND, UINT, WPARAM, LPARAM);
Run Code Online (Sandbox Code Playgroud)
this指针是函数调用中的隐藏参数,通过将其声明为静态,this指针不再是参数,并且两个函数的签名匹配.