LoginSignup
0
0

More than 3 years have passed since last update.

画面キャプチャ

Last updated at Posted at 2021-03-29

// Console.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include "stdafx.h"
#include 


struct  cell{
    HWND hWnd;
    TCHAR WindowName[256];
};

BOOL  CALLBACK  EnumWndProc( HWND hWnd, LPARAM lParam )
{
    TCHAR buff[256];
    GetWindowText( hWnd, buff, sizeof(buff));//ウインドウの文字を取得して、
    if(_tcscmp(buff,((cell*)lParam)->WindowName)==0){//名前が一致したら、
        ((cell*)lParam)->hWnd = hWnd;//ウィンドウハンドルを渡す
    }
    return true;
}



int _tmain(int argc, _TCHAR* argv[])
{

    cell c;
    c.hWnd =NULL;
    _tcscpy_s(c.WindowName, TEXT("電卓"));//検索するウィンドウの名前

    EnumWindows( EnumWndProc, (LPARAM)&c);

    if(c.hWnd != NULL){
        //目的のウインドウハンドルが取得できました
        //SetWindowPos(c.hWnd,HWND_TOP,0 ,0 ,100,100,SWP_SHOWWINDOW);//ウインドウのサイズを変更
    }
    else {
        return 0;
    }

    #if 0   // 横
        #define X   28
        #define Y   101
        #define W   (78 - 1)
        #define H   (60 - 1)
    #else
        #define X   37
        #define Y   92
        #define W   (60 - 1)
        #define H   (78 - 1)
    #endif

    

    OpenClipboard(NULL);

    HBITMAP  hBitmap;
    HDC hDC;
    HWND hWnd = c.hWnd; //GetForegroundWindow();
    hDC = GetDC(hWnd);

    HDC destDC;



    destDC = CreateCompatibleDC(hDC);
    hBitmap = CreateCompatibleBitmap(hDC, W, H);

    SelectObject(destDC, hBitmap);
    BitBlt(destDC, 0, 0, W, H, hDC, X, Y, SRCCOPY);

    if (0) {
        HPEN hPen;
        hPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
        SelectObject(destDC, hPen);
        MoveToEx(destDC, 0, H-1, NULL);
        LineTo(destDC, 2, H-1);
        MoveToEx(destDC, W-1, 0, NULL);
        LineTo(destDC, W-1, 2);
    }


    EmptyClipboard();
    SetClipboardData(CF_BITMAP, hBitmap);
    CloseClipboard();


    return 0;
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0