質問編集履歴

1

ソースコードを所定の書式に修正しました。内容の変更はありません。

2022/01/26 00:53

投稿

yun
yun

スコア5

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
- : TForm(Owner)
29
+ : TForm(Owner)
30
30
  {
31
31
  }
32
32
  //---------------------------------------------------------------------------
33
33
  void __fastcall TForm1::Button1Click(TObject *Sender)
34
34
  {
35
- wchar_t lpResult;
35
+ wchar_t lpResult;
36
- wchar_t Result[1024];
36
+ wchar_t Result[1024];
37
- wchar_t _str[1024];
37
+ wchar_t _str[1024];
38
- String str, str1;
38
+ String str, str1;
39
39
 
40
- ZeroMemory(&si, sizeof(STARTUPINFOW));
40
+ ZeroMemory(&si, sizeof(STARTUPINFOW));
41
- ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
41
+ ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
42
42
 
43
- si.cb = sizeof(STARTUPINFOW);
43
+ si.cb = sizeof(STARTUPINFOW);
44
- si.dwFlags = STARTF_USESHOWWINDOW;
44
+ si.dwFlags = STARTF_USESHOWWINDOW;
45
- si.wShowWindow = SW_SHOWNORMAL;
45
+ si.wShowWindow = SW_SHOWNORMAL;
46
46
 
47
- str = L"C:\\Windows\\System32\\notepad.exe D:\\Mydesktop\\memo.txt";
47
+ str = L"C:\\Windows\\System32\\notepad.exe D:\\Mydesktop\\memo.txt";
48
48
 
49
- CreateProcessW(
49
+ CreateProcessW(
50
- NULL,
50
+ NULL,
51
- str.c_str(),
51
+ str.c_str(),
52
- NULL,
52
+ NULL,
53
- NULL,
53
+ NULL,
54
- FALSE,
54
+ FALSE,
55
- 0,
55
+ 0,
56
- NULL,
56
+ NULL,
57
- NULL,
57
+ NULL,
58
- &si,
58
+ &si,
59
- &pi
59
+ &pi
60
- );
60
+ );
61
61
 
62
- WaitForSingleObject(pi.hProcess, 1000);
62
+ WaitForSingleObject(pi.hProcess, 1000);
63
63
 
64
- EnumWindows(EnumWindowsProc, (LPARAM)&pi);
64
+ EnumWindows(EnumWindowsProc, (LPARAM)&pi);
65
65
 
66
- CloseHandle(pi.hThread);
66
+ CloseHandle(pi.hThread);
67
- CloseHandle(pi.hProcess);
67
+ CloseHandle(pi.hProcess);
68
-
69
68
  }
70
69
  //---------------------------------------------------------------------------
71
- void __fastcall TForm1::Button2Click(TObject *Sender)
70
+ void __fastcall TForm1::Button2Click(TObject Sender)
72
71
  {
73
- Memo1->Lines->Clear();
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
- PROCESS_INFORMATION* p = (PROCESS_INFORMATION*)lParam;
79
+ PROCESS_INFORMATION p = (PROCESS_INFORMATION*)lParam;
81
80
 
82
- DWORD pid = 0;
81
+ DWORD pid = 0;
83
- GetWindowThreadProcessId(hWnd, &pid);
82
+ GetWindowThreadProcessId(hWnd, &pid);
84
83
 
85
- wchar_t _Title[1024];
84
+ wchar_t _Title[1024];
86
- String Title;
85
+ String Title;
87
86
 
88
- GetWindowTextW(hWnd, _Title, 1024);
87
+ GetWindowTextW(hWnd, _Title, 1024);
89
- Title = _Title;
88
+ Title = _Title;
90
89
 
91
- if (pid == p->dwProcessId) {
90
+ if (pid == p->dwProcessId) {
92
- Form1->Memo1->Lines->Add(L"-----");
91
+ Form1->Memo1->Lines->Add(L"-----");
93
- Form1->Memo1->Lines->Add(L"Title = " + Title);
92
+ Form1->Memo1->Lines->Add(L"Title = " + Title);
94
- Form1->Memo1->Lines->Add(L"pid = " + IntToStr((int)pid));
93
+ Form1->Memo1->Lines->Add(L"pid = " + IntToStr((int)pid));
95
- Form1->Memo1->Lines->Add(L"p->dwProcessId = " + IntToStr((int)p->dwProcessId));
94
+ Form1->Memo1->Lines->Add(L"p->dwProcessId = " + IntToStr((int)p->dwProcessId));
96
- Form1->Memo1->Lines->Add(L"hWnd = " + IntToStr((int)hWnd));
95
+ Form1->Memo1->Lines->Add(L"hWnd = " + IntToStr((int)hWnd));
97
- }
96
+ }
98
97
 
99
- return true;
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: // IDE で管理されるコンポーネント
116
+ __published: // IDE で管理されるコンポーネント
118
- TPanel *Panel1;
117
+ TPanel *Panel1;
119
- TMemo *Memo1;
118
+ TMemo *Memo1;
120
- TButton *Button1;
119
+ TButton *Button1;
121
- TButton *Button2;
120
+ TButton *Button2;
122
- void __fastcall Button1Click(TObject *Sender);
121
+ void __fastcall Button1Click(TObject *Sender);
123
- void __fastcall Button2Click(TObject *Sender);
122
+ void __fastcall Button2Click(TObject Sender);
124
- private: // ユーザー宣言
123
+ private: // ユーザー宣言
125
- STARTUPINFOW si;
124
+ STARTUPINFOW si;
126
- PROCESS_INFORMATION pi;
125
+ PROCESS_INFORMATION pi;
127
- public: // ユーザー宣言
126
+ public: // ユーザー宣言
128
- __fastcall TForm1(TComponent* Owner);
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