-1

Is there any way to refresh() MFC CDialog in the same class?

I have tried using Invalidate(), RedrawWindow(), UpdateWindow() without success...

I would appreciate any kind of help.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Alberto Bricio
  • 402
  • 1
  • 6
  • 22
  • 2
    Refresh _what_? If it's a normal `CDialog`, it doesn't need explicit redrawing. – Roger Lipscombe Mar 07 '18 at 15:12
  • 2
    Don't ask about your proposed solution. Ask about the issue you are trying to solve instead. Forcing a redraw is your solution, but the real issue is undisclosed. – IInspectable Mar 07 '18 at 15:17
  • It appears like something in your dialog is not updating after you changed some data. Can you add a screenshot of what went wrong and explain how it should look like instead? As usual, showing the relevant source code would help too. – zett42 Mar 07 '18 at 15:19
  • In this case, I'm trying to change language characters according to IME. What I really want to know is if there are any way to restart/reboot my CWinApp class which launch all my dialogs because it will be an enough solution for me. Thank for your help. – Alberto Bricio Mar 07 '18 at 15:24
  • I use a little executable and a header file. These work to restart my application. I use it when the user changes language and the app must restart. – Andrew Truckle Mar 07 '18 at 15:34
  • Possible duplicate of [how to restart my own application in VC++](https://stackoverflow.com/questions/15197345/how-to-restart-my-own-application-in-vc) – Andrew Truckle Mar 07 '18 at 15:37
  • https://www.codeproject.com/Articles/15184/How-To-Create-a-Self-Restartable-Application – Andrew Truckle Mar 07 '18 at 15:38
  • There is no easy way to do that. You have to restart manually and restart the dialogs. Is this MDI or SDI framework? There is usually only one dialog open for application settings, that's the only one you have to restore. – Barmak Shemirani Mar 08 '18 at 03:51
  • I think that MFC is MDI, but i'm not sure at all. The application has a lot of dialogs, but I want to refresh only one. – Alberto Bricio Mar 08 '18 at 09:06

1 Answers1

0

You have to close the program and run the program again.

Use GetModuleFileName to find your app name. Run the program with CreateProcess.

You can add a command line argument after applications path, for example " /restart?mydialog", so that when the program restarts, it can examine the commandline argument and launch the appropriate dialog. Example:

void CMyDialog::OnSettings()
{
    wchar_t buf[MAX_PATH];
    GetModuleFileName(NULL, buf, _countof(buf));
    wcscat_s(buf, L" /restart?mydialog");
    AfxGetMainWnd()->SendMessage(WM_CLOSE);
    STARTUPINFO si = { sizeof(si) };
    PROCESS_INFORMATION pi = { 0 };
    CreateProcess(NULL, buf, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
}

Now go to CMainFrame, CMyMDIFrameWnd, or whichever is the application's main window, and get ready to launch the dialog when L"/restart?mydialog" appears in the command line. Example:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    ...

    CString s = GetCommandLine();
    if (s.Find(L"/restart?mydialog") >= 0)
        PostMessage(WM_COMMAND, ID_APP_ABOUT); //<== launch the correct dialog here

    return 0;
}
Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77