【C++】從零開始的CS:GO逆向分析2——配置GLFW+IMGUI環境并創建透明窗口( 二 )

 至此,環境配置完畢
 需要補充幾個用得到glfw代碼:讓鼠標事件透過創建的窗口glfwWindowHint(GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE);讓窗口透明glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, true);置頂窗口glfwWindowHint(GLFW_FLOATING, true);禁止更改窗口大小glfwWindowHint(GLFW_RESIZABLE, false);窗口最大化glfwWindowHint(GLFW_MAXIMIZED, true);設置沒有標題欄glfwSetWindowAttrib(window, GLFW_DECORATED, false);刪除掉沒有用的代碼,刪掉界面顯示的代碼 , 設置窗口透明,設置窗口最大化,設置鼠標通過 , 設置窗口不允許resize,就可以得到一個透明的窗口,即下面的代碼
#include <stdio.h>#include<Windows.h>#include <GLFW/glfw3.h>#include "imgui/imgui.h"#include "imgui/imgui_impl_glfw.h"#include "imgui/imgui_impl_opengl3.h"#include "imgui/alifont.hpp"static void glfw_error_callback(int error, const char* description){fprintf(stderr, "Glfw Error %d: %s\n", error, description);}int main(){glfwSetErrorCallback(glfw_error_callback);if (!glfwInit())return 1;GLFWmonitor *monitor = glfwGetPrimaryMonitor();//###########################設置窗口###########################const char* glsl_version = "#version 130";int Height = glfwGetVideoMode(monitor)->height;int Width = glfwGetVideoMode(monitor)->width;glfwWindowHint(GLFW_FLOATING, true);glfwWindowHint(GLFW_RESIZABLE, false);glfwWindowHint(GLFW_MAXIMIZED, true);glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, true);glfwWindowHint(GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE);//###########################設置窗口###########################GLFWwindow* window = glfwCreateWindow(Width, Height, "titile", NULL, NULL);if (window == NULL)return 1;glfwSetWindowAttrib(window, GLFW_DECORATED, false); //設置沒有標題欄ShowWindow(GetConsoleWindow(), SW_HIDE);glfwMakeContextCurrent(window);glfwSwapInterval(1);IMGUI_CHECKVERSION();ImGui::CreateContext();ImGuiIO& io = ImGui::GetIO(); (void)io;ImGui::StyleColorsDark();ImGui_ImplGlfw_InitForOpenGL(window, true);ImGui_ImplOpenGL3_Init(glsl_version);while (!glfwWindowShouldClose(window)){glfwPollEvents();glClear(GL_COLOR_BUFFER_BIT);ImGui_ImplOpenGL3_NewFrame();ImGui_ImplGlfw_NewFrame();ImGui::NewFrame();ImGui::Render();int display_w, display_h;glfwGetFramebufferSize(window, &display_w, &display_h);glViewport(0, 0, display_w, display_h);ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());glfwSwapBuffers(window);}// CleanupImGui_ImplOpenGL3_Shutdown();ImGui_ImplGlfw_Shutdown();ImGui::DestroyContext();glfwDestroyWindow(window);glfwTerminate();return 0;}至此 , 已經配置好了glfw+imgui的環境,并且創建了透明窗口,下一章用第一篇里的偏移值做點事
【【C++】從零開始的CS:GO逆向分析2——配置GLFW+IMGUI環境并創建透明窗口】

推薦閱讀