Solved

Disabling ShellOpen???

Posted on 1998-02-04
5
185 Views
Last Modified: 2013-11-19
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
Comment
Question by:winmeister
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1315545
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
 
LVL 1

Author Comment

by:winmeister
ID: 1315546
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
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1315547
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
 
LVL 1

Author Comment

by:winmeister
ID: 1315548
Actually I don't know which is my  "existing DDE code". I just have an EnableShellOpen() command in InitInstance, before file type registration.
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1315549
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to determine file rename from EventLog ? 2 49
substring method in java 1 116
sumHeights  challenge 17 70
wordcount challenge 11 121
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question