EDN Admin
Well-known member
Hello,
Could you please help me how to stop the screensaver from running under Windows embedded standard 7? Below is my little snippet in Visual studio c++ 6, It works most of the time but some time it just not too reliably.
HWND hwnd = NULL;
DWORD dwProcID = FindProcessID("Screensaver.scr", hwnd); //known scrnsvr proccess name.
bool bScrnsvrRunning = (dwProcID && ::IsWindow(hwnd) && ::IsWindowVisible(hwnd));
if(bScrnsvrRunning )
{
if
:IsWindow(hwnd) && ::IsWindowVisible(hwnd))
{
::SendMessage( hwnd, WM_CLOSE, NULL, NULL );
}
if (!SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, // system parameter to set
FALSE,NULL,SPIF_SENDWININICHANGE))
{
sprintf(chBuffer, "SPI_SETSCREENSAVEACTIVE failed. Error Code(%d)", GetLastError()); OutputDebugString(chBuffer);
}
// disable screen saver by moving mouse and pressing ctrl key
mouse_event(MOUSEEVENTF_MOVE,500,0,0,0);
mouse_event(MOUSEEVENTF_MOVE,-1,0,0,0);
keybd_event(VK_CONTROL,0x9d,KEYEVENTF_KEYUP , 0);
} -----------------------------------------------------------------------------------------------------------------------
FindProcessID(std::string sProcess, HWND& hwnd)
{
DWORD dwReturn = 0;
hwnd = NULL;
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
return dwReturn;
}
// Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 );
// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
//FindScreenSaverPID - Could not get system process information
CloseHandle( hProcessSnap ); // clean the snapshot object
return dwReturn;
}
// Now walk the snapshot of processes, and look for sScreenSaver process
do
{
if(pe32.szExeFile == sProcess)
{
dwReturn = pe32.th32ProcessID;
}
} while((dwReturn == 0) && Process32Next( hProcessSnap, &pe32 ));
CloseHandle( hProcessSnap );
//Loop over the windows and find the window handle of the
//processID in dwReturn and assign it to the hwnd reference
if(dwReturn != 0)
{
HWND hWndCurr = ::FindWindow(NULL,NULL);
while (hWndCurr)
{
if
:GetParent(hWndCurr) == NULL)
{
DWORD nCurrProcID = 0;
GetWindowThreadProcessId(hWndCurr, &nCurrProcID) ;
if (nCurrProcID == dwReturn)
{
hwnd = hWndCurr;
break;
}
}
hWndCurr = ::GetWindow(hWndCurr, GW_HWNDNEXT);
}
}
return dwReturn;
}
View the full article
Could you please help me how to stop the screensaver from running under Windows embedded standard 7? Below is my little snippet in Visual studio c++ 6, It works most of the time but some time it just not too reliably.
HWND hwnd = NULL;
DWORD dwProcID = FindProcessID("Screensaver.scr", hwnd); //known scrnsvr proccess name.
bool bScrnsvrRunning = (dwProcID && ::IsWindow(hwnd) && ::IsWindowVisible(hwnd));
if(bScrnsvrRunning )
{
if

{
::SendMessage( hwnd, WM_CLOSE, NULL, NULL );
}
if (!SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, // system parameter to set
FALSE,NULL,SPIF_SENDWININICHANGE))
{
sprintf(chBuffer, "SPI_SETSCREENSAVEACTIVE failed. Error Code(%d)", GetLastError()); OutputDebugString(chBuffer);
}
// disable screen saver by moving mouse and pressing ctrl key
mouse_event(MOUSEEVENTF_MOVE,500,0,0,0);
mouse_event(MOUSEEVENTF_MOVE,-1,0,0,0);
keybd_event(VK_CONTROL,0x9d,KEYEVENTF_KEYUP , 0);
} -----------------------------------------------------------------------------------------------------------------------
FindProcessID(std::string sProcess, HWND& hwnd)
{
DWORD dwReturn = 0;
hwnd = NULL;
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
return dwReturn;
}
// Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 );
// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
//FindScreenSaverPID - Could not get system process information
CloseHandle( hProcessSnap ); // clean the snapshot object
return dwReturn;
}
// Now walk the snapshot of processes, and look for sScreenSaver process
do
{
if(pe32.szExeFile == sProcess)
{
dwReturn = pe32.th32ProcessID;
}
} while((dwReturn == 0) && Process32Next( hProcessSnap, &pe32 ));
CloseHandle( hProcessSnap );
//Loop over the windows and find the window handle of the
//processID in dwReturn and assign it to the hwnd reference
if(dwReturn != 0)
{
HWND hWndCurr = ::FindWindow(NULL,NULL);
while (hWndCurr)
{
if

{
DWORD nCurrProcID = 0;
GetWindowThreadProcessId(hWndCurr, &nCurrProcID) ;
if (nCurrProcID == dwReturn)
{
hwnd = hWndCurr;
break;
}
}
hWndCurr = ::GetWindow(hWndCurr, GW_HWNDNEXT);
}
}
return dwReturn;
}
View the full article