質問編集履歴
1
ソースコードを所定の書式に修正しました。内容の変更はありません。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
```
|
11
11
|
|
12
12
|
### 該当のソースコード
|
13
|
-
|
13
|
+
```
|
14
14
|
【SampleU.cpp】
|
15
15
|
//---------------------------------------------------------------------------
|
16
16
|
#include <vcl.h>
|
@@ -26,77 +26,76 @@
|
|
26
26
|
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam);
|
27
27
|
//---------------------------------------------------------------------------
|
28
28
|
__fastcall TForm1::TForm1(TComponent* Owner)
|
29
|
-
|
29
|
+
: TForm(Owner)
|
30
30
|
{
|
31
31
|
}
|
32
32
|
//---------------------------------------------------------------------------
|
33
33
|
void __fastcall TForm1::Button1Click(TObject *Sender)
|
34
34
|
{
|
35
|
-
|
35
|
+
wchar_t lpResult;
|
36
|
-
|
36
|
+
wchar_t Result[1024];
|
37
|
-
|
37
|
+
wchar_t _str[1024];
|
38
|
-
|
38
|
+
String str, str1;
|
39
39
|
|
40
|
-
|
40
|
+
ZeroMemory(&si, sizeof(STARTUPINFOW));
|
41
|
-
|
41
|
+
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
|
42
42
|
|
43
|
-
|
43
|
+
si.cb = sizeof(STARTUPINFOW);
|
44
|
-
|
44
|
+
si.dwFlags = STARTF_USESHOWWINDOW;
|
45
|
-
|
45
|
+
si.wShowWindow = SW_SHOWNORMAL;
|
46
46
|
|
47
|
-
|
47
|
+
str = L"C:\\Windows\\System32\\notepad.exe D:\\Mydesktop\\memo.txt";
|
48
48
|
|
49
|
-
|
49
|
+
CreateProcessW(
|
50
|
-
|
50
|
+
NULL,
|
51
|
-
|
51
|
+
str.c_str(),
|
52
|
-
|
52
|
+
NULL,
|
53
|
-
|
53
|
+
NULL,
|
54
|
-
|
54
|
+
FALSE,
|
55
|
-
|
55
|
+
0,
|
56
|
-
|
56
|
+
NULL,
|
57
|
-
|
57
|
+
NULL,
|
58
|
-
|
58
|
+
&si,
|
59
|
-
|
59
|
+
&pi
|
60
|
-
|
60
|
+
);
|
61
61
|
|
62
|
-
|
62
|
+
WaitForSingleObject(pi.hProcess, 1000);
|
63
63
|
|
64
|
-
|
64
|
+
EnumWindows(EnumWindowsProc, (LPARAM)&pi);
|
65
65
|
|
66
|
-
|
66
|
+
CloseHandle(pi.hThread);
|
67
|
-
|
67
|
+
CloseHandle(pi.hProcess);
|
68
|
-
|
69
68
|
}
|
70
69
|
//---------------------------------------------------------------------------
|
71
|
-
void __fastcall TForm1::Button2Click(TObject
|
70
|
+
void __fastcall TForm1::Button2Click(TObject Sender)
|
72
71
|
{
|
73
|
-
|
72
|
+
Memo1->Lines->Clear();
|
74
73
|
}
|
75
74
|
//---------------------------------------------------------------------------
|
76
75
|
//■hWnd:トップウィンドウのハンドル、 LPARAM lParam ← (LPARAM)pi.hProcess
|
77
76
|
//------------------------------------------------------------
|
78
77
|
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
|
79
78
|
{
|
80
|
-
|
79
|
+
PROCESS_INFORMATION p = (PROCESS_INFORMATION*)lParam;
|
81
80
|
|
82
|
-
|
81
|
+
DWORD pid = 0;
|
83
|
-
|
82
|
+
GetWindowThreadProcessId(hWnd, &pid);
|
84
83
|
|
85
|
-
|
84
|
+
wchar_t _Title[1024];
|
86
|
-
|
85
|
+
String Title;
|
87
86
|
|
88
|
-
|
87
|
+
GetWindowTextW(hWnd, _Title, 1024);
|
89
|
-
|
88
|
+
Title = _Title;
|
90
89
|
|
91
|
-
|
90
|
+
if (pid == p->dwProcessId) {
|
92
|
-
|
91
|
+
Form1->Memo1->Lines->Add(L"-----");
|
93
|
-
|
92
|
+
Form1->Memo1->Lines->Add(L"Title = " + Title);
|
94
|
-
|
93
|
+
Form1->Memo1->Lines->Add(L"pid = " + IntToStr((int)pid));
|
95
|
-
|
94
|
+
Form1->Memo1->Lines->Add(L"p->dwProcessId = " + IntToStr((int)p->dwProcessId));
|
96
|
-
|
95
|
+
Form1->Memo1->Lines->Add(L"hWnd = " + IntToStr((int)hWnd));
|
97
|
-
|
96
|
+
}
|
98
97
|
|
99
|
-
|
98
|
+
return true;
|
100
99
|
}
|
101
100
|
//---------------------------------------------------------------------------
|
102
101
|
|
@@ -114,23 +113,24 @@
|
|
114
113
|
//---------------------------------------------------------------------------
|
115
114
|
class TForm1 : public TForm
|
116
115
|
{
|
117
|
-
__published:
|
116
|
+
__published: // IDE で管理されるコンポーネント
|
118
|
-
|
117
|
+
TPanel *Panel1;
|
119
|
-
|
118
|
+
TMemo *Memo1;
|
120
|
-
|
119
|
+
TButton *Button1;
|
121
|
-
|
120
|
+
TButton *Button2;
|
122
|
-
|
121
|
+
void __fastcall Button1Click(TObject *Sender);
|
123
|
-
|
122
|
+
void __fastcall Button2Click(TObject Sender);
|
124
|
-
private:
|
123
|
+
private: // ユーザー宣言
|
125
|
-
|
124
|
+
STARTUPINFOW si;
|
126
|
-
|
125
|
+
PROCESS_INFORMATION pi;
|
127
|
-
public:
|
126
|
+
public: // ユーザー宣言
|
128
|
-
|
127
|
+
__fastcall TForm1(TComponent Owner);
|
129
128
|
};
|
130
129
|
//---------------------------------------------------------------------------
|
131
130
|
extern PACKAGE TForm1 *Form1;
|
132
131
|
//---------------------------------------------------------------------------
|
133
132
|
#endif
|
133
|
+
```
|
134
134
|
|
135
135
|
### 試したこと
|
136
136
|
|