Last active
April 29, 2019 09:02
-
-
Save kumatti1/674ffec040a66c7874f1 to your computer and use it in GitHub Desktop.
メモ帳のウィンドウ制御
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <windows.h> | |
void hoge() | |
{ | |
HWND hwnd = FindWindowW( L"Notepad", L"無題 - メモ帳"); | |
if(!hwnd){ | |
MessageBoxW(0, L"", L"メモ帳未起動!", MB_OK); | |
_wsystem(L"c:\\windows\\system32\\notepad.exe"); | |
return; | |
} | |
//書式のフォント | |
PostMessageW(hwnd, WM_COMMAND, MAKEWPARAM(33, BN_CLICKED), 0L); | |
HWND hDlg = 0; | |
while(hDlg == 0){ | |
Sleep(1); | |
hDlg = FindWindowW(L"#32770", L"フォント"); | |
} | |
HWND hCmb = 0; | |
while( hCmb == 0){ | |
Sleep(1); | |
hCmb = FindWindowExW(hDlg,0, L"ComboBox",NULL); | |
} | |
HWND hCmbl = 0; | |
while(hCmbl == 0){ | |
Sleep(1); | |
hCmbl = FindWindowExW(hCmb,0, L"ComboLBox",NULL); | |
} | |
//フォント設定 | |
SendMessageW(hCmbl ,LB_SELECTSTRING, 0, (LPARAM)L"MS ゴシック"); | |
//変更を通知 | |
SendMessageW(hCmb, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hCmbl),LBN_SELCHANGE), (LPARAM)hCmbl); | |
//ダイアログ閉じる | |
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(1, BN_CLICKED), 0L); | |
//印刷 | |
PostMessageW(hwnd, WM_COMMAND, MAKEWPARAM(6, BN_CLICKED), 0L); | |
hDlg = 0; | |
while(hDlg == 0){ | |
Sleep(1); | |
hDlg = FindWindowW(L"#32770", L"印刷"); | |
} | |
Sleep(500); | |
//詳細設定ボタン | |
HWND hBtn = 0; | |
hBtn = FindWindowExW(hDlg,0, L"#32770", L"全般"); | |
HWND hBtn2 = FindWindowExW(hBtn,0, L"Button",L"詳細設定(&R)"); | |
SendMessageW(hBtn, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hBtn2),BN_CLICKED), (LPARAM)hBtn2); | |
} | |
int CALLBACK WinMain( | |
_In_ HINSTANCE hInstance, | |
_In_ HINSTANCE hPrevInstance, | |
_In_ LPSTR lpCmdLine, | |
_In_ int nCmdShow | |
) | |
{ | |
hoge(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <windows.h> | |
#include <Prsht.h> | |
void hoge() | |
{ | |
HWND hDlg2 = 0; | |
while (hDlg2 == 0) { | |
Sleep(1); | |
hDlg2 = FindWindowW(NULL, L"印刷設定"); | |
} | |
Sleep(500); | |
SetForegroundWindow(hDlg2); | |
//隣のタブへ移動 | |
PropSheet_SetCurSel(hDlg2, nullptr, 1); | |
//子ダイアログ | |
HWND h = GetTopWindow(hDlg2); | |
//モノクロ印刷ボタン | |
HWND hButton = FindWindowExW(h, 0, L"Button", L"モノクロ印刷(&L)"); | |
SendMessageW(hButton, BM_CLICK, 0, 0); | |
//OKボタン | |
SendMessageW(hDlg2, WM_COMMAND, MAKEWPARAM(1, BN_CLICKED), (LPARAM)FindWindowExW(h, 0, L"Button", L"OK")); | |
//印刷ダイアログ | |
HWND hDlg = FindWindowW(L"#32770", L"印刷"); | |
//印刷ボタン | |
HWND hBtn2 = FindWindowExW(hDlg, 0, L"Button", L"印刷(&P)"); | |
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hBtn2), BN_CLICKED), (LPARAM)hBtn2); | |
} | |
int CALLBACK WinMain( | |
_In_ HINSTANCE hInstance, | |
_In_ HINSTANCE hPrevInstance, | |
_In_ LPSTR lpCmdLine, | |
_In_ int nCmdShow | |
) | |
{ | |
hoge(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment