ReactOS  0.4.12-dev-57-g7050ac4
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 
173  pos = ListBox_GetCurSel(hWnd);
174  if (pos != LB_ERR)
175  {
176  if (!ListBox_GetItemData(hWnd, pos)) // Line is not a default one
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 }
Definition: tftpd.h:59
#define TRUE
Definition: types.h:120
#define ListBox_GetCurSel(hwndCtl)
Definition: windowsx.h:451
static BOOL LoadIniFile(HWND hDlg, LPCWSTR lpszIniFile)
Definition: freeldrpage.c:36
HWND hWnd
Definition: settings.c:17
HANDLE HWND
Definition: compat.h:13
#define LBN_SELCHANGE
Definition: winuser.h:2036
#define ListBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:470
WPARAM wParam
Definition: combotst.c:138
#define LB_ERR
Definition: winuser.h:2386
struct _PROPSHEETPAGEW * LPPROPSHEETPAGEW
#define IDC_BTN_ADVANCED_OPTIONS
Definition: resource.h:40
#define ListBox_GetItemData(hwndCtl, index)
Definition: windowsx.h:453
static FREELDR_SETTINGS Settings
Definition: freeldrpage.c:33
LPARAM lParam
Definition: prsht.h:218
#define WM_COMMAND
Definition: winuser.h:1716
HWND hFreeLdrPage
Definition: freeldrpage.c:12
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LONG_PTR LRESULT
Definition: windef.h:209
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82

◆ LoadIniFile()

static BOOL LoadIniFile ( HWND  hDlg,
LPCWSTR  lpszIniFile 
)
static

Definition at line 36 of file freeldrpage.c.

Referenced by FreeLdrPageWndProc().

38 {
39  DWORD dwNumOfChars;
40  LPWSTR lpszFileName;
41  FILE* file;
42 
43  WCHAR szBuffer[512];
44  HWND hDlgCtrl;
45  SIZE_T length;
46  LRESULT pos;
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 
105  }
106  }
107 
108  SelectObject(hDC, hOldFont);
109  ReleaseDC(hDlgCtrl, hDC);
110 
111  fclose(file);
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 
128  {
132  }
133 
134  return TRUE;
135 }
WCHAR szDefaultOS[512]
Definition: freeldrpage.c:18
#define HDC
Definition: msvc.h:22
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
#define IDC_TXT_BOOT_TIMEOUT
Definition: resource.h:41
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
HDC WINAPI GetDC(_In_opt_ HWND)
__wchar_t WCHAR
Definition: xmlstorage.h:180
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
_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 ListBox_AddString(hwndCtl, lpsz)
Definition: windowsx.h:442
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define ListBox_GetHorizontalExtent(hwndCtl)
Definition: windowsx.h:452
#define IDC_LIST_BOX
Definition: resource.h:30
#define ListBox_FindString(hwndCtl, indexStart, lpszFind)
Definition: windowsx.h:447
#define ListBox_SetHorizontalExtent(hwndCtl, cxExtent)
Definition: windowsx.h:471
#define ListBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:470
HFONT hFont
Definition: main.c:53
_Check_return_ _CRTIMP FILE *__cdecl _wfsopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode, _In_ int _ShFlag)
#define IDC_BTN_MOVE_UP_BOOT_OPTION
Definition: resource.h:33
#define LB_ERR
Definition: winuser.h:2386
long LONG
Definition: pedump.c:60
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define IDC_BTN_MOVE_DOWN_BOOT_OPTION
Definition: resource.h:34
smooth NULL
Definition: ftsmooth.c:416
#define WM_GETFONT
Definition: winuser.h:1633
LONG cx
Definition: windef.h:324
#define ListBox_SetItemData(hwndCtl, index, data)
Definition: windowsx.h:472
#define _SH_DENYWR
Definition: share.h:15
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
static FREELDR_SETTINGS Settings
Definition: freeldrpage.c:33
GLsizeiptr size
Definition: glext.h:5919
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
const char file[]
Definition: icontest.c:11
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG OSConfigurationCount
Definition: freeldrpage.c:20
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
BOOL WINAPI SetDlgItemInt(_In_ HWND, _In_ int, _In_ UINT, _In_ BOOL)
static const WCHAR L[]
Definition: oid.c:1087
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
static HDC hDC
Definition: 3dtext.c:33
ULONG_PTR SIZE_T
Definition: typedefs.h:78
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LONG_PTR LRESULT
Definition: windef.h:209
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOL WINAPI GetTextExtentPoint32W(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpString, _In_ int c, _Out_ LPSIZE psizl)
#define IDC_BTN_SET_DEFAULT_BOOT
Definition: resource.h:32

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.