ReactOS  0.4.13-dev-249-gcba1a2f
mainwnd.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API Test GUI
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE:
5  * PURPOSE: main dialog implementation
6  * COPYRIGHT: Copyright 2008 Ged Murphy <gedmurphy@reactos.org>
7  *
8  */
9 
10 #include <precomp.h>
11 #include <io.h>
12 
13 #define BUFSIZE 4096
14 
16 
17 WCHAR szPipeName[] = L"\\\\.\\pipe\\winetest_pipe";
18 
19 typedef int (_cdecl *RUNTEST)(char **);
20 
23 {
24  PMAIN_WND_INFO pInfo;
25  HWND hList, hEdit;
26  DWORD dwRead;
27  CHAR chBuf[BUFSIZE];
29  LVITEMA item;
30  INT count;
31 
32  pInfo = (PMAIN_WND_INFO)lpParam;
33 
34  hList = GetDlgItem(pInfo->hMainWnd, IDC_LIST);
36 
37  ZeroMemory(&item, sizeof(LVITEMA));
38  item.mask = LVIF_TEXT;
39 
40  while (TRUE)
41  {
42  dwRead = 0;
43  bSuccess = ReadFile(pInfo->hStdOutRd,
44  chBuf,
45  BUFSIZE,
46  &dwRead,
47  NULL);
48  if(!bSuccess || dwRead == 0)
49  break;
50 
51  chBuf[dwRead] = 0;
52 
56 
57  //item.iItem = ListView_GetItemCount(hList);
58  //item.pszText = chBuf;
59  //SendMessage(hEdit, LVM_INSERTITEMA, 0, (LPARAM)&item);
60  }
61 
62  return 0;
63 }
64 
65 
68 {
70  STARTUPINFO si;
73 
74  //
75  // Set up the security attributes
76  //
77  sa.nLength= sizeof(SECURITY_ATTRIBUTES);
78  sa.lpSecurityDescriptor = NULL;
79  sa.bInheritHandle = TRUE;
80 
81  //
82  // Create a pipe for the child process's STDOUT
83  //
84  if (!CreatePipe(&pInfo->hStdOutRd,
85  &pInfo->hStdOutWr,
86  &sa,
87  0))
88  {
89  return FALSE;
90  }
91 
92  //
93  // Ensure the read handle to the pipe for STDOUT is not inherited
94  //
95  if (!SetHandleInformation(pInfo->hStdOutRd,
97  0))
98  {
99  return FALSE;
100  }
101 
102  ZeroMemory(&si, sizeof(STARTUPINFO));
103  si.cb = sizeof(STARTUPINFO);
104  si.hStdError = pInfo->hStdOutWr;
105  si.hStdOutput = pInfo->hStdOutWr;
108 
109  ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
110 
112  NULL,
113  NULL,
114  NULL,
115  TRUE,
116  0,//CREATE_SUSPENDED,
117  NULL,
118  NULL,
119  &si,
120  &pi);
121  if (bSuccess)
122  {
123  //
124  // Create thread to handle pipe input from child processes
125  //
126  pInfo->hPipeThread = CreateThread(NULL,
127  0,
129  pInfo,
130  0,
131  NULL);
132 
133  WaitForSingleObject(pi.hProcess, INFINITE);
134 
135  CloseHandle(pi.hProcess);
136  CloseHandle(pi.hThread);
137  }
138 
139  return bSuccess;
140 }
141 
142 
143 static BOOL
145  LPARAM lParam)
146 {
147  PMAIN_WND_INFO pInfo;
148 
149  pInfo = (PMAIN_WND_INFO)lParam;
150 
151  /* Initialize the main window context */
152  pInfo->hMainWnd = hDlg;
153 
154  SetWindowLongPtr(hDlg,
156  (LONG_PTR)pInfo);
157 
158  pInfo->hSmIcon = LoadImageW(hInstance,
160  IMAGE_ICON,
161  16,
162  16,
163  0);
164  if (pInfo->hSmIcon)
165  {
166  SendMessageW(hDlg,
167  WM_SETICON,
168  ICON_SMALL,
169  (LPARAM)pInfo->hSmIcon);
170  }
171 
172  pInfo->hBgIcon = LoadImageW(hInstance,
174  IMAGE_ICON,
175  32,
176  32,
177  0);
178  if (pInfo->hBgIcon)
179  {
180  SendMessageW(hDlg,
181  WM_SETICON,
182  ICON_BIG,
183  (LPARAM)pInfo->hBgIcon);
184  }
185 
186  return TRUE;
187 }
188 
189 static VOID
191 {
192  HWND hRunCmd;
193  WCHAR szTextCmd[MAX_RUN_CMD];
194  INT sel;
195 
196  hRunCmd = GetDlgItem(pInfo->hMainWnd, IDC_TESTSELECTION);
197 
198  sel = SendMessageW(hRunCmd,
199  CB_GETCURSEL,
200  0,
201  0);
202  if (sel != CB_ERR)
203  {
204  if (SendMessageW(hRunCmd,
205  CB_GETLBTEXT,
206  sel,
207  (LPARAM)szTextCmd) != CB_ERR)
208  {
209  pInfo->lpCmdLine = (LPWSTR)SendMessage(hRunCmd,
211  0,
212  0);
213  if (pInfo->lpCmdLine)
214  {
215  //
216  // Create a new thread to create the client process
217  // and receive any ouput via stdout
218  //
220  0,
222  pInfo,
223  0,
224  NULL);
225  }
226  }
227  }
228 }
229 
230 static VOID
232 {
233  HWND hRunCmd;
234  LPWSTR lpExePath;
235  INT len;
236 
237  hRunCmd = GetDlgItem(pInfo->hMainWnd, IDC_TESTSELECTION);
238  if (hRunCmd)
239  {
240  SendMessageW(hRunCmd,
242  0,
243  (LPARAM)pInfo->SelectedTest.szName);
244 
245  len = (wcslen(pInfo->SelectedTest.szRunCmd) + 1) * sizeof(WCHAR);
246  lpExePath = HeapAlloc(GetProcessHeap(), 0, len);
247  if (lpExePath)
248  {
249  wcsncpy(lpExePath,
250  pInfo->SelectedTest.szRunCmd,
251  len / sizeof(WCHAR));
252  }
253 
254  SendMessageW(hRunCmd,
256  0,
257  (LPARAM)lpExePath);
258  SendMessageW(hRunCmd,
259  CB_SETCURSEL,
260  0,
261  0);
262  }
263 }
264 
265 static VOID
267 {
268  HWND hRunCmd;
269  LPWSTR lpExePath;
270  INT cnt, i;
271 
272  hRunCmd = GetDlgItem(pInfo->hMainWnd, IDC_TESTSELECTION);
273 
274  cnt = SendMessageW(hRunCmd,
275  CB_GETCOUNT,
276  0,
277  0);
278  if (cnt != CB_ERR)
279  {
280  for (i = 0; i < cnt; i++)
281  {
282  lpExePath = (LPWSTR)SendMessage(hRunCmd,
284  i,
285  0);
286  if (lpExePath)
287  {
288  HeapFree(GetProcessHeap(), 0, lpExePath);
289  }
290  }
291  }
292 }
293 
294 static BOOL CALLBACK
296  UINT Message,
297  WPARAM wParam,
298  LPARAM lParam)
299 {
300  PMAIN_WND_INFO pInfo;
301 
302  /* Get the window context */
303  pInfo = (PMAIN_WND_INFO)GetWindowLongPtr(hDlg,
304  GWLP_USERDATA);
305  if (pInfo == NULL && Message != WM_INITDIALOG)
306  {
307  goto HandleDefaultMessage;
308  }
309 
310  switch(Message)
311  {
312  case WM_INITDIALOG:
313  return OnInitMainDialog(hDlg, lParam);
314 
315  case WM_COMMAND:
316  {
317  switch(LOWORD(wParam))
318  {
319  case IDC_BROWSE:
320  {
321  INT_PTR ret;
322 
325  hDlg,
327  (LPARAM)pInfo);
328  if (ret == IDOK)
329  {
330  AddTestToCombo(pInfo);
331  }
332 
333  break;
334  }
335  case IDC_OPTIONS:
338  hDlg,
340  (LPARAM)pInfo);
341  break;
342 
343  case IDC_RUN:
344  RunSelectedTest(pInfo);
345  break;
346 
347  case IDOK:
348  EndDialog(hDlg, 0);
349  break;
350  }
351  }
352  break;
353 
354  case WM_CLOSE:
355  EndDialog(hDlg, 0);
356  break;
357 
358  case WM_DESTROY:
359  if (pInfo->hSmIcon)
360  DestroyIcon(pInfo->hSmIcon);
361  if (pInfo->hBgIcon)
362  DestroyIcon(pInfo->hBgIcon);
363 
364  FreeTestCmdStrings(pInfo);
365 
366  break;
367 
368 HandleDefaultMessage:
369  default:
370  return FALSE;
371  }
372 
373  return FALSE;
374 }
375 
376 
377 INT WINAPI
379  HINSTANCE hPrev,
380  LPWSTR Cmd,
381  int iCmd)
382 {
384  PMAIN_WND_INFO pInfo;
385  INT Ret = -1;
386 
387  UNREFERENCED_PARAMETER(hPrev);
389  UNREFERENCED_PARAMETER(iCmd);
390 
391  hInstance = hInst;
392 
393  ZeroMemory(&iccx, sizeof(INITCOMMONCONTROLSEX));
394  iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
395  iccx.dwICC = ICC_TAB_CLASSES;
396  InitCommonControlsEx(&iccx);
397 
398  pInfo = HeapAlloc(GetProcessHeap(),
399  0,
400  sizeof(MAIN_WND_INFO));
401  if (pInfo)
402  {
403  Ret = (DialogBoxParamW(hInstance,
405  NULL,
407  (LPARAM)pInfo) == IDOK);
408 
410  0,
411  pInfo);
412  }
413 
414  return Ret;
415 }
#define IDD_TESTBROWSER
Definition: resource.h:2
DWORD WINAPI CreateClientProcess(PMAIN_WND_INFO pInfo)
Definition: mainwnd.c:67
#define CB_SETITEMDATA
Definition: winuser.h:1927
#define IDI_ICON
Definition: resource.h:5
HANDLE hStdOutRd
Definition: precomp.h:29
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
#define CloseHandle
Definition: compat.h:398
#define IDC_OUTPUT
Definition: resource.h:11
#define IMAGE_ICON
Definition: winuser.h:212
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
WCHAR szName[MAX_NAME]
Definition: precomp.h:17
HICON hSmIcon
Definition: precomp.h:34
#define IDC_TESTSELECTION
Definition: resource.h:12
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define CB_GETLBTEXT
Definition: winuser.h:1913
LRESULT WINAPI SendMessageA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDC_BROWSE
Definition: resource.h:21
HICON hBgIcon
Definition: precomp.h:35
int(_cdecl * RUNTEST)(char **)
Definition: mainwnd.c:19
#define CB_GETITEMDATA
Definition: winuser.h:1911
GLuint GLuint GLsizei count
Definition: gl.h:1545
char CHAR
Definition: xmlstorage.h:175
#define IDC_OPTIONS
static BOOL OnInitMainDialog(HWND hDlg, LPARAM lParam)
Definition: mainwnd.c:144
BOOL CALLBACK BrowseDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
Definition: browsewnd.c:332
#define CALLBACK
Definition: compat.h:27
#define ZeroMemory
Definition: winbase.h:1635
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
#define BUFSIZE
Definition: mainwnd.c:13
DWORD WINAPI PipeReadThread(LPVOID lpParam)
Definition: mainwnd.c:22
DWORD dwFlags
Definition: winbase.h:807
UINT_PTR WPARAM
Definition: windef.h:207
int32_t INT_PTR
Definition: typedefs.h:62
#define IDD_OPTIONS
Definition: resource.h:18
struct tagINITCOMMONCONTROLSEX INITCOMMONCONTROLSEX
int32_t INT
Definition: typedefs.h:56
static BOOLEAN bSuccess
Definition: drive.cpp:417
#define SetWindowLongPtr
Definition: treelist.c:70
#define CB_GETCURSEL
Definition: winuser.h:1904
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define ICON_SMALL
Definition: tnclass.cpp:48
#define LVIF_TEXT
Definition: commctrl.h:2281
static BOOL CALLBACK MainDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
Definition: mainwnd.c:295
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define MAX_RUN_CMD
Definition: precomp.h:13
unsigned int BOOL
Definition: ntddk_ex.h:94
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
#define IDD_WINETESTGUI
Definition: resource.h:1
#define GWLP_USERDATA
Definition: treelist.c:63
#define CB_INSERTSTRING
Definition: winuser.h:1918
#define IDC_RUN
Definition: resource.h:21
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:111
smooth NULL
Definition: ftsmooth.c:416
static VOID RunSelectedTest(PMAIN_WND_INFO pInfo)
Definition: mainwnd.c:190
WCHAR szRunCmd[MAX_RUN_CMD]
Definition: precomp.h:18
#define IDC_LIST
Definition: resource.h:93
LONG_PTR LPARAM
Definition: windef.h:208
#define HANDLE_FLAG_INHERIT
Definition: winbase.h:261
#define STD_INPUT_HANDLE
Definition: winbase.h:264
static VOID FreeTestCmdStrings(PMAIN_WND_INFO pInfo)
Definition: mainwnd.c:266
#define CB_ERR
Definition: winuser.h:2389
#define WM_DESTROY
Definition: winuser.h:1591
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4623
#define STARTF_USESTDHANDLES
Definition: winbase.h:480
int WINAPI GetWindowTextLengthA(_In_ HWND)
LPWSTR lpCmdLine
Definition: precomp.h:31
DWORD cb
Definition: winbase.h:796
#define GetProcessHeap()
Definition: compat.h:395
HANDLE hPipeThread
Definition: precomp.h:28
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WM_CLOSE
Definition: winuser.h:1603
#define WINAPI
Definition: msvc.h:8
#define EM_SETSEL
Definition: winuser.h:1979
struct _MAIN_WND_INFO * PMAIN_WND_INFO
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE hStdOutput
Definition: winbase.h:812
WCHAR szPipeName[]
Definition: mainwnd.c:17
TEST_ITEM SelectedTest
Definition: precomp.h:40
CHAR Message[80]
Definition: alive.c:5
static DWORD pi
Definition: protocol.c:150
int ret
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
Definition: sacdrv.h:277
GLenum GLsizei len
Definition: glext.h:6722
static HWND hEdit
Definition: autocomplete.c:34
#define CB_SETCURSEL
Definition: winuser.h:1922
#define WM_COMMAND
Definition: winuser.h:1716
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
Definition: npipe.c:117
INT_PTR(CALLBACK * DLGPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2849
HANDLE hStdOutWr
Definition: precomp.h:30
HWND hList
Definition: livecd.c:10
HINSTANCE hInst
Definition: dxdiag.c:13
static ATOM item
Definition: dde.c:856
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
static VOID AddTestToCombo(PMAIN_WND_INFO pInfo)
Definition: mainwnd.c:231
STARTUPINFOA STARTUPINFO
Definition: winbase.h:3533
HANDLE hStdInput
Definition: winbase.h:811
HINSTANCE hInstance
Definition: mainwnd.c:15
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
INT_PTR CALLBACK OptionsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: solitaire.cpp:273
HWND hMainWnd
Definition: precomp.h:48
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define SendMessage
Definition: winuser.h:5709
BOOL WINAPI SetHandleInformation(IN HANDLE hObject, IN DWORD dwMask, IN DWORD dwFlags)
Definition: handle.c:78
#define CB_GETCOUNT
Definition: winuser.h:1903
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GetWindowLongPtr
Definition: treelist.c:73
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define INFINITE
Definition: serial.h:102
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
HANDLE hStdError
Definition: winbase.h:813
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define EM_REPLACESEL
Definition: winuser.h:1967
INT WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR Cmd, int iCmd)
Definition: mainwnd.c:378
#define ICON_BIG
Definition: tnclass.cpp:51
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define ICC_TAB_CLASSES
Definition: commctrl.h:61