Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Disabling ShellOpen???

My MFC application accepts opening registered files by double-clicking on them. I need this behaviour, except when a flag is set (bNotAccept=TRUE). In this case no external DDE event should interfere with program execution. How can I handle this?
0
winmeister
Asked:
winmeister
  • 2
  • 2
1 Solution
 
Tommy HuiCommented:
In your Application::InitInstance() function, there's a section of code that looks like

      // Parse command line for standard shell commands, DDE, file open
      CCommandLineInfo cmdInfo;
      ParseCommandLine(cmdInfo);

      // Dispatch commands specified on the command line
      if (!ProcessShellCommand(cmdInfo))
            return FALSE;

This is the part that parses the DDE interface. If you replace it with

      int oldShellCommand = cmdInfo.m_nShellCommand;

      if (oldShellCommand == CCommandLineInfo::FileOpen && bNotAccept)
            cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;

      // Dispatch commands specified on the command line
      if (!ProcessShellCommand(cmdInfo))
            return FALSE;

Then that should do what you want.
0
 
winmeisterAuthor Commented:
Thui,
your code is executed only during InitIntance. I need to change the behaviour during program execution: at certain point, if the flag goes up, the program should reject all DDE processing.
0
 
Tommy HuiCommented:
You should then terminate all DDE conversations. There isn't anything in MFC that I know of that automatically responds to DDE commands for you. You need to change your existing DDE code.
0
 
winmeisterAuthor Commented:
Actually I don't know which is my  "existing DDE code". I just have an EnableShellOpen() command in InitInstance, before file type registration.
0
 
chensuCommented:
There are three ways you may try (I haven't done it).

1. Override the CWinApp::OnDDECommand() function to see what the lpszCommand is when you want to disable it.

2. Call the CWinApp::UnregisterShellFileTypes() function although it is undocumented, enable  it again by calling the CWinApp::RegisterShellFileTypes() function.

3. Do the following code when you need to disable it, enable it again by calling the CWinApp::EnableShellOpen() function.

    ::GlobalDeleteAtom(m_atomApp);
    ::GlobalDeleteAtom(m_atomSystemTopic);
    m_atomApp = NULL;
    m_atomSystemTopic = NULL;

For your information, the following is the relevant MFC source code from appui2.cpp.

void CWinApp::EnableShellOpen()
{
      ASSERT(m_atomApp == NULL && m_atomSystemTopic == NULL); // do once

      m_atomApp = ::GlobalAddAtom(m_pszExeName);
      m_atomSystemTopic = ::GlobalAddAtom(szSystemTopic);
}

void CWinApp::RegisterShellFileTypes(BOOL bCompat)
{
      ASSERT(m_pDocManager != NULL);
      m_pDocManager->RegisterShellFileTypes(bCompat);
}

void CWinApp::RegisterShellFileTypesCompat()
{
      ASSERT(m_pDocManager != NULL);
      m_pDocManager->RegisterShellFileTypes(TRUE);
}

void CWinApp::UnregisterShellFileTypes()
{
      ASSERT(m_pDocManager != NULL);
      m_pDocManager->UnregisterShellFileTypes();
}

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now