LoginSignup
0
1

More than 5 years have passed since last update.

c++ builder > ソフト操作 > notepad を開いて、ステータスバーを表示 / 非表示 > Alt+V, S の送信

Last updated at Posted at 2015-09-15
動作確認
Windows 7Pro 32bit

C++ Builderから別ソフトを操作するための方法。

試しにnotepadを表示して、[表示(V)]->[ステータスバー(S)]を実行してみる。

参考1: http://www.gesource.jp/weblog/?p=5143

sample.cpp
void __fastcall TForm1::Button1Click(TObject *Sender)
{

    STARTUPINFO si = {};
    si.cb = sizeof(si);
    PROCESS_INFORMATION pi = {};

    CreateProcess(NULL, L"notepad.exe", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);

    WaitForInputIdle(pi.hProcess, INFINITE);
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);

    HWND hwnd = GetDesktopWindow();
    hwnd = FindWindowEx(hwnd, NULL, L"Notepad", NULL);

    SetForegroundWindow(hwnd);

    for(int loop=0; loop<3; loop++) {
        Sleep(3000);
        keybd_event(VK_MENU, 0, 0, 0); // Altキー
        keybd_event('V', 0, 0, 0);
        keybd_event('S', 0, 0, 0);
        keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); // これがないとAltを押したままになる
    }

    keybd_event(VK_RETURN, 0, 0, 0);

}

KEYEVENTF_KEYUPは大切。これがないとAltが押しっぱなしになり、何度かやってしまって、不自由になり、Windowsをログアウトした。

ひっかかり

.についてはそのまま送のではなくVK_DECIMALを送らないといけない。
http://homepage3.nifty.com/ic/help/rmfunc/vkey.htm

IPアドレスを送るときに失敗した。

0
1
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
1