Solved

modal

Posted on 1998-07-21
5
249 Views
Last Modified: 2013-11-20
I use Visual C++5
 I would like to make my window 's application same modal dialog. when i execeute my application
the other application cann't use till i quit my application.
Please advise me to do it.
thank you
0
Comment
Question by:eakkung
  • 3
5 Comments
 

Author Comment

by:eakkung
ID: 1319480
Edited text of question
0
 
LVL 1

Accepted Solution

by:
atari earned 180 total points
ID: 1319481
Hi, I call your application-class CApplic : CWinApp. Add the following variable to your Applic.h-File:

HANDLE m_hInstanceSem;

Then add the following function to your Applic.cpp-file, there where you find the functions InitInstance() and ExitInstance().

BOOL CApplic::IsFirstInstance()
{
  // Define a global semaphore to see if we are already running an instance
  m_hInstanceSem=CreateSemaphore(NULL,0,1,_T("INSTANCE_CHECK__1"));
  if (!m_hInstanceSem)
      return FALSE;

  if (m_hInstanceSem!=NULL && GetLastError()==ERROR_ALREADY_EXISTS)
  {
    CloseHandle(m_hInstanceSem);
    m_hInstanceSem=NULL;
    return FALSE;
  }
 
  return TRUE;
}

Then in the beginning your InitInstance()-function add the following:
BOOL CApplic::InitInstance()
{
  if (!IsFirstInstance())
  {
     AfxMessageBox("Application is already running ...");
     return FALSE;
  }
 
.   and so on.

Then if you run your program first, the program starts correctly. But if you run your program a second time, the above message appears and the program never starts.

Hope this helps.

Bye,
atari
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319482
Actually I do not understand the question thoroughly. Did he want to make the application can be run only once?
0
 
LVL 1

Expert Comment

by:atari
ID: 1319483
To trestan, it sounds for me like this, or wasn't this the question ?
0
 
LVL 1

Expert Comment

by:atari
ID: 1319484
Can we get any answer from you, eakkung ???

Bye,
atari
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 45
windows 10 how make picture as desktop background 2 65
sameEnds challenge 3 180
move a line in eclipse 3 107
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

830 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