EnumProcesses Example by MSDN;
Code:
#include <windows.h>
#include <stdio.h>
#include "psapi.h"
void PrintProcessNameAndID( DWORD processID )
{
char szProcessName[MAX_PATH] = "unknown";
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
}
else return;
}
else return;
// Print the process name and identifier.
printf( "%s (Process ID: %u)\n", szProcessName, processID );
CloseHandle( hProcess );
}
void main( )
{
// Get the list of process identifiers.
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process.
for ( i = 0; i < cProcesses; i++ )
PrintProcessNameAndID( aProcesses[i] );
}
The main function obtains a list of processes by using
the EnumProcesses function. For each process, main calls the
PrintProcessNameAndID function, passing it the process identifier.
PrintProcessNameAndID in turn calls the OpenProcess function
to obtain the process handle. If OpenProcess fails, the output
shows only the process identifier. For example, OpenProcess
fails for the Idle and CSRSS processes because their
access
restrictions prevent user-level code from opening them.
Next,
PrintProcessNameAndID calls the EnumProcessModules
function to obtain the module handles. Finally, PrintProcessNameAndID calls the GetModuleBaseName
function to obtain the name of the executable
Microsoft Windows CE 3.0
SendMessage
This function sends the specified message to a window
or
windows. SendMessage calls the window procedure for
the specified window and does not return until the
window procedure has processed the message.
The PostMessage function, in contrast, posts a
message to a thread's message queue and
returns immediately.
LRESULT SendMessage(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam );
Parameters
hWnd
[in] Handle to the window whose window procedure will
receive the message. If this parameter is
HWND_BROADCAST, the message is sent to all top-level
windows in the system, including disabled or invisible
unowned windows, overlapped windows, and pop-up
windows; but the message is not sent to
child windows.
Msg
[in] Specifies the message to be sent.
wParam
[in] Specifies additional message-specific information.
lParam
[in] Specifies additional message-specific information.
Return Values
The return value specifies
FindWindow() example by me.
hwnd = FindWindow("FileView", TEXT("Afx:400000:8:10011:0:0"));
handle to window = FindWindow(window caption, class name);