2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/misc.c
5 * PURPOSE: Misc functions
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
12 /* SESSION Operation */
13 #define EXTRACT_FILLFILELIST 0x00000001
14 #define EXTRACT_EXTRACTFILES 0x00000002
26 struct FILELIST
*next
;
34 struct FILELIST
*FileList
;
37 CHAR Destination
[MAX_PATH
];
38 CHAR CurrentFile
[MAX_PATH
];
39 CHAR Reserved
[MAX_PATH
];
40 struct FILELIST
*FilterList
;
43 HRESULT (WINAPI
*pfnExtract
)(SESSION
*dest
, LPCSTR szCabName
);
47 GetSystemColorDepth(VOID
)
52 pDevMode
.dmSize
= sizeof(DEVMODE
);
53 pDevMode
.dmDriverExtra
= 0;
55 if (!EnumDisplaySettings(NULL
, ENUM_CURRENT_SETTINGS
, &pDevMode
))
57 /* TODO: Error message */
61 switch (pDevMode
.dmBitsPerPel
)
63 case 32: ColorDepth
= ILC_COLOR32
; break;
64 case 24: ColorDepth
= ILC_COLOR24
; break;
65 case 16: ColorDepth
= ILC_COLOR16
; break;
66 case 8: ColorDepth
= ILC_COLOR8
; break;
67 case 4: ColorDepth
= ILC_COLOR4
; break;
68 default: ColorDepth
= ILC_COLOR
; break;
75 GetWindowWidth(HWND hwnd
)
79 GetWindowRect(hwnd
, &Rect
);
80 return (Rect
.right
- Rect
.left
);
84 GetWindowHeight(HWND hwnd
)
88 GetWindowRect(hwnd
, &Rect
);
89 return (Rect
.bottom
- Rect
.top
);
93 GetClientWindowWidth(HWND hwnd
)
97 GetClientRect(hwnd
, &Rect
);
98 return (Rect
.right
- Rect
.left
);
102 GetClientWindowHeight(HWND hwnd
)
106 GetClientRect(hwnd
, &Rect
);
107 return (Rect
.bottom
- Rect
.top
);
111 CopyTextToClipboard(LPCWSTR lpszText
)
113 if(OpenClipboard(NULL
))
119 ClipBuffer
= GlobalAlloc(GMEM_DDESHARE
, (wcslen(lpszText
) + 1) * sizeof(TCHAR
));
120 Buffer
= (WCHAR
*)GlobalLock(ClipBuffer
);
121 wcscpy(Buffer
, lpszText
);
122 GlobalUnlock(ClipBuffer
);
124 SetClipboardData(CF_UNICODETEXT
, ClipBuffer
);
133 WCHAR szText
[MAX_STR_LEN
*3];
135 LoadStringW(hInst
, IDS_WELCOME_TITLE
, szText
, sizeof(szText
) / sizeof(WCHAR
));
136 NewRichEditText(szText
, CFE_BOLD
);
138 LoadStringW(hInst
, IDS_WELCOME_TEXT
, szText
, sizeof(szText
) / sizeof(WCHAR
));
139 InsertRichEditText(szText
, 0);
141 LoadStringW(hInst
, IDS_WELCOME_URL
, szText
, sizeof(szText
) / sizeof(WCHAR
));
142 InsertRichEditText(szText
, CFM_LINK
);
146 ShowPopupMenu(HWND hwnd
, UINT MenuID
)
148 HMENU hPopupMenu
= GetSubMenu(LoadMenuW(hInst
, MAKEINTRESOURCEW(MenuID
)), 0);
153 SetForegroundWindow(hwnd
);
154 TrackPopupMenu(hPopupMenu
, 0, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
156 DestroyMenu(hPopupMenu
);
160 StartProcess(LPWSTR lpPath
, BOOL Wait
)
162 PROCESS_INFORMATION pi
;
167 ZeroMemory(&si
, sizeof(si
));
169 si
.wShowWindow
= SW_SHOW
;
171 if (!CreateProcessW(NULL
, lpPath
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
176 CloseHandle(pi
.hThread
);
177 if (Wait
) EnableWindow(hMainWnd
, FALSE
);
181 dwRet
= MsgWaitForMultipleObjects(1, &pi
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
);
182 if (dwRet
== WAIT_OBJECT_0
+ 1)
184 while (PeekMessageW(&msg
, NULL
, 0, 0, PM_REMOVE
))
186 TranslateMessage(&msg
);
187 DispatchMessage(&msg
);
192 if (dwRet
== WAIT_OBJECT_0
|| dwRet
== WAIT_FAILED
)
197 CloseHandle(pi
.hProcess
);
201 EnableWindow(hMainWnd
, TRUE
);
202 SetForegroundWindow(hMainWnd
);
211 ExtractFilesFromCab(LPWSTR lpCabName
, LPWSTR lpOutputPath
)
213 HINSTANCE hCabinetDll
;
214 CHAR szCabName
[MAX_PATH
];
218 hCabinetDll
= LoadLibraryW(L
"cabinet.dll");
221 pfnExtract
= (void *) GetProcAddress(hCabinetDll
, "Extract");
224 ZeroMemory(&Dest
, sizeof(SESSION
));
226 WideCharToMultiByte(CP_ACP
, 0, lpOutputPath
, -1, Dest
.Destination
, MAX_PATH
, NULL
, NULL
);
227 WideCharToMultiByte(CP_ACP
, 0, lpCabName
, -1, szCabName
, MAX_PATH
, NULL
, NULL
);
228 Dest
.Operation
= EXTRACT_FILLFILELIST
;
230 Result
= pfnExtract(&Dest
, szCabName
);
233 Dest
.Operation
= EXTRACT_EXTRACTFILES
;
234 Result
= pfnExtract(&Dest
, szCabName
);
237 FreeLibrary(hCabinetDll
);
242 FreeLibrary(hCabinetDll
);