DO EVENTS

Whilst your application will be multi threaded if you hold waiting for something you need to use this to allow other tasks on the same thread to execute, and to tell the OS that your holding so it’s OK for it to attend to other things.


	System::Windows::Forms::Application::DoEvents();
Warning!

Remember that using this can potentially cause the same function that is using it to be re-called if whatever triggered it to be called happens again. You may need to use some sort of semaphore to protect against this.

Debug Mode Only Compiler Check


#if _DEBUG			//Only do if we're in debug mode
#endif

#if !_DEBUG			//Only do if we're in release mode
#endif

#if defined(_DEBUG) && defined(DEBUG_AUTO_LOG_IN_USER_ID)
#endif

Exiting The Application (i.e. File > Exit menu item)


Application::Exit();

Note that the Form..::.Closed and Form..::.Closing events are not raised when the Application..::.Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form..::.Close method for each open form individually before calling the Exit method.
Or just use this instead:


	this->Close();

Preventing Multiple Instances Of An Application Running

Place this in the YourApName.cpp file before Application::Run is called. It needs to be here as if you do it in the main forms constructor the application won’t exit correctly. You should only do it there if you change the Application::Exit to something else.


//----- CHECK FOR APPLICATION ALREADY RUNNING (MULTIPLE INSTANCES ARE NOT PERMITTED) -----
Process ^CurrentProcess = System::Diagnostics::Process::GetCurrentProcess();
array ^CurrentProcesses = System::Diagnostics::Process::GetProcessesByName(CurrentProcess->ProcessName);
if (CurrentProcesses->Length > 1)
{
	MessageBox::Show(L"There is already another instance of the application running", Application::ProductName, MessageBoxButtons::OK, MessageBoxIcon::Asterisk);
	Application::Exit();
	return 0;
}

Get Windows Version

Use the GetVersionEx function

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *