|
#define END_CAPTURE \
{ \
this->CaptureFlg = false; \
ReleaseCapture(); \
DWORD ThisThread, ActiveThread, pid; \
ActiveThread = GetWindowThreadProcessId( \
GetForegroundWindow(), \
&pid \
); \
ThisThread = GetCurrentThreadId(); \
if ( ActiveThread != ThisThread ) { \
AttachThreadInput(ThisThread, ActiveThread, true ); \
AttachThreadInput(ThisThread, ActiveThread, false ); \
::BringWindowToTop( this->hWnd ); \
} \
else { \
::SetForegroundWindow( this->hWnd ); \
} \
}
void MyDlg::WMAll()
{
switch( this->message ) {
case WM_LBUTTONDOWN:
if ( this->CaptureFlg ) {
POINT pt;
HWND hTarget;
pt.x = (short)LOWORD(this->lParam);
pt.y = (short)HIWORD(this->lParam);
::ClientToScreen( this->hWnd, &pt );
hTarget = ::WindowFromPoint( pt );
if ( hTarget == NULL ) {
this->StatusSetText("キャプチャに失敗しました");
END_CAPTURE
break;
}
::Sleep( 500 );
// デスクトップのデバイスコンテキストを取得
HDC hDc;
hDc = GetDC( GetDesktopWindow() );
if ( hDc == NULL ) {
this->StatusSetText(
"デバイスコンテキストを取得できませんでした"
);
END_CAPTURE
break;
}
HDC hDCMem;
HBITMAP hBitmap;
HGDIOBJ hOld;
RECT rt;
// 目的のウインドウの位置情報
GetWindowRect( hTarget, &rt );
// デスクトップと互換性のあるデバイスコンテキストを作成
hDCMem = CreateCompatibleDC( hDc );
if ( hDCMem == NULL ) {
ReleaseDC( GetDesktopWindow(), hDc );
END_CAPTURE
}
// デスクトップと互換性のあるビットマップを目的のウインドウの大きさで作成
hBitmap = CreateCompatibleBitmap(
hDc,
rt.right - rt.left,
rt.bottom - rt.top
);
// デバイスコンテキストにビットマップを選択
hOld = SelectObject( hDCMem, hBitmap );
// デスクトップからメモリにイメージを転送
BitBlt(
hDCMem,
0,
0,
rt.right - rt.left,
rt.bottom - rt.top,
hDc,
rt.left,
rt.top,
SRCCOPY
);
// デスクトツプのデバイスコンテキストを解放
ReleaseDC( GetDesktopWindow(), hDc );
LOAD_DLL(imgctl.dll)
if ( this->lib != NULL ) {
LOAD_FUNC(DELETEDIB,DeleteDIB)
LOAD_FUNC(DCTODIB,DCtoDIB)
LOAD_FUNC(HEADDIB,HeadDIB)
LOAD_FUNC(DIBTOBMP,DIBtoBMP)
}
else {
this->StatusSetText("imgctl.dll をロードできませんでした");
END_CAPTURE
break;
}
// メモリデバイスコンテキストより DIB を作成
hDib = DCtoDIB(
hDCMem,
0,
0,
rt.right - rt.left,
rt.bottom - rt.top
);
// メモリデバイスコンテキストを解放
SelectObject( hDCMem, hOld );
DeleteObject( hBitmap );
DeleteDC( hDCMem );
// DIB より BMP ファイルを作成
if ( !DIBtoBMP( "c:\\temp\\capture.bmp", hDib ) ) {
this->StatusSetText("ファイルに保存できませんでした");
END_CAPTURE
DeleteDIB( hDib );
FreeLibrary( this->lib );
break;
}
// imgctl.dll の終了処理
DeleteDIB( hDib );
FreeLibrary( this->lib );
this->StatusSetText("キャプチャは正常終了しました");
END_CAPTURE
}
break;
case WM_CAPTURECHANGED:
if ( this->CaptureFlg ) {
this->StatusSetText("キャプチャは解除されました");
}
break;
}
}
| |