{"id":2386,"date":"2022-05-22T11:32:23","date_gmt":"2022-05-22T02:32:23","guid":{"rendered":"http:\/\/oreoreki.gotdns.ch\/?p=2386"},"modified":"2022-06-02T18:48:36","modified_gmt":"2022-06-02T09:48:36","slug":"post-2386","status":"publish","type":"post","link":"http:\/\/oreoreki.gotdns.ch\/?p=2386","title":{"rendered":"VBA\u3067Windows\u30a2\u30d7\u30ea\u300c\u30e1\u30e2\u5e33\u300d\u3092\u64cd\u4f5c\u3057\u3066\u307f\u305f\u30fbSendMessage\/PostMessage\u7de8"},"content":{"rendered":"<p><span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe loading=\"lazy\" class=\"youtube-player\" width=\"750\" height=\"422\" src=\"https:\/\/www.youtube.com\/embed\/NLvNxiBGdCY?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=ja&#038;autohide=2&#038;wmode=transparent\" allowfullscreen=\"true\" style=\"border:0;\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox\"><\/iframe><\/span><\/p>\n<h2><\/h2>\n<div class=\"hcb_wrap\">\n<p>VBA\u3067Windows\u30a2\u30d7\u30ea\u300c\u30e1\u30e2\u5e33\u300d\u3092\u64cd\u4f5c\u3057\u3066\u307f\u305f\u30fbSendMessage\/PostMessage\u7de8<br \/>\n<span class=\"bold-red\">\u3053\u306e\u52d5\u753b\u306e\u30de\u30af\u30ed\u306fWindows11\/Office2013\u3067\u4f5c\u6210\u3057\u3066\u307e\u3059\u3002<br \/>\n\u30e1\u30e2\u5e33\u306eid\u3068\u304b\u306fWindows11\u3068\u305d\u308c\u4ee5\u524d\u306eWindows\u3068\u3067\u306f\u7570\u306a\u3063\u3066\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001<br \/>\nWindows11\u4ee5\u5916\u3067\u52d5\u304b\u3059\u5834\u5408\u306fspyxx_amd64.exe\u3067id\u3092\u78ba\u8a8d\u3057\u30b3\u30fc\u30c9\u4fee\u6b63\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/span><\/p>\n<pre class=\"prism line-numbers lang-ts\" data-lang=\"TypeScript\"><code>Option Explicit\r\n'64\u30d3\u30c3\u30c8Office\u7528\u3067\u3059\u3002\r\n'32\u30d3\u30c3\u30c8\u7248\u3067\u306fPtrSafe \u3092\u3068\u308b\u3068\u52d5\u304f\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u78ba\u8a8d\u306f\u3057\u3066\u307e\u305b\u3093\u304c\u3002\r\nPrivate Declare PtrSafe Function FindWindowA Lib \"user32\" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long\r\nPrivate Declare PtrSafe Function FindWindowEx Lib \"user32.dll\" Alias \"FindWindowExA\" (ByVal hMemochoParent As Long, ByVal hMemochoChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long\r\nPrivate Declare PtrSafe Function SendMessage Lib \"user32.dll\" Alias \"SendMessageA\" (ByVal hMemocho As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Any) As Long\r\nPrivate Declare PtrSafe Function PostMessage Lib \"user32\" Alias \"PostMessageA\" (ByVal hMemocho As LongPtr, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long\r\nPrivate Declare PtrSafe Sub Sleep Lib \"kernel32\" (ByVal dwMilliseconds As Long)\r\n\r\nConst WM_COMMAND = &H111\r\nConst WM_CLOSE = &H10\r\nConst WM_SETTEXT As Long = &HC\r\nConst WM_GETTEXT As Long = &HD\r\nConst WM_GETTEXTLENGTH As Long = &HE\r\nConst EM_REPLACESEL As Long = &HC2\r\nConst EM_SETMODIFY  As Long = &HB9\r\nConst BM_CLICK  As Long = &HF5\r\n\r\nConst VK_RETURN  As Long = &HD 'Enter\u30ad\u30fc\r\nConst WM_KEYDOWN As Long = &H100\r\nConst WM_KEYUP As Long = &H101\r\n\r\nSub Memo2()\r\n    Dim hMemocho As Long\r\n    Dim hNamae As Long\r\n    Dim hChild As Long\r\n    Dim nLen As Long\r\n    Dim rtn As Long\r\n    Dim xStr As String\r\n    Dim xFikename As String\r\n    Dim fso, CurrentDirectory, i\r\n    '---------------------------------------------------------------------------\r\n    '\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb\u306e\u3042\u308b\u30d1\u30b9\u540d\u3092\u53d6\u5f97\r\n    \r\n    Set fso = CreateObject(\"Scripting.FileSystemObject\")\r\n    CurrentDirectory = ActiveWorkbook.Path\r\n\r\n    ' \u30e1\u30e2\u5e33\u306e\u8d77\u52d5\r\n    Call Shell(\"notepad.exe\", vbNormalFocus)\r\n    Do While hMemocho = 0\r\n        hMemocho = FindWindowEx(0, 0, \"Notepad\", vbNullString)\r\n        'DoEvents\r\n        Sleep 100      'DoEvents\u3060\u3068\u3046\u307e\u304f\u52d5\u304b\u306a\u3044\u306e\u3067Sleep\u3092\u4f7f\u3063\u305f\r\n    Loop\r\n\r\n    'Windows11\u4ed8\u5c5e\u306e\u30e1\u30e2\u5e33\u306e\u7de8\u96c6\u30a8\u30ea\u30a2\r\n    hChild = FindWindowEx(hMemocho, 0&, \"RichEditD2DPT\", vbNullString)\r\n    \r\n    For i = 1 To 2\r\n        xStr = Cells(i, 2).Value\r\n        rtn = SendMessage(hChild, EM_REPLACESEL, 0, xStr & vbCrLf) ' \u6587\u5b57\u5217\u3092\u9001\u4fe1\r\n    Next\r\n    \r\n    rtn = SendMessage(hChild, EM_SETMODIFY, 0, 0&) '\u5909\u66f4\u30d5\u30e9\u30b0OFF\r\n    \r\n    \r\n    '\u30e1\u30e2\u5e33\u306e\u7de8\u96c6\u30a8\u30ea\u30a2\u304b\u3089\u6587\u5b57\u5217\u3092\u8aad\u307f\u53d6\u308b\r\n    ' \u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u306e\u6587\u5b57\u5217\u306e\u9577\u3055  0&\u306fLong\u578b\u306e0\u3092\u610f\u5473\u3059\u308b\r\n    nLen = SendMessage(hChild, WM_GETTEXTLENGTH, 0, 0&)\r\n    ' \u6587\u5b57\u5217 +1 \u306e\u9577\u3055\u306e\u7a7a\u767d\u6587\u5b57\u5217\u3092\u7528\u610f  +1\u306fNull\u30b3\u30fc\u30c9(&H00)\r\n    xStr = String(nLen + 1, vbNullChar)\r\n    rtn = SendMessage(hChild, WM_GETTEXT, nLen + 1, xStr)\r\n    Debug.Print xStr\r\n    \r\n\r\n    '---------------------------------------------------------------------------\r\n    '  \u300c\u540d\u524d\u3092\u4ed8\u3051\u3066\u4fdd\u5b58\u300dWindow\u306e\u51e6\u7406\r\n    '  \u3053\u306e\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb\u3068\u540c\u3058\u30d5\u30a9\u30eb\u30c0\u30fc\u306b\"abc.txt\"\u3068\u3044\u3046\u540d\u524d\u3067\u4fdd\u5b58\u3059\u308b\r\n    '\r\n    '\u4fdd\u5b58\u3057\u3088\u3046\u3068\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3057\u3066\u308b\u3068\u3001\u4e0a\u66f8\u304d\u3092\u805e\u3044\u3066\u304f\u308b\u306e\u3067\r\n    '\u4e88\u3081\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u3063\u305f\u3089\u524a\u9664\u3057\u3066\u304a\u304f\u3002\r\n    xFikename = fso.BuildPath(CurrentDirectory, \"abc.txt\")\r\n    If fso.FileExists(xFikename) Then\r\n        fso.DeleteFile xFikename, True\r\n    End If\r\n\r\n    rtn = PostMessage(hMemocho, WM_COMMAND, &H4, 0&)     '\u30d5\u30a1\u30a4\u30eb - \u540d\u524d\u3092\u3064\u3051\u3066\u4fdd\u5b58\r\n    Do While hNamae = 0 Or hChild = 0\r\n        hNamae = FindWindowA(vbNullString, \"\u540d\u524d\u3092\u4ed8\u3051\u3066\u4fdd\u5b58\")\r\n        hChild = FindWindowEx(hNamae, 0&, \"DUIViewWndClassName\", vbNullString)\r\n        hChild = FindWindowEx(hChild, 0&, \"DirectUIHWND\", vbNullString)\r\n        hChild = FindWindowEx(hChild, 0&, \"FloatNotifySink\", vbNullString)\r\n        hChild = FindWindowEx(hChild, 0&, \"ComboBox\", vbNullString)\r\n        'DoEvents\r\n        Sleep 100      'DoEvents\u3060\u3068\u3046\u307e\u304f\u52d5\u304b\u306a\u3044\u306e\u3067Sleep\u3092\u4f7f\u3063\u305f\r\n    Loop\r\n\r\n    xStr = xFikename\r\n    rtn = SendMessage(hChild, WM_SETTEXT, 0, xFikename) ' \u6587\u5b57\u5217\u3092\u9001\u4fe1\r\n\r\n    '\u4fdd\u5b58(&S)\u3092\u62bc\u3059\r\n    hChild = FindWindowEx(hNamae, 0&, \"Button\", \"\u4fdd\u5b58(&S)\")\r\n    rtn = PostMessage(hChild, BM_CLICK, 0, 0&)\r\n    ''Enter\u30ad\u30fc\u3092\u62bc\u3059\r\n    'rtn = PostMessage(hChild, WM_KEYDOWN, VK_RETURN, 0&)\r\n    'rtn = PostMessage(hChild, WM_KEYUP, VK_RETURN, 0&)\r\n\r\n    '\u30e1\u30e2\u5e33\u306e\u7d42\u4e86\r\n    'rtn = PostMessage(hMemocho, WM_COMMAND, &H7, 0&)     '\u30d5\u30a1\u30a4\u30eb - \u7d42\u4e86\r\n    rtn = PostMessage(hMemocho, WM_CLOSE, 0, 0&)     '\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u7d42\u4e86\r\n  \r\nEnd Sub\r\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>VBA\u3067Windows\u30a2\u30d7\u30ea\u300c\u30e1\u30e2\u5e33\u300d\u3092\u64cd\u4f5c\u3057\u3066\u307f\u305f\u30fbSendMessage\/PostMessage [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2388,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[34],"tags":[],"class_list":["post-2386","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vba"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"http:\/\/oreoreki.gotdns.ch\/wp-content\/uploads\/sites\/2\/2022\/05\/vbawindowssendmessage-postmessag.jpg","jetpack_shortlink":"https:\/\/wp.me\/p9WqRX-Cu","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts\/2386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2386"}],"version-history":[{"count":5,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts\/2386\/revisions"}],"predecessor-version":[{"id":2400,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts\/2386\/revisions\/2400"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/media\/2388"}],"wp:attachment":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2386"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}