1 /*
2  *	Gdi handle viewer
3  *
4  *	mainwnd.c
5  *
6  *	Copyright (C) 2007	Timo Kreuzer <timo <dot> kreuzer <at> reactos <dot> org>
7  *
8  *	This program is free software; you can redistribute it and/or modify
9  *	it under the terms of the GNU General Public License as published by
10  *	the Free Software Foundation; either version 2 of the License, or
11  *	(at your option) any later version.
12  *
13  *	This program is distributed in the hope that it will be useful,
14  *	but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *	GNU General Public License for more details.
17  *
18  *	You should have received a copy of the GNU General Public License
19  *	along with this program; if not, write to the Free Software
20  *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22 
23 #include "gdihv.h"
24 
25 INT g_Separator;
26 
27 
28 static LRESULT
29 MainWindow_OnSize(HWND hMainWnd)
30 {
31 	HWND hProcessListctrl, hHandleListCtrl, hProcessRefresh, hHandleRefresh;
32 	RECT rect;
33 
34 	hProcessListctrl = GetDlgItem(hMainWnd, IDC_PROCESSLIST);
35 	hHandleListCtrl = GetDlgItem(hMainWnd, IDC_HANDLELIST);
36 	hProcessRefresh = GetDlgItem(hMainWnd, IDC_REFRESHPROCESS);
37 	hHandleRefresh = GetDlgItem(hMainWnd, IDC_REFRESHHANDLE);
38 
39 	GetClientRect(hMainWnd, &rect);
40 
41 //g_Separator = (rect.right / 2);
42 	MoveWindow(hProcessListctrl, 5, 5, g_Separator - 5, rect.bottom - 40, TRUE);
43 	MoveWindow(hHandleListCtrl, g_Separator + 5, 5, rect.right - g_Separator - 5, rect.bottom - 40, TRUE);
44 	MoveWindow(hProcessRefresh, g_Separator - 90, rect.bottom - 30, 90, 25, TRUE);
45 	MoveWindow(hHandleRefresh, rect.right - 90, rect.bottom - 30, 90, 25, TRUE);
46 
47 	return 0;
48 }
49 
50 
51 static LRESULT
52 MainWnd_OnNotify(HWND hWnd, WPARAM wParam, LPARAM lParam)
53 {
54 	LPNMHDR pnmh = (LPNMHDR)lParam;
55 
56 	switch(pnmh->code)
57 	{
58 		case LVN_ITEMCHANGED:
59 		{
60 			LPNMLISTVIEW pnmlv = (LPNMLISTVIEW)pnmh;
61 			if ((wParam == IDC_PROCESSLIST)
62 				&& (pnmlv->uNewState & LVIS_SELECTED)
63 				&& !(pnmlv->uOldState & LVIS_SELECTED))
64 			{
65 				LV_ITEM item;
66 				memset(&item, 0, sizeof(LV_ITEM));
67 				item.mask = LVIF_PARAM;
68 				item.iItem = pnmlv->iItem;
69 				(void)ListView_GetItem(GetDlgItem(hWnd, IDC_PROCESSLIST), &item);
70 				HandleList_Update(GetDlgItem(hWnd, IDC_HANDLELIST), (HANDLE)item.lParam);
71 				return TRUE;
72 			}
73 			break;
74 		}
75 	}
76 
77 	return 0;
78 }
79 
80 INT_PTR CALLBACK
81 MainWindow_WndProc(HWND hMainWnd, UINT message, WPARAM wParam, LPARAM lParam)
82 {
83 	switch (message)
84 	{
85 		case WM_INITDIALOG:
86 		{
87 			RECT rect;
88 
89 			SendMessage(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_MAIN)));
90 			(void)ListView_SetExtendedListViewStyle(GetDlgItem(hMainWnd, IDC_PROCESSLIST), LVS_EX_FULLROWSELECT);
91 			(void)ListView_SetExtendedListViewStyle(GetDlgItem(hMainWnd, IDC_HANDLELIST), LVS_EX_FULLROWSELECT);
92 			GetClientRect(hMainWnd, &rect);
93 			g_Separator = (rect.right / 2);
94 			HandleList_Create(GetDlgItem(hMainWnd, IDC_HANDLELIST));
95 			ProcessList_Create(GetDlgItem(hMainWnd, IDC_PROCESSLIST));
96 			MainWindow_OnSize(hMainWnd);
97 
98 			break;
99 		}
100 		case WM_SIZE:
101 			return MainWindow_OnSize(hMainWnd);
102 
103 		case WM_COMMAND:
104 		{
105 			switch (LOWORD(wParam))
106 			{
107 				case IDOK:
108 				case IDCANCEL:
109 				{
110 					EndDialog(hMainWnd, IDOK);
111 					break;
112 				}
113 				case IDC_REFRESHHANDLE:
114 				{
115 					LV_ITEM item;
116 					HWND hProcessListCtrl = GetDlgItem(hMainWnd, IDC_PROCESSLIST);
117 					memset(&item, 0, sizeof(LV_ITEM));
118 					item.mask = LVIF_PARAM;
119 					item.iItem = ListView_GetSelectionMark(hProcessListCtrl);
120 					(void)ListView_GetItem(hProcessListCtrl, &item);
121 					HandleList_Update(GetDlgItem(hMainWnd, IDC_HANDLELIST), (HANDLE)item.lParam);
122 					break;
123 				}
124 				case IDC_REFRESHPROCESS:
125 				{
126 					ProcessList_Update(GetDlgItem(hMainWnd, IDC_PROCESSLIST));
127 					break;
128 				}
129 				default:
130 				{
131 					return FALSE;
132 				}
133 			}
134 			break;
135 		}
136 
137 		case WM_NOTIFY:
138 			return MainWnd_OnNotify(hMainWnd, wParam, lParam);
139 
140 		default:
141 		{
142 			return FALSE;
143 		}
144 	}
145 	return TRUE;
146 }
147 
148