我用c编写了一些代码来制作简单的win32窗口,但失败了
I wrote some code in c to make simple win32 window but failed
我收到此错误:
LNK1120:第 1 行上有 1 个未解析的外部
错误 LNK2019:未解析的外部符号_winproc@20在函数 _WinMain@16 C:\Users\giorgi\Documents\Visual Studio 2013\Projects\Hello\Hello\Source.obj 你好
我是WinApi的新手,请帮忙。
#include <windows.h>
LRESULT CALLBACK winproc(WNDPROC lpPrevWndFunc, HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR LpCmdLine, int nCmdShow)
{
WNDCLASSEX class;
ZeroMemory(&class, sizeof(WNDCLASSEX));
class.cbSize = sizeof(WNDCLASSEX);
class.style = CS_HREDRAW | CS_VREDRAW;
class.lpfnWndProc = (WNDPROC)winproc;
class.cbClsExtra = 0;
class.cbWndExtra = 0;
class.hInstance = hInstance;
class.hIcon = NULL;
class.hCursor = LoadCursor(NULL, IDC_ARROW);
class.hbrBackground = (HBRUSH)COLOR_WINDOW;
class.lpszClassName = "window class";
class.lpszMenuName = NULL;
class.hIconSm = NULL;
RegisterClassEx(&class);
HWND hwnd = CreateWindowEx
(
WS_EX_ACCEPTFILES,
"window class",
"window",
WS_OVERLAPPED,
200,
200,
800,
600,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd, nCmdShow);
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
break;
}
return DefWindowProc(hwnd, msg, wp, lp);
}
正如其他人所说,C 区分大小写,因此 winproc
和 WinProc
将是两个不同的函数。 您还需要确保 Windows 过程的签名与 Windows 的预期相匹配,因此请进行以下更改:
-
将
LRESULT CALLBACK winproc(WNDPROC lpPrevWndFunc, HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
更改为LRESULT CALLBACK winProc(HWND, UINT, WPARAM, LPARAM);
-
将
class.lpfnWndProc = (WNDPROC)winproc;
更改为class.lpfnWndProc = (WNDPROC)winProc;
-
将
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
更改为LRESULT CALLBACK winProc(HWND hwnd, UINT mgs, WPARAM wp, LPARAM lp)
最后,自从我在win32-API级别编程以来已经有一段时间了,但我相信你的Windows过程应该看起来像:
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
break;
default:
return DefWindowProc(hwnd, msg, wp, lp);
}
}
换句话说,如果您不自己处理消息,则只想返回默认窗口过程(DefWindowProc
)。
- 在c++中用vector填充一个简单的动态数组
- (C++)分析树以计算返回错误值的简单算术表达式
- Win32编译器选项和内存分配
- 我的简单if-else语句是如何无法访问的代码
- 使用简单类型列表实现的指数编译时间.为什么
- 如何在BST的这个简单递归实现中消除警告
- 一种在C++中读取TXT配置文件的简单方法
- 关于简单C++函数(is_palindrome)的逻辑的问题
- 显示错误输出的简单数组排序程序
- 当无法使用模板和宏时,生成类型变体C++代码的最简单方法是什么?
- 退出简单while循环时出现问题
- 一个非常简单的win32套接字代码,但工作错误
- 一个简单的 win32 多线程代码.这能行吗?
- 是否有一种简单的方法可以从普通的 win32 C++代码向应用程序见解提供数据?
- C 本机Win32简单的编辑控件
- 有没有一种简单的方法可以将多个资源添加到 Win32/C++ 项目
- 我用c编写了一些代码来制作简单的win32窗口,但失败了
- 组织X11和Win32简单游戏代码的最佳方式是什么
- 如何加载加载win32 dll和执行简单的winapi与firebreath
- 如何在没有Win32 API的情况下制作一个简单的窗口