ReactOS 0.4.15-dev-7659-ga55345b
freeldrpage.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Applications
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/msconfig_new/freeldrpage.c
5 * PURPOSE: Freeloader configuration page message handler
6 * COPYRIGHT: Copyright 2005-2006 Christoph von Wittich <Christoph@ApiViewer.de>
7 * 2011 Gregor Schneider <Gregor.Schneider@reactos.org>
8 * Copyright 2011-2012 Hermes BELUSCA - MAITO <hermes.belusca@sfr.fr>
9 */
10
11#include "precomp.h"
12#include <share.h>
13
14#include <wingdi.h>
15#include "comctl32supp.h"
16
17#include "utils.h"
18
20
21LPCWSTR lpszFreeLdrIni = L"%SystemDrive%\\freeldr.ini";
22LPCWSTR lpszBootIni = L"%SystemDrive%\\boot.ini";
23
24typedef struct _FREELDR_SETTINGS
25{
32
33static FREELDR_SETTINGS Settings = { 0, {0}, 0, 0, FALSE };
34
35static BOOL
37 LPCWSTR lpszIniFile)
38{
39 DWORD dwNumOfChars;
40 LPWSTR lpszFileName;
41 FILE* file;
42
43 WCHAR szBuffer[512];
44 HWND hDlgCtrl;
47
48 SIZE size;
49 LONG horzExt;
50
51 HDC hDC;
52 HFONT hFont, hOldFont;
53
54 /*
55 * Open for read + write (without file creation if it didn't already exist)
56 * of a read-only text stream.
57 */
58 dwNumOfChars = ExpandEnvironmentStringsW(lpszIniFile, NULL, 0);
59 lpszFileName = (LPWSTR)MemAlloc(0, dwNumOfChars * sizeof(WCHAR));
60 ExpandEnvironmentStringsW(lpszIniFile, lpszFileName, dwNumOfChars);
61
62 file = _wfsopen(lpszFileName, L"rt", _SH_DENYWR); // r+t <-- read write text ; rt <-- read text
63 MemFree(lpszFileName);
64
65 if (!file) return FALSE;
66
67 hDlgCtrl = GetDlgItem(hDlg, IDC_LIST_BOX);
68
69 hDC = GetDC(hDlgCtrl);
70 hFont = (HFONT)SendMessageW(hDlgCtrl, WM_GETFONT, 0, 0);
71 hOldFont = (HFONT)SelectObject(hDC, hFont);
72
73 while (!feof(file) && fgetws(szBuffer, ARRAYSIZE(szBuffer), file))
74 {
75 length = wcslen(szBuffer);
76 if (length > 1)
77 {
78 /* Remove \r\n */
79 szBuffer[length-1] = szBuffer[length] = L'\0';
80
81 pos = ListBox_AddString(hDlgCtrl, szBuffer);
82
83 GetTextExtentPoint32W(hDC, szBuffer, (int)wcslen(szBuffer), &size);
84 horzExt = max((LONG)ListBox_GetHorizontalExtent(hDlgCtrl), size.cx + 5); // 5 to have a little room between the text and the end of the list box.
85 ListBox_SetHorizontalExtent(hDlgCtrl, horzExt);
86
87 if (szBuffer[0] == L'[')
88 continue;
89
90 if (!_wcsnicmp(szBuffer, L"timeout=", 8))
91 {
92 Settings.TimeOut = _wtoi(&szBuffer[8]);
93 continue;
94 }
95
96 if (!_wcsnicmp(szBuffer, L"default=", 8))
97 {
98 wcscpy(Settings.szDefaultOS, &szBuffer[8]);
99 continue;
100 }
101 if (pos != LB_ERR)
102 ListBox_SetItemData(hDlgCtrl, pos, 1); // indicate that this item is a boot entry
103
104 Settings.OSConfigurationCount++;
105 }
106 }
107
108 SelectObject(hDC, hOldFont);
109 ReleaseDC(hDlgCtrl, hDC);
110
111 fclose(file);
112 Settings.UseBootIni = TRUE;
113
114 /*
115 * Start to search for the string at the "operating systems" section
116 * (after the "boot loader" section, which takes 3 lines in the .INI file).
117 */
118 pos = ListBox_FindString(hDlgCtrl, 3, Settings.szDefaultOS);
119 if (pos != LB_ERR)
120 {
121 Settings.szDefaultPos = (ULONG)pos;
122 ListBox_SetCurSel(hDlgCtrl, pos);
123 // SendMessageW(hDlgCtrl, WM_VSCROLL, SB_LINEDOWN, 0); // Or use SetScroll...()
124 }
125
127 if (Settings.OSConfigurationCount < 2)
128 {
132 }
133
134 return TRUE;
135}
136
142{
143 switch (message)
144 {
145 case WM_INITDIALOG:
146 {
148
149 hFreeLdrPage = hDlg;
150 LoadIniFile(hDlg, (LPWSTR)(psp->lParam));
151 return TRUE;
152 }
153
154 case WM_COMMAND:
155 {
156 switch (LOWORD(wParam))
157 {
159 // DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_FREELDR_ADVANCED_DIALOG), hDlg /* hMainWnd */, NULL /*FileExtractDialogWndProc*/);
160 break;
161
162 // default:
163 // return FALSE;
164 }
165
166 switch (HIWORD(wParam))
167 {
168 case LBN_SELCHANGE:
169 {
170 HWND hWnd = (HWND)lParam;
171 LRESULT pos;
172
174 if (pos != LB_ERR)
175 {
176 if (!ListBox_GetItemData(hWnd, pos)) // Line is not a default one
177 ListBox_SetCurSel(hWnd, Settings.szDefaultPos);
178 else
179 Settings.szDefaultPos = (ULONG)pos;
180
181 // SendMessageW((HWND)lParam, WM_VSCROLL, SB_LINEDOWN, 0); // Or use SetScroll...()
182 }
183
184 return TRUE;
185 }
186 }
187 }
188
189 default:
190 return FALSE;
191 }
192
193 // return FALSE;
194}
static HDC hDC
Definition: 3dtext.c:33
HWND hWnd
Definition: settings.c:17
#define IDC_LIST_BOX
Definition: resource.h:30
#define IDC_BTN_SET_DEFAULT_BOOT
Definition: resource.h:32
#define IDC_BTN_MOVE_DOWN_BOOT_OPTION
Definition: resource.h:34
#define IDC_BTN_MOVE_UP_BOOT_OPTION
Definition: resource.h:33
#define IDC_TXT_BOOT_TIMEOUT
Definition: resource.h:41
#define IDC_BTN_ADVANCED_OPTIONS
Definition: resource.h:40
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
PVOID MemAlloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: utils.c:33
HFONT hFont
Definition: main.c:53
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
HANDLE HWND
Definition: compat.h:19
#define CALLBACK
Definition: compat.h:35
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
_Check_return_ _CRTIMP FILE *__cdecl _wfsopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode, _In_ int _ShFlag)
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static HDC
Definition: imagelist.c:92
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
HWND hFreeLdrPage
Definition: freeldrpage.c:12
INT_PTR CALLBACK FreeLdrPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: freeldrpage.c:134
LPCWSTR lpszFreeLdrIni
Definition: freeldrpage.c:21
LPCWSTR lpszBootIni
Definition: freeldrpage.c:22
static BOOL LoadIniFile(HWND hDlg, LPCWSTR lpszIniFile)
Definition: freeldrpage.c:36
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
long LONG
Definition: pedump.c:60
struct _PROPSHEETPAGEW * LPPROPSHEETPAGEW
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define _SH_DENYWR
Definition: share.h:15
WCHAR szDefaultOS[512]
Definition: freeldrpage.c:27
ULONG OSConfigurationCount
Definition: freeldrpage.c:29
LPARAM lParam
Definition: prsht.h:227
Definition: fci.c:127
Definition: tftpd.h:60
#define max(a, b)
Definition: svc.c:63
int32_t INT_PTR
Definition: typedefs.h:64
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
#define HIWORD(l)
Definition: typedefs.h:247
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
Definition: wdfdevice.h:2595
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define ListBox_GetCurSel(hwndCtl)
Definition: windowsx.h:481
#define ListBox_FindString(hwndCtl, indexStart, lpszFind)
Definition: windowsx.h:477
#define ListBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:500
#define ListBox_GetItemData(hwndCtl, index)
Definition: windowsx.h:483
#define ListBox_GetHorizontalExtent(hwndCtl)
Definition: windowsx.h:482
#define ListBox_SetItemData(hwndCtl, index, data)
Definition: windowsx.h:502
#define ListBox_AddString(hwndCtl, lpsz)
Definition: windowsx.h:472
#define ListBox_SetHorizontalExtent(hwndCtl, cxExtent)
Definition: windowsx.h:501
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
BOOL WINAPI GetTextExtentPoint32W(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpString, _In_ int c, _Out_ LPSIZE psizl)
#define LB_ERR
Definition: winuser.h:2431
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_COMMAND
Definition: winuser.h:1739
#define WM_INITDIALOG
Definition: winuser.h:1738
#define WM_GETFONT
Definition: winuser.h:1650
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI SetDlgItemInt(_In_ HWND, _In_ int, _In_ UINT, _In_ BOOL)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HDC WINAPI GetDC(_In_opt_ HWND)
#define LBN_SELCHANGE
Definition: winuser.h:2074
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185