Solved

modal

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 54
xyBalance chalenge 58 104
repeatSeparator  java  challenge 13 59
sameEnds challenge 3 196
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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