• VC++ 实现程序重启


    转载:https://blog.csdn.net/what951006/article/details/72729448

    一、创建一个Win32项目

    二、窗口处理函数中,Create窗口时创建一个按钮,并在按钮点击事件中处理程序重启

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        int wmId, wmEvent;
        PAINTSTRUCT ps;
        HDC hdc;
    
        switch (message)
        {
        case WM_CREATE:
        {
                          //创建按钮  
                          CreateWindow(L"Button", L"重启", WS_VISIBLE | WS_CHILD,
                              600, 240, 100, 50, hWnd, (HMENU)IDC_BUTTON_RESTART, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
        }
            break;
    
        case WM_COMMAND:
            wmId = LOWORD(wParam);
            wmEvent = HIWORD(wParam);
            // 分析菜单选择: 
            switch (wmId)
            {
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            case IDC_BUTTON_RESTART://重启按钮的响应
            {
                                        //::PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, NULL);
                                        TCHAR szModuleName[MAX_PATH * 2];
                                        ::GetModuleFileName(NULL, szModuleName, _countof(szModuleName) - 2);
    
                                        STARTUPINFO si;
                                        ZeroMemory(&si, sizeof(si));
                                        si.cb = sizeof(si);
                                        si.dwFlags = STARTF_USESHOWWINDOW;
                                        si.wShowWindow = SW_SHOW;
    
                                        PROCESS_INFORMATION pi;
                                        ZeroMemory(&pi, sizeof(pi));
    
                                        if (CreateProcess(NULL, szModuleName, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
                                        {
                                            // 既然我们不使用两个句柄,最好是立刻将它们关闭
                                            ::CloseHandle(pi.hThread);
                                            ::CloseHandle(pi.hProcess);
                                        }
    
                                        ::PostMessage(hWnd, WM_QUIT, 0, 0);
            }
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
            break;
        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
            // TODO:  在此添加任意绘图代码...
            EndPaint(hWnd, &ps);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        return 0;
    }
  • 相关阅读:
    9. 远程分支与本地分支管理
    8. Git 远程协作
    7. Git stash命令
    6. Git版本处理
    5. Git 本地分支命令
    4. Git 日志命令
    JVM垃圾回收分析
    python常用模块
    ubuntu18配置jetty9
    logback spring配置
  • 原文地址:https://www.cnblogs.com/chechen/p/10682924.html
Copyright © 2020-2023  润新知