Browse Source

fix everything

main
Hendrik Langer 6 years ago
parent
commit
e29e7f3d90
  1. BIN
      windows-snapshot-tool/bin/freeze.exe
  2. 38
      windows-snapshot-tool/src/LimitSingleInstance.h
  3. 12
      windows-snapshot-tool/src/main.cpp

BIN
windows-snapshot-tool/bin/freeze.exe

Binary file not shown.

38
windows-snapshot-tool/src/LimitSingleInstance.h

@ -0,0 +1,38 @@
#ifndef LimitSingleInstance_H
#define LimitSingleInstance_H
#include <windows.h>
//This code is from Q243953 in case you lose the article and wonder
//where this code came from.
class CLimitSingleInstance
{
protected:
DWORD m_dwLastError;
HANDLE m_hMutex;
public:
CLimitSingleInstance(TCHAR *strMutexName)
{
//Make sure that you use a name that is unique for this application otherwise
//two apps may think they are the same if they are using same name for
//3rd parm to CreateMutex
m_hMutex = CreateMutex(NULL, FALSE, strMutexName); //do early
m_dwLastError = GetLastError(); //save for use later...
}
~CLimitSingleInstance()
{
if (m_hMutex) //Do not forget to close handles.
{
CloseHandle(m_hMutex); //Do as late as possible.
m_hMutex = NULL; //Good habit to be in.
}
}
BOOL IsAnotherInstanceRunning()
{
return (ERROR_ALREADY_EXISTS == m_dwLastError);
}
};
#endif

12
windows-snapshot-tool/src/main.cpp

@ -1,4 +1,8 @@
#include "resource.h"
#include "LimitSingleInstance.h"
CLimitSingleInstance g_SingleInstanceObj(TEXT("Global\\{38593226-AABB-1234-7592-D335AAB6F22A}"));
/*variables*/
UINT WM_TASKBAR = 0;
@ -26,6 +30,13 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
LPSTR lpszArgument,
int nCmdShow)
{
if (g_SingleInstanceObj.IsAnotherInstanceRunning())
{
HWND existingApp = FindWindow(0, szClassName);
SendMessage(existingApp, WM_DESTROY, 0, 0);
//return FALSE;
}
/* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
@ -181,6 +192,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
break;
case WM_HOTKEY_FREEZE:
case WM_HOTKEY:
{
doScreenshot();
}

Loading…
Cancel
Save