GLFW窗口关闭但未处理

时间:2020-07-29 17:55:45

标签: glfw

当我右键单击窗口的任务栏图标并单击“关闭窗口”时,该窗口将关闭,但进程仍在运行。如何关闭程序? 我从imgui的示例中获取了代码,我是非常基础的编码员。 非常感谢。

它说请添加更多详细信息,我不知道还要写些什么,我提供了我不知道可以写的代码。请

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    HANDLE handle = CreateMutex(NULL, TRUE, "Dialog553453534");
    if (GetLastError() != ERROR_SUCCESS)
    {
        MessageBox(0, "The program is already running!", "Information", MB_OK | MB_ICONINFORMATION);
        return 0;
    }
    InitRadio();
    int screenW = GetSystemMetrics(SM_CXSCREEN);
    int screenH = GetSystemMetrics(SM_CYSCREEN);
    int screensizex = 296, screensizey = 267;
    int centrx = (screenW / 2) - (screensizex / 2);
    int centry = (screenH / 2) - (screensizey / 2);
    if (!glfwInit())
        return 1;
    GLFWwindow* window = glfwCreateWindow(screensizex, screensizey, "Dialog", NULL, NULL);
    if (window == NULL)
        return 1; 
    icons[0].pixels = SOIL_load_image_from_memory(Dialog, 26315, &icons[0].width, &icons[0].height, 0, SOIL_LOAD_RGBA);
    glfwSetWindowIcon(window, 1, icons);
    SOIL_free_image_data(icons[0].pixels);
    glfwSetWindowPos(window, centrx, centry);
    HWND hWnd = glfwGetWin32Window(window);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);
    LONG style = GetWindowLong(hWnd, GWL_STYLE);
    style &= ~(WS_CAPTION | WS_THICKFRAME );
    SetWindowLong(hWnd, GWL_STYLE, style);

    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    SetWindowLong(hWnd, GWL_WNDPROC, (LONG)WndProc);
    ImGui_ImplWin32_Init(hWnd);
    ImGui_ImplOpenGL2_Init();
    ImGui::StyleColorsDark();
    ImGui::GetStyle().AntiAliasedFill = false;
    ImGui::GetStyle().AntiAliasedLines = false;
    ImGui::GetStyle().FrameRounding = 0.0f;
    ImGui::GetStyle().WindowRounding = 0.0f;
    ImGui::GetStyle().ChildRounding = 0.0f;
    ImGui::GetStyle().ScrollbarRounding = 0.0f;
    ImGui::GetStyle().GrabRounding = 0.0f;
    ImGui::GetStyle().FrameBorderSize = 1.0f;
    ImGui::GetStyle().WindowPadding = ImVec2(6, 8);
    ImGui::GetStyle().WindowTitleAlign = ImVec2(0.5f, 0.5f);
    ImGui::GetStyle().DisplaySafeAreaPadding = ImVec2(0.0f, 0.0f);
    ImGui::GetStyle().WindowBorderSize = 0.0f;
    ImGui::GetStyle().FrameBorderSize = 0.0f;
    ImGui::GetStyle().PopupBorderSize = 0.0f;
    ImGui::GetIO().IniFilename = NULL;
    ImGui::GetIO().LogFilename = NULL;

    while (!glfwWindowShouldClose(window))
    {
        glfwPollEvents();
        ImGui_ImplOpenGL2_NewFrame();
        ImGui_ImplWin32_NewFrame();
        ImGui::NewFrame();
        PlayRadio();
        Menu(hWnd);
        ImGui::Render();
        int display_w, display_h;
        glfwGetFramebufferSize(window, &display_w, &display_h);
        glViewport(0, 0, display_w, display_h);
        ImVec4 clear_color = ImVec4(0.f, 0.f, 0.f, 1.f);
        glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
        glClear(GL_COLOR_BUFFER_BIT);
        ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
        glfwMakeContextCurrent(window);
        glfwSwapBuffers(window);
    }
    ImGui_ImplOpenGL2_Shutdown();
    ImGui_ImplWin32_Shutdown();
    ImGui::DestroyContext();
    glfwDestroyWindow(window);
    glfwTerminate();

    return 0;
}

0 个答案:

没有答案