Process Hacker
sessmsg.c
Go to the documentation of this file.
1 /*
2  * Process Hacker -
3  * send message window
4  *
5  * Copyright (C) 2010-2013 wj32
6  *
7  * This file is part of Process Hacker.
8  *
9  * Process Hacker is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * Process Hacker is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include <phapp.h>
24 #include <windowsx.h>
25 #include <winsta.h>
26 
27 #define SIP(String, Integer) { (String), (PVOID)(Integer) }
28 
29 static PH_KEY_VALUE_PAIR PhpMessageBoxIconPairs[] =
30 {
31  SIP(L"None", 0),
32  SIP(L"Information", MB_ICONINFORMATION),
33  SIP(L"Warning", MB_ICONWARNING),
34  SIP(L"Error", MB_ICONERROR),
35  SIP(L"Question", MB_ICONQUESTION)
36 };
37 
38 INT_PTR CALLBACK PhpSessionSendMessageDlgProc(
39  _In_ HWND hwndDlg,
40  _In_ UINT uMsg,
41  _In_ WPARAM wParam,
42  _In_ LPARAM lParam
43  );
44 
46  _In_ HWND ParentWindowHandle,
47  _In_ ULONG SessionId
48  )
49 {
50  DialogBoxParam(
52  MAKEINTRESOURCE(IDD_EDITMESSAGE),
53  ParentWindowHandle,
55  (LPARAM)SessionId
56  );
57 }
58 
60  _In_ HWND hwndDlg,
61  _In_ UINT uMsg,
62  _In_ WPARAM wParam,
63  _In_ LPARAM lParam
64  )
65 {
66  switch (uMsg)
67  {
68  case WM_INITDIALOG:
69  {
70  HWND iconComboBox;
71 
72  SetProp(hwndDlg, L"SessionId", (HANDLE)(ULONG)lParam);
73  PhCenterWindow(hwndDlg, GetParent(hwndDlg));
74 
75  iconComboBox = GetDlgItem(hwndDlg, IDC_TYPE);
76 
77  ComboBox_AddString(iconComboBox, L"None");
78  ComboBox_AddString(iconComboBox, L"Information");
79  ComboBox_AddString(iconComboBox, L"Warning");
80  ComboBox_AddString(iconComboBox, L"Error");
81  ComboBox_AddString(iconComboBox, L"Question");
82  PhSelectComboBoxString(iconComboBox, L"None", FALSE);
83 
85  {
86  SetDlgItemText(
87  hwndDlg,
88  IDC_TITLE,
89  PhaFormatString(L"Message from %s", PhCurrentUserName->Buffer)->Buffer
90  );
91  }
92 
93  SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDC_TEXT), TRUE);
94  }
95  break;
96  case WM_DESTROY:
97  {
98  RemoveProp(hwndDlg, L"SessionId");
99  }
100  break;
101  case WM_COMMAND:
102  {
103  switch (LOWORD(wParam))
104  {
105  case IDCANCEL:
106  EndDialog(hwndDlg, IDCANCEL);
107  break;
108  case IDOK:
109  {
110  ULONG sessionId = (ULONG)GetProp(hwndDlg, L"SessionId");
111  PPH_STRING title;
112  PPH_STRING text;
113  ULONG icon = 0;
114  ULONG64 timeout = 0;
115  ULONG response;
116 
117  title = PhaGetDlgItemText(hwndDlg, IDC_TITLE);
118  text = PhaGetDlgItemText(hwndDlg, IDC_TEXT);
119 
121  PhpMessageBoxIconPairs,
122  sizeof(PhpMessageBoxIconPairs),
123  PhaGetDlgItemText(hwndDlg, IDC_TYPE)->Buffer,
124  &icon
125  );
127  &PhaGetDlgItemText(hwndDlg, IDC_TIMEOUT)->sr,
128  10,
129  &timeout
130  );
131 
133  NULL,
134  sessionId,
135  title->Buffer,
136  (ULONG)title->Length,
137  text->Buffer,
138  (ULONG)text->Length,
139  icon,
140  (ULONG)timeout,
141  &response,
142  TRUE
143  ))
144  {
145  EndDialog(hwndDlg, IDOK);
146  }
147  else
148  {
149  PhShowStatus(hwndDlg, L"Unable to send the message", 0, GetLastError());
150  }
151  }
152  break;
153  }
154  }
155  break;
156  }
157 
158  return FALSE;
159 }