Solved

modal

Posted on 1998-07-21
5
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

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

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

626 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