Solved

modal

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Rewrite URL With Encoded Characters 6 64
Define unique primary key 9 81
sumDigits challenge 9 96
fizzArray  challenge 1 47
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

21 Experts available now in Live!

Get 1:1 Help Now