主目录传送门
https://blog.csdn.net/zb774095236/article/details/108291755
本次学习的源码模板下载:
1、 百度云:https://pan.baidu.com/s/14XoBHrtVVvvN_zaiv-ebmg 提取码:kvbq
学习目标:
在Windows API一日一练(1)-弹出按钮的基础源码版本上学习自己注册一个窗口
本次没有效果展示 你可以通过调试来确定是否注册成功
学习内容:
一、 项目参考
1. https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerclassa Microsoft官方函数文档
2.https://docs.microsoft.com/en-us/windows/win32/winmsg/using-window-procedures Microsoft官方创建流程文档
3. https://blog.csdn.net/caimouse/article/details/1686079 大牛的Win32系列
二. 在往期模板上修改和新增的步骤
1.代码段
//库文件
#include "Windows.h"
#include "tchar.h"
LRESULT CALLBACK MainWndProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam) // second message parameter
{
switch (uMsg)
{
case WM_CREATE:
// Initialize the window.
return 0;
case WM_PAINT:
// Paint the window's client area.
return 0;
case WM_SIZE:
// Set the size and position of the window.
return 0;
case WM_DESTROY:
// Clean up window-specific data objects.
return 0;
//
// Process other messages.
//
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
//定义WinMain的入口
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
//没有这些参数也不会发生警告
//UNREFERENCED_PARAMETER(hInstance);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
WNDCLASS wc;//定义一个窗口结构的对象wc
// Register the main window class.
wc.style = CS_HREDRAW | CS_VREDRAW;//设置窗口类型
wc.lpfnWndProc = (WNDPROC)MainWndProc;//设置窗口消息处理函数WndProc
wc.cbClsExtra = 0;//设置窗口类型的扩展为空
wc.cbWndExtra = 0;//设置窗口实例的扩展为空
wc.hInstance = hInstance;//设置窗口当前实例句柄hInstance
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);//设置窗口图标。
wc.hCursor = LoadCursor(NULL, IDC_ARROW);//设置光标为箭头。
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//设置窗口背景颜色为白色
wc.lpszMenuName = _T("MainMenu");//设置窗口菜单
wc.lpszClassName = _T("MainWindowClass");//设置窗口类型名称
if (!RegisterClass(&wc))//调用函数RegisterClass注册这个窗口类型
return FALSE;
//如果注册成功,返回这个窗口类型的标识号,可以用标识号进行创建窗口,
//查找窗口和注销窗口类型等等。如果失败返回的值是空,因此可以通过检查返回值为判断是否调用成功。
return 0;
}
项目下载地址:
1.百度云:https://pan.baidu.com/s/1wtFruTAv3PcvpkkKWpftWw 提取码:olww
留在最后
创建窗口之路还将继续 哈撒给