// w32.cpp : 启动EPSnap , 模拟按键 win+1 , 达到使EPSnap固定捕捉等目的。
// 哦也 , 2007-03-18 02:58:51 终于完成第一版
// v0.01 , 2007-03-18
// gudai (异域苍穹)
#include "stdafx.h"
#include <stdio.h>
#include <iostream.h>
#include <tlhelp32.h>
#include <shellapi.h>
void f_put( char * filename , char * data , char * mode);
BOOL IsProcessExists(LPCSTR ExeName);
void StartSnapProgram();
void SnapCreen();
void SnapWindowAndControllers();
void SnapExtendedWindow();
void SnapRectArea();
void SnapKey( unsigned char chr );
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char num;
StartSnapProgram();
if( strlen(lpCmdLine)>=1 )
num = lpCmdLine[0];
else
//num = getchar();
scanf("%d", &num);
switch( num )
{
case '1':
SnapCreen();
break;
case '2':
SnapWindowAndControllers();
break;
case '3':
//SnapExtendedWindow(); //EPSnap有bug,自动退出,该内存不能为read
break;
case '4':
SnapRectArea();
break;
default:
SnapRectArea();
}
//f_put ( "prog_params.txt" , lpCmdLine , "w");
return 0;
}
//捕捉屏幕
void SnapCreen(){SnapKey( '1' );}
//窗口或控件捕捉
void SnapWindowAndControllers(){SnapKey( '2' );}
//捕捉扩展窗口
void SnapExtendedWindow(){SnapKey( '3' );}
//捕捉指定区域
void SnapRectArea()
{
SnapKey( '4' );
}
void SnapKey( unsigned char chr )
{
keybd_event(VK_LWIN, 0, 0 ,0);
keybd_event( chr , 0, 0 ,0);
keybd_event( chr , 0, KEYEVENTF_KEYUP ,0);
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP,0);
}
void StartSnapProgram()
{
//HINSTANCE hi;
BOOL processExists = false;
processExists = IsProcessExists("EPSnap.exe");
if(processExists)
{
//f_put( "test.txt" , "good" , "w" );
}else{
//f_put( "test.txt" , "bad" , "w" );
ShellExecute(NULL,NULL,"EPSnap.exe",NULL,"",SW_SHOWNORMAL); //E:\\tools\\media\\snap\\epsnap\\
}
}
void KillProgram(LPCSTR ExeName)
{
}
//有点小问题,我终结epsnap.exe的时候,emule该内存不能为read,退出。
BOOL IsProcessExists(LPCSTR ExeName)
{
char *File ;
BOOL bRet;
bRet = false;
HANDLE hProcessSnap;
PROCESSENTRY32 pe32 ;//, me32
if (!ExeName || !ExeName[0])
return bRet;
File = strrchr(ExeName, '\\');
if (File!=0) ExeName = File+1;
hProcessSnap = CreateToolhelp32Snapshot(
TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == (HANDLE)-1) return false;
memset(&pe32, 0, sizeof(pe32));
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hProcessSnap, &pe32))
{
do {
File = strrchr(pe32.szExeFile, '\\');
File = File? File+1 : pe32.szExeFile;
if (strcmpi(File,ExeName)==0) {
bRet = TRUE;
break;
//EnumWindows((WNDENUMPROC)EnumWinProc,
//pe32.th32ProcessID);
}
}
while(Process32Next(hProcessSnap,&pe32));
}
CloseHandle(hProcessSnap);
return bRet;
}
void f_put( char * filename , char * data , char * mode)
{
FILE *pFile = fopen( filename , mode );
fwrite( data , 1 , strlen(data) , pFile);
fclose(pFile);
}
/*
BOOL CALLBACK EnumWinProc(HWND hwnd, LPARAM lParam)
{
DWORD dwID;
char tmpstr[9000];
LPTSTR tmptext;
memset( &tmptext , 0 , sizeof(tmptext));
memset(tmpstr , 0 , sizeof(tmpstr));
strcpy(tmpstr , "start Enum \n" );
GetWindowThreadProcessId(hwnd, &dwID);
GetWindowText(hwnd , tmptext , 20 );
strcat( tmpstr , tmptext );
strcat( tmpstr , "\n" );
memset( &tmptext , 0 , sizeof(tmptext));
if (dwID == (DWORD)lParam) {
//PostMessage(hwnd, WM_QUIT, 0, 0);
//return FALSE;
}
f_put( "EnumWindows.txt" , tmpstr , "a+" );
return TRUE;
}
*/
// 哦也 , 2007-03-18 02:58:51 终于完成第一版
// v0.01 , 2007-03-18
// gudai (异域苍穹)
#include "stdafx.h"
#include <stdio.h>
#include <iostream.h>
#include <tlhelp32.h>
#include <shellapi.h>
void f_put( char * filename , char * data , char * mode);
BOOL IsProcessExists(LPCSTR ExeName);
void StartSnapProgram();
void SnapCreen();
void SnapWindowAndControllers();
void SnapExtendedWindow();
void SnapRectArea();
void SnapKey( unsigned char chr );
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char num;
StartSnapProgram();
if( strlen(lpCmdLine)>=1 )
num = lpCmdLine[0];
else
//num = getchar();
scanf("%d", &num);
switch( num )
{
case '1':
SnapCreen();
break;
case '2':
SnapWindowAndControllers();
break;
case '3':
//SnapExtendedWindow(); //EPSnap有bug,自动退出,该内存不能为read
break;
case '4':
SnapRectArea();
break;
default:
SnapRectArea();
}
//f_put ( "prog_params.txt" , lpCmdLine , "w");
return 0;
}
//捕捉屏幕
void SnapCreen(){SnapKey( '1' );}
//窗口或控件捕捉
void SnapWindowAndControllers(){SnapKey( '2' );}
//捕捉扩展窗口
void SnapExtendedWindow(){SnapKey( '3' );}
//捕捉指定区域
void SnapRectArea()
{
SnapKey( '4' );
}
void SnapKey( unsigned char chr )
{
keybd_event(VK_LWIN, 0, 0 ,0);
keybd_event( chr , 0, 0 ,0);
keybd_event( chr , 0, KEYEVENTF_KEYUP ,0);
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP,0);
}
void StartSnapProgram()
{
//HINSTANCE hi;
BOOL processExists = false;
processExists = IsProcessExists("EPSnap.exe");
if(processExists)
{
//f_put( "test.txt" , "good" , "w" );
}else{
//f_put( "test.txt" , "bad" , "w" );
ShellExecute(NULL,NULL,"EPSnap.exe",NULL,"",SW_SHOWNORMAL); //E:\\tools\\media\\snap\\epsnap\\
}
}
void KillProgram(LPCSTR ExeName)
{
}
//有点小问题,我终结epsnap.exe的时候,emule该内存不能为read,退出。
BOOL IsProcessExists(LPCSTR ExeName)
{
char *File ;
BOOL bRet;
bRet = false;
HANDLE hProcessSnap;
PROCESSENTRY32 pe32 ;//, me32
if (!ExeName || !ExeName[0])
return bRet;
File = strrchr(ExeName, '\\');
if (File!=0) ExeName = File+1;
hProcessSnap = CreateToolhelp32Snapshot(
TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == (HANDLE)-1) return false;
memset(&pe32, 0, sizeof(pe32));
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hProcessSnap, &pe32))
{
do {
File = strrchr(pe32.szExeFile, '\\');
File = File? File+1 : pe32.szExeFile;
if (strcmpi(File,ExeName)==0) {
bRet = TRUE;
break;
//EnumWindows((WNDENUMPROC)EnumWinProc,
//pe32.th32ProcessID);
}
}
while(Process32Next(hProcessSnap,&pe32));
}
CloseHandle(hProcessSnap);
return bRet;
}
void f_put( char * filename , char * data , char * mode)
{
FILE *pFile = fopen( filename , mode );
fwrite( data , 1 , strlen(data) , pFile);
fclose(pFile);
}
/*
BOOL CALLBACK EnumWinProc(HWND hwnd, LPARAM lParam)
{
DWORD dwID;
char tmpstr[9000];
LPTSTR tmptext;
memset( &tmptext , 0 , sizeof(tmptext));
memset(tmpstr , 0 , sizeof(tmpstr));
strcpy(tmpstr , "start Enum \n" );
GetWindowThreadProcessId(hwnd, &dwID);
GetWindowText(hwnd , tmptext , 20 );
strcat( tmpstr , tmptext );
strcat( tmpstr , "\n" );
memset( &tmptext , 0 , sizeof(tmptext));
if (dwID == (DWORD)lParam) {
//PostMessage(hwnd, WM_QUIT, 0, 0);
//return FALSE;
}
f_put( "EnumWindows.txt" , tmpstr , "a+" );
return TRUE;
}
*/