ReactOS 0.4.16-dev-122-g325d74c
freeldrpage.c File Reference
#include "precomp.h"
#include <share.h>
#include <wingdi.h>
#include "comctl32supp.h"
#include "utils.h"
Include dependency graph for freeldrpage.c:

Go to the source code of this file.

Classes

struct  _FREELDR_SETTINGS
 

Typedefs

typedef struct _FREELDR_SETTINGS FREELDR_SETTINGS
 

Functions

static BOOL LoadIniFile (HWND hDlg, LPCWSTR lpszIniFile)
 
INT_PTR CALLBACK FreeLdrPageWndProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 

Variables

static HWND hFreeLdrPage
 
LPCWSTR lpszFreeLdrIni = L"%SystemDrive%\\freeldr.ini"
 
LPCWSTR lpszBootIni = L"%SystemDrive%\\boot.ini"
 
static FREELDR_SETTINGS Settings = { 0, {0}, 0, 0, FALSE }
 

Typedef Documentation

◆ FREELDR_SETTINGS

Function Documentation

◆ FreeLdrPageWndProc()

INT_PTR CALLBACK FreeLdrPageWndProc ( HWND  hDlg,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 138 of file freeldrpage.c.

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}
HWND hWnd
Definition: settings.c:17
#define IDC_BTN_ADVANCED_OPTIONS
Definition: resource.h:40
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HANDLE HWND
Definition: compat.h:19
static HWND hFreeLdrPage
Definition: freeldrpage.c:19
static BOOL LoadIniFile(HWND hDlg, LPCWSTR lpszIniFile)
Definition: freeldrpage.c:36
#define LOWORD(l)
Definition: pedump.c:82
struct _PROPSHEETPAGEW * LPPROPSHEETPAGEW
LPARAM lParam
Definition: prsht.h:227
Definition: tftpd.h:60
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 LRESULT
Definition: windef.h:209
#define ListBox_GetCurSel(hwndCtl)
Definition: windowsx.h:481
#define ListBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:500
#define ListBox_GetItemData(hwndCtl, index)
Definition: windowsx.h:483
#define LB_ERR
Definition: winuser.h:2435
#define WM_COMMAND
Definition: winuser.h:1743
#define WM_INITDIALOG
Definition: winuser.h:1742
#define LBN_SELCHANGE
Definition: winuser.h:2078
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ LoadIniFile()

static BOOL LoadIniFile ( HWND  hDlg,
LPCWSTR  lpszIniFile 
)
static

Definition at line 36 of file freeldrpage.c.

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}
static HDC hDC
Definition: 3dtext.c:33
#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
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
#define NULL
Definition: types.h:112
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
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:88
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
_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
Definition: fci.c:127
#define max(a, b)
Definition: svc.c:63
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define ListBox_FindString(hwndCtl, indexStart, lpszFind)
Definition: windowsx.h:477
#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:1546
BOOL WINAPI GetTextExtentPoint32W(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpString, _In_ int c, _Out_ LPSIZE psizl)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_GETFONT
Definition: winuser.h:1654
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)
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

Referenced by FreeLdrPageWndProc().

Variable Documentation

◆ hFreeLdrPage

HWND hFreeLdrPage
static

Definition at line 19 of file freeldrpage.c.

◆ lpszBootIni

LPCWSTR lpszBootIni = L"%SystemDrive%\\boot.ini"

Definition at line 22 of file freeldrpage.c.

Referenced by CreatePropSheet().

◆ lpszFreeLdrIni

LPCWSTR lpszFreeLdrIni = L"%SystemDrive%\\freeldr.ini"

Definition at line 21 of file freeldrpage.c.

Referenced by CreatePropSheet().

◆ Settings

FREELDR_SETTINGS Settings = { 0, {0}, 0, 0, FALSE }
static

Definition at line 33 of file freeldrpage.c.