Win32 コンソール アプリケーション キット
|
|
日時: 2010/08/04 18:03
名前: lightbox
|
以下は、キットのダウンロードページです。
Win32 コンソール アプリケーション キット
findwindow.cpp
指定したタイトル(必要ならばウインドウクラス名)より、ウインドウハンドル
を取得して標準出力へ出力します
movewindow.cpp
指定したウインドウハンドルを持つウインドウの位置を変更します
位置を省略すると、デスクトップの中央に移動します
最後に最前面にウインドウを持ってきます
拡張子:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
HWND hWnd;
int x,y;
if ( argc == 1 ) {
printf("%s\n", "movewindow.exe ウインドウハンドル [X Y]" );
exit( 1 );
}
hWnd = (HWND)(_wtol( argv[1] ));
RECT drt;
RECT rt;
if ( argc == 2 ) {
GetWindowRect( GetDesktopWindow(), &drt );
GetWindowRect( hWnd, &rt );
x = ( (drt.right - drt.left) - (rt.right - rt.left) ) / 2;
y = ( (drt.bottom - drt.top) - (rt.bottom - rt.top) ) / 2;
MoveWindow( hWnd, x, y, rt.right - rt.left , rt.bottom- rt.top, true );
}
else {
x = _wtol( argv[2] );
y = _wtol( argv[3] );
GetWindowRect( hWnd, &rt );
MoveWindow( hWnd, x, y, rt.right - rt.left , rt.bottom- rt.top, true );
}
SetForegroundWindow( hWnd );
return 0;
}
postmessage.cpp
メッセージをポストします。
引数は、ウインドウハンドル メッセージID wParam lParam です
foreground.cpp
ウインドウを最前面に移動します
|
|
run_and_win_handle.cpp ( No.1 ) |
|
日時: 2010/08/04 17:43
名前: lightbox
|
日時: 2010/08/04 17:43 名前: lightbox
拡張子:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam );
static DWORD pid;
static HWND hTarget;
int _tmain(int argc, _TCHAR* argv[])
{
// プログラムを実行して、PID を取得し
// PID から Window ハンドルを取得
int ret;
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory( &pi , sizeof(PROCESS_INFORMATION));
ZeroMemory( &si , sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
// 実行
ret = CreateProcess(
NULL,
argv[1],
NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
// ユーザーからの入力を待っている状態になるまで待つ
// ( タイムアウト 60 秒
WaitForInputIdle(pi.hProcess,60000);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
pid = pi.dwProcessId;
// Window ハンドルを Callback で取得
EnumWindows( EnumWindowsProc, 0 );
printf("%u\n", hTarget );
return 0;
}
// *********************************************************
// トップレベル用 ウインドウの列挙
// *********************************************************
BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam )
{
DWORD ProcessId;
GetWindowThreadProcessId( hWnd, &ProcessId );
// 実行したプロセス内で表示されるウインドウを選ぶ
if ( pid == ProcessId && IsWindowVisible( hWnd ) ) {
hTarget = hWnd;
return false;
}
return true;
}
|
sample.bat ( No.2 ) |
日時: 2010/08/04 18:05 名前: lightbox
|
|
|
|