예제 #1
0
void initDLL()
{
	USES_CONVERSION;

	atexit( exitDLL );

	hSHlib = LoadLibrary( _T("shfolder.dll") );
	if( hSHlib != NULL )
		lpSHGetFolderPath = (LPSHGETFOLDERPATH)GetProcAddress( hSHlib, W2A(_T("SHGetFolderPathA")) );

	hK32lib = LoadLibrary( _T("kernel32.dll") );
	if (hK32lib != NULL)
	{
		lpCreateToolhelp32Snapshot	= (LPCREATETOOLHELP32SNAPSHOT)GetProcAddress(	hK32lib, W2A(_T("CreateToolhelp32Snapshot")));
		lpProcess32First			= (LPPROCESS32FIRST)GetProcAddress(				hK32lib, W2A(_T("Process32First")));
		lpProcess32Next				= (LPPROCESS32NEXT)GetProcAddress(				hK32lib, W2A(_T("Process32Next")));
	}

	std::string strVersion;
	UINT uWinPlatform;
	getWinVersion( strVersion, uWinPlatform );
	if( uWinPlatform == VER_PLATFORM_WIN32_NT )
	{
		hPSlib = LoadLibrary( _T("psapi.dll") );

		if (hPSlib != NULL)
		{
			lpEnumProcesses		 = (LPENUMPROCESSES)GetProcAddress(		hPSlib, W2A(_T("EnumProcesses")));
			lpEnumProcessModules = (LPENUMPROCESSMODULES)GetProcAddress(hPSlib, W2A(_T("EnumProcessModules")));
			lpGetModuleBaseName  = (LPGETMODULEBASENAME)GetProcAddress(	hPSlib, W2A(_T("GetModuleBaseNameA")));
		}
	}
}
void CCloseApplicationDlg::OnTimer(UINT nIDEvent)
{
	// Declare variables
	CString sTemp;
	bool bRunning = false;

	// Did we receive the right timer event?
	if (nIDEvent == TIMER_COUNTDOWN)
	{
		// Check if the application is still running
		std::string strVersion;
		UINT uWinPlatform;
		UINT uVersion = getWinVersion(strVersion, uWinPlatform);
		CString sProcess = CPath::Instance()->ExtractFileName(m_sApplicationPath);
		if ((uVersion == WINDOWS_NT3) || (uVersion == WINDOWS_NT4))
		{
			bRunning = NTApplicationRunning(sProcess.GetBuffer(sProcess.GetLength()));
		}
		else
		{
			bRunning = AllWinApplicationRunning(sProcess.GetBuffer(sProcess.GetLength()));
		}

		// Is the application running?
		if (bRunning == false)
		{
			// No, we can close the dialog
			EndDialog(IDOK);
		}

		// Lower the timer
		m_iCountDown--;

		// Set up text
		if (m_iCountDown > 0)
		{
			// Set explanation text
			sTemp.Format(CLanguage::Instance()->GetString(IDS_CLOSEAPPLICATION_EXPLANATION), m_sApplicationTitle,
				m_iCountDown, m_sApplicationTitle);
			m_lblExplanation.SetWindowText(sTemp);

			// Update progressbar
			m_prgEnd.SetPos(m_prgEnd.GetPos() + 1);
		}
		else
		{
			// Kill timer
			KillTimer(TIMER_COUNTDOWN);

			// Force application to close
			OnBtnEndNow();
		}
	}
}
예제 #3
0
void Gripper::create()
{
	RECT		rc		= {0};
	POINT		pt		= {0};

	// start hooking
	::SetWindowPos(_pCont->getHSelf(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
	::SetCapture(_hSelf);
	winVer ver = getWinVersion();
	hookMouse = ::SetWindowsHookEx(ver >= WV_W2K?WH_MOUSE_LL:WH_MOUSE, (HOOKPROC)hookProcMouse, _hInst, 0);

    if (!hookMouse)
    {
        DWORD dwError = ::GetLastError();
        TCHAR  str[128];
        ::wsprintf(str, TEXT("GetLastError() returned %lu"), dwError);
        ::MessageBox(NULL, str, TEXT("SetWindowsHookEx(MOUSE) failed"), MB_OK | MB_ICONERROR);
    }

	if (ver < WV_VISTA)
	{
		hookKeyboard = ::SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)hookProcKeyboard, _hInst, 0);
		if (!hookKeyboard)
		{
			DWORD dwError = ::GetLastError();
			TCHAR  str[128];
			::wsprintf(str, TEXT("GetLastError() returned %lu"), dwError);
			::MessageBox(NULL, str, TEXT("SetWindowsHookEx(KEYBOARD) failed"), MB_OK | MB_ICONERROR);
		}
	}
//  Removed regarding W9x systems
//	mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

	// calculate the mouse pt within dialog
	::GetCursorPos(&pt);

	// get tab informations
	initTabInformation();

	if (_pCont->isFloating() == true)
	{
		::GetWindowRect(_pCont->getHSelf(), &rc);
	}
	else
	{
		_pCont->getClientRect(rc);
		::ScreenToClient(_pCont->getHSelf(), &pt);
	}

	_ptOffset.x	= pt.x - rc.left;
	_ptOffset.y	= pt.y - rc.top;
}
void CCloseApplicationDlg::OnBtnEndNow()
{
	// OK, kill the process
	std::string strVersion;
	UINT uWinPlatform;
	UINT uVersion = getWinVersion(strVersion, uWinPlatform);
	CString sProcess = CPath::Instance()->ExtractFileName(m_sApplicationPath);
	if ((uVersion == WINDOWS_NT3) || (uVersion == WINDOWS_NT4))
	{
		CloseNTApplication(sProcess.GetBuffer(sProcess.GetLength()), true);
	}
	else
	{
		CloseAllWinApplication(sProcess.GetBuffer(sProcess.GetLength()), true);
	}

	// Set return code
	EndDialog(IDOK);
}
BOOL CCloseApplicationDlg::OnInitDialog()
{
	// Declare variables
	CString sTemp;
	CLanguage * pLanguage = CLanguage::Instance();

	// Call original function
	CDialog::OnInitDialog();

	// Set icon
	m_icoApplication.SetSize(40, 40);
	m_icoApplication.SetTransparentColor(RGB(0, 0, 0));
	m_icoApplication.LoadIcon(m_hIcon);

	// Set window text
	sTemp.Format(pLanguage->GetString(IDS_CLOSEAPPLICATION_TITLE), m_sApplicationTitle);
	SetWindowText(sTemp);
	m_lblTitle.SetWindowText(sTemp);

	// Set explanation text
	sTemp.Format(pLanguage->GetString(IDS_CLOSEAPPLICATION_EXPLANATION), m_sApplicationTitle,
		m_iCountDown, m_sApplicationTitle);
	m_lblExplanation.SetWindowText(sTemp);

	// Set button text
	m_btnCancel.SetWindowText(pLanguage->GetString(IDS_GENERAL_CANCEL));
	m_btnEndNow.SetWindowText(pLanguage->GetString(IDS_CLOSEAPPLICATION_ENDNOW));

	// Create and set font
	m_fntTitle.DeleteObject();
	m_fntTitle.CreateFont(
		20,								// nHeight
		0,								// nWidth
		0,								// nEscapement
		0,								// nOrientation
		FW_BOLD,						// nWeight
		FALSE,							// bItalic
		FALSE,							// bUnderline
		0,								// cStrikeOut
		DEFAULT_CHARSET,				// nCharSet
		OUT_DEFAULT_PRECIS,				// nOutPrecision
		CLIP_DEFAULT_PRECIS,			// nClipPrecision
		PROOF_QUALITY,					// nQuality
		DEFAULT_PITCH | FF_DONTCARE,	// nPitchAndFamily
		NULL);
	m_lblTitle.SetFont(&m_fntTitle);

	// Auto resize controls
	AutoResizeControls();

	// Set control properties
	m_prgEnd.SetRange32(0, CLOSEAPPLICATION_TIME);
	m_prgEnd.SetPos(0);

	// Start timer
	SetTimer(TIMER_COUNTDOWN, 1000, NULL);

	// Try to close application in a nice way
	std::string strVersion;
	UINT uWinPlatform;
	UINT uVersion = getWinVersion(strVersion, uWinPlatform);
	CString sProcess = CPath::Instance()->ExtractFileName(m_sApplicationPath);
	if ((uVersion == WINDOWS_NT3) || (uVersion == WINDOWS_NT4))
	{
		CloseNTApplication(sProcess.GetBuffer(sProcess.GetLength()));
	}
	else
	{
		CloseAllWinApplication(sProcess.GetBuffer(sProcess.GetLength()));
	}

	// Return TRUE unless you want to set focus to a control
	return TRUE;
}
예제 #6
0
static _WinVersion* GetWinVer ()
{
  _WinVersion *winver = getWinVersion ();
  return winver;
}