int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
傻吊代码
不说啥
注册消息,
和互斥体
然后postmessage广播消息 即可
#7
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
//...
#ifdef SINGLE_INSTANCE
HANDLE hMutex;
hMutex = CreateMutex(NULL, FALSE, "MySigleInstance" );
if ( WaitForSingleObject(hMutex, 1000) == WAIT_TIMEOUT ) {
// There is another instance out there, but it is taking to long to
// locate, just exit
return FALSE;
}
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
ReleaseMutex(hMutex);
return FALSE;
}
#endif
//...
#ifdef SINGLE_INSTANCE
ReleaseMutex(hMutex);
CloseHandle(hMutex);
#endif
return 0;
}