Solved

Disabling ShellOpen???

Posted on 1998-02-04
5
179 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now