Solved

modal

Posted on 1998-07-21
5
248 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
substring method in java 1 123
either24  challenge 19 97
Unix Command -- Challenging  question 7 92
how to split multiple lines delimiter : 8 99
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…
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 …

803 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