ImGui
目录
创建窗口
|
|
|
|
|
|
参数1:name,相当于窗口的id,是独一无二的 参数2:p_open,如果设置这个参数,窗口的右上角就会出现一个X按钮来执行关闭窗口的功能。这个参数和X按钮绑定,当X按钮被按下时,p_open被设为false 参数3:flags,这个参数的类型实际上是int,用来指示当前窗口的某个feature是否应该激活 flags是一个整数,表示你需要的样式的和,以下是所有的flag
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
ImGuiWindowFlags_None = 0, ImGuiWindowFlags_NoTitleBar = 1 << 0, // 禁用标题栏 ImGuiWindowFlags_NoResize = 1 << 1, // 禁用右下角调整功能 ImGuiWindowFlags_NoMove = 1 << 2, // 禁止移动窗口 ImGuiWindowFlags_NoScrollbar = 1 << 3, // Disable scrollbars (window can still scroll with mouse or programmatically) ImGuiWindowFlags_NoScrollWithMouse = 1 << 4, // Disable user vertically scrolling with mouse wheel. On child window, mouse wheel will be forwarded to the parent unless NoScrollbar is also set. ImGuiWindowFlags_NoCollapse = 1 << 5, // 通过双击禁止用户折叠窗口 ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame ImGuiWindowFlags_NoBackground = 1 << 7, // Disable drawing background color (WindowBg, etc.) and outside border. Similar as using SetNextWindowBgAlpha(0.0f). ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file ImGuiWindowFlags_NoMouseInputs = 1 << 9, // Disable catching mouse, hovering test with pass through. ImGuiWindowFlags_MenuBar = 1 << 10, // Has a menu-bar ImGuiWindowFlags_HorizontalScrollbar = 1 << 11, // Allow horizontal scrollbar to appear (off by default). You may use SetNextWindowContentSize(ImVec2(width,0.0f)); prior to calling Begin() to specify width. Read code in imgui_demo in the "Horizontal Scrolling" section. ImGuiWindowFlags_NoFocusOnAppearing = 1 << 12, // Disable taking focus when transitioning from hidden to visible state ImGuiWindowFlags_NoBringToFrontOnFocus = 1 << 13, // Disable bringing window to front when taking focus (e.g. clicking on it or programmatically giving it focus) ImGuiWindowFlags_AlwaysVerticalScrollbar= 1 << 14, // Always show vertical scrollbar (even if ContentSize.y < Size.y) ImGuiWindowFlags_AlwaysHorizontalScrollbar=1<< 15, // Always show horizontal scrollbar (even if ContentSize.x < Size.x) ImGuiWindowFlags_AlwaysUseWindowPadding = 1 << 16, // Ensure child windows without border uses style.WindowPadding (ignored by default for non-bordered child windows, because more convenient) ImGuiWindowFlags_NoNavInputs = 1 << 18, // No gamepad/keyboard navigation within the window ImGuiWindowFlags_NoNavFocus = 1 << 19, // No focusing toward this window with gamepad/keyboard navigation (e.g. skipped by CTRL+TAB) ImGuiWindowFlags_UnsavedDocument = 1 << 20, // Append '*' to title without affecting the ID, as a convenience to avoid using the ### operator. When used in a tab/docking context, tab is selected on closure and closure is deferred by one frame to allow code to cancel the closure (with a confirmation popup, etc.) without flicker. ImGuiWindowFlags_NoNav = ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus, ImGuiWindowFlags_NoDecoration = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse, ImGuiWindowFlags_NoInputs = ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus, // [Internal] ImGuiWindowFlags_NavFlattened = 1 << 23, // [BETA] Allow gamepad/keyboard navigation to cross over parent border to this child (only use on child that have no scrolling!) ImGuiWindowFlags_ChildWindow = 1 << 24, // Don't use! For internal use by BeginChild() ImGuiWindowFlags_Tooltip = 1 << 25, // Don't use! For internal use by BeginTooltip() ImGuiWindowFlags_Popup = 1 << 26, // Don't use! For internal use by BeginPopup() ImGuiWindowFlags_Modal = 1 << 27, // Don't use! For internal use by BeginPopupModal() ImGuiWindowFlags_ChildMenu = 1 << 28 // Don't use! For internal use by BeginMenu()
以上内容在
imgui.h
的枚举ImGuiWindowFlags_
里也有。
Demo窗口
|
|
主菜单栏
|
|
菜单(横排)与菜单项(竖排)
|
|
次菜单栏
|
|
通过BeginMenuBar()和BeginMenu()来分别定制顶部菜单栏和对应的下拉菜单栏的内容; 注意任意的beginXXX都要对应一个endXXX
|
|
Text及Text各种效果
|
|
按钮及事件
|
|
单选框
|
|
|
|
复选框
|
|
|
|
折叠框控件
|
|
文本框
|
|
|
|
滑块
|
|
|
|
Tab菜单(横向子菜单)
|
|
显示中文
|
|
内存加载字体
|
|
生成字体
|
|
设置不同控件的颜色
|
|
设置不同控件的样式
|
|
|
|
绘制线
|
|
绘制四边形
|
|
绘制文字
|
|
|
|
绘制图片
|
|
-
首先必须导入stb_image.h
1 2 3
//在文件头部包含以下内容 #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h"
-
在适当的位置添加函数LoadTextureFromFile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
bool LoadTextureFromFile(const char* filename, ID3D11ShaderResourceView** out_srv, int* out_width, int* out_height) { // Load from disk into a raw RGBA buffer int image_width = 0; int image_height = 0; unsigned char* image_data = stbi_load(filename, &image_width, &image_height, NULL, 4); if (image_data == NULL) return false; // Create texture D3D11_TEXTURE2D_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.Width = image_width; desc.Height = image_height; desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count = 1; desc.Usage = D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; ID3D11Texture2D *pTexture = NULL; D3D11_SUBRESOURCE_DATA subResource; subResource.pSysMem = image_data; subResource.SysMemPitch = desc.Width * 4; subResource.SysMemSlicePitch = 0; g_pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); // Create texture view D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; ZeroMemory(&srvDesc, sizeof(srvDesc)); srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MipLevels = desc.MipLevels; srvDesc.Texture2D.MostDetailedMip = 0; g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, out_srv); pTexture->Release(); *out_width = image_width; *out_height = image_height; stbi_image_free(image_data); return true; }
-
在需要绘制图片的地方引用以下代码
1 2 3 4 5 6 7
int my_image_width = 0; int my_image_height = 0; ID3D11ShaderResourceView* my_texture = NULL; bool ret = LoadTextureFromFile("d:/ccz.jpg", &my_texture, &my_image_width, &my_image_height); //bool ret = LoadTextureFromFile("./sources/MyImage01.jpg", &my_texture, &my_image_width, &my_image_height); IM_ASSERT(ret); ImGui::Image((void*)my_texture, ImVec2(my_image_width, my_image_height));
初始化交换链
|
|
利用Detours库挂钩MessageBoxA
|
|
利用Detours库挂钩游戏Present函数
|
|
ImGui的初始化
|
|
在游戏内部绘制外挂页面
|
|
添加ImGui窗口消息响应
|
|
TabBar控件
|
|
远线程注入
- 使用进程PID打开进程,获得句柄
- 使用进程句柄申请内存空间
- 把dll路径写入内存
- 创建远程线程,调用LoadLibrary
- 释放收尾工作或者卸载dll
|
|
最好是 既然学了ImGui 最好用ImGui来写一个启动程序 ImGui 肯定是要比我们课堂上演示的黑框框要高大上很多