Solved

Disabling ShellOpen???

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Detect file exist or not 3 134
how to split multiple lines delimiter : 8 80
Making an alias 7 82
Bartender label printing - switch on and off graphics 3 15
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

863 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

25 Experts available now in Live!

Get 1:1 Help Now