Click here to Skip to main content
15,892,697 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Visual Studio 2005 application deployment Pin
bigdenny20011-Feb-07 0:00
bigdenny20011-Feb-07 0:00 
GeneralRe: Visual Studio 2005 application deployment Pin
Waldermort11-Feb-07 0:40
Waldermort11-Feb-07 0:40 
AnswerRe: Visual Studio 2005 application deployment Pin
bob1697211-Feb-07 5:52
bob1697211-Feb-07 5:52 
AnswerRe: Visual Studio 2005 application deployment Pin
Mark Salsbery11-Feb-07 7:58
Mark Salsbery11-Feb-07 7:58 
QuestionHow to prevent switch (or focus) to an application? Pin
Brooks Harris10-Feb-07 13:45
Brooks Harris10-Feb-07 13:45 
AnswerRe: How to prevent switch (or focus) to an application? Pin
Waldermort11-Feb-07 1:34
Waldermort11-Feb-07 1:34 
GeneralRe: How to prevent switch (or focus) to an application? Pin
Brooks Harris11-Feb-07 5:11
Brooks Harris11-Feb-07 5:11 
AnswerRe: How to prevent switch (or focus) to an application? Pin
Brooks Harris11-Feb-07 11:36
Brooks Harris11-Feb-07 11:36 
I believe I've found a solution.

The following appraoch will find the Apps window, minimize it, and suspend the Apps threads. The user can't reach the App by mouse, Alt-Tab, or Task Manager.

On resume, its all restoreed.

//////////////////////
By enumnerating the desktop windows ( EnumDesktopWindows() ) and searching for the App's registered class name ( GetClassName())in the Enum CallBack one can find the application Window.

Its a good idea to minimize the App before suspending
( ::ShowWindow(m_hwndSuspended, SW_MINIMIZE);)
so the user does see the unpainted app

GetWindowThreadProcessId() will give the process ID. Open it:

m_hProcessSuspended =
OpenProcess(PROCESS_ALL_ACCESS ,FALSE, m_dwProcessIdSuspended) ;

//////////////////////
Now suspend the thread - credit for this approach goes to
// File Name: AdvancedTaskManagerDlg.cpp
// Contents : Implementation of AdvancedTaskManagerDlg class.
// Originator: Madhu Raykar.

See -
CAdvancedTaskManagerDlg::PauseResumeThreadList() of AdvancedTaskManagerDlg.cpp

This version is slightly modified :::

BOOL CAdvancedTaskManagerDlg::PauseResumeThreadList(DWORD dwOwnerPID, bool bResumeThread)
{
HANDLE hThreadSnap = NULL;
BOOL bRet = FALSE;
THREADENTRY32 te32 = {0};

// Take a snapshot of all threads currently in the system.

hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hThreadSnap == INVALID_HANDLE_VALUE)
return (FALSE);

// Fill in the size of the structure before using it.

te32.dwSize = sizeof(THREADENTRY32);

// Walk the thread snapshot to find all threads of the process.
// If the thread belongs to the process, add its information
// to the display list.

if (Thread32First(hThreadSnap, &te32))
{
do
{
if (te32.th32OwnerProcessID == dwOwnerPID)
{
HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, te32.th32ThreadID);
if (bResumeThread)
{
// cout << _T("Resuming Thread 0x") << cout.setf( ios_base::hex ) << te32.th32ThreadID << '\n';
ResumeThread(hThread);
}
else
{
// cout << _T("Suspending Thread 0x") << cout.setf( ios_base::hex ) << te32.th32ThreadID << '\n';
SuspendThread(hThread);
}
CloseHandle(hThread);
}
}
while (Thread32Next(hThreadSnap, &te32));
bRet = TRUE;
}
else
bRet = FALSE; // could not walk the list of threads

// Do not forget to clean up the snapshot object.
CloseHandle (hThreadSnap);

return (bRet);
}

//////////////////////
// be usre to resume and restore the App

if(m_dwProcessIdSuspended && m_hProcessSuspended != NULL)
{
BOOL bRet= PauseResumeThreadList(m_dwProcessIdSuspended, TRUE);
BOOL bRetShow = ::ShowWindow(m_hwndSuspended, SW_RESTORE);
m_hwndSuspended = NULL;
CloseHandle(m_hProcessSuspended);
m_hProcessSuspended = NULL;
m_dwProcessIdSuspended = 0;
}

//////////////////////


-Brooks







Brooks

AnswerRe: How to prevent switch (or focus) to an application? Pin
Brooks Harris11-Feb-07 11:53
Brooks Harris11-Feb-07 11:53 
QuestionDevC++ Clock Pin
EagleAmerican1410-Feb-07 11:25
EagleAmerican1410-Feb-07 11:25 
AnswerRe: DevC++ Clock Pin
El Corazon10-Feb-07 14:25
El Corazon10-Feb-07 14:25 
AnswerRe: DevC++ Clock Pin
Christian Graus10-Feb-07 14:51
protectorChristian Graus10-Feb-07 14:51 
QuestionConfused about Mutex? Pin
nde_plume10-Feb-07 6:12
nde_plume10-Feb-07 6:12 
AnswerRe: Confused about Mutex? Pin
Waldermort10-Feb-07 6:17
Waldermort10-Feb-07 6:17 
GeneralRe: Confused about Mutex? Pin
nde_plume10-Feb-07 6:47
nde_plume10-Feb-07 6:47 
GeneralRe: Confused about Mutex? Pin
Waldermort10-Feb-07 7:05
Waldermort10-Feb-07 7:05 
QuestionDisplay settings Pin
Waldermort10-Feb-07 5:31
Waldermort10-Feb-07 5:31 
AnswerRe: Display settings Pin
Christian Graus10-Feb-07 11:05
protectorChristian Graus10-Feb-07 11:05 
GeneralRe: Display settings Pin
Waldermort10-Feb-07 11:25
Waldermort10-Feb-07 11:25 
QuestionDirect3D forum Pin
Waldermort10-Feb-07 3:45
Waldermort10-Feb-07 3:45 
AnswerRe: Direct3D forum Pin
Hamid_RT10-Feb-07 20:46
Hamid_RT10-Feb-07 20:46 
QuestionESP exception Pin
sanjutvm10-Feb-07 3:33
sanjutvm10-Feb-07 3:33 
AnswerRe: ESP exception Pin
Cedric Moonen10-Feb-07 5:25
Cedric Moonen10-Feb-07 5:25 
GeneralRe: ESP exception Pin
sanjutvm12-Feb-07 5:15
sanjutvm12-Feb-07 5:15 
Questionwindow update problem? Pin
amitmistry_petlad 10-Feb-07 1:23
amitmistry_petlad 10-Feb-07 1:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.