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>
15 #include "comctl32supp.h"
19 static HWND hFreeLdrPage
;
21 LPCWSTR lpszFreeLdrIni
= L
"%SystemDrive%\\freeldr.ini";
22 LPCWSTR lpszBootIni
= L
"%SystemDrive%\\boot.ini";
24 typedef struct _FREELDR_SETTINGS
27 WCHAR szDefaultOS
[512];
29 ULONG OSConfigurationCount
;
33 static FREELDR_SETTINGS Settings
= { 0, {0}, 0, 0, FALSE
};
36 LoadIniFile(HWND hDlg
,
52 HFONT hFont
, hOldFont
;
55 * Open for read + write (without file creation if it didn't already exist)
56 * of a read-only text stream.
58 dwNumOfChars
= ExpandEnvironmentStringsW(lpszIniFile
, NULL
, 0);
59 lpszFileName
= (LPWSTR
)MemAlloc(0, dwNumOfChars
* sizeof(WCHAR
));
60 ExpandEnvironmentStringsW(lpszIniFile
, lpszFileName
, dwNumOfChars
);
62 file
= _wfsopen(lpszFileName
, L
"rt", _SH_DENYWR
); // r+t <-- read write text ; rt <-- read text
63 MemFree(lpszFileName
);
65 if (!file
) return FALSE
;
67 hDlgCtrl
= GetDlgItem(hDlg
, IDC_LIST_BOX
);
69 hDC
= GetDC(hDlgCtrl
);
70 hFont
= (HFONT
)SendMessageW(hDlgCtrl
, WM_GETFONT
, 0, 0);
71 hOldFont
= (HFONT
)SelectObject(hDC
, hFont
);
73 while (!feof(file
) && fgetws(szBuffer
, ARRAYSIZE(szBuffer
), file
))
75 length
= wcslen(szBuffer
);
79 szBuffer
[length
-1] = szBuffer
[length
] = L
'\0';
81 pos
= ListBox_AddString(hDlgCtrl
, szBuffer
);
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
);
87 if (szBuffer
[0] == L
'[')
90 if (!_wcsnicmp(szBuffer
, L
"timeout=", 8))
92 Settings
.TimeOut
= _wtoi(&szBuffer
[8]);
96 if (!_wcsnicmp(szBuffer
, L
"default=", 8))
98 wcscpy(Settings
.szDefaultOS
, &szBuffer
[8]);
102 ListBox_SetItemData(hDlgCtrl
, pos
, 1); // indicate that this item is a boot entry
104 Settings
.OSConfigurationCount
++;
108 SelectObject(hDC
, hOldFont
);
109 ReleaseDC(hDlgCtrl
, hDC
);
112 Settings
.UseBootIni
= TRUE
;
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).
118 pos
= ListBox_FindString(hDlgCtrl
, 3, Settings
.szDefaultOS
);
121 Settings
.szDefaultPos
= (ULONG
)pos
;
122 ListBox_SetCurSel(hDlgCtrl
, pos
);
123 // SendMessageW(hDlgCtrl, WM_VSCROLL, SB_LINEDOWN, 0); // Or use SetScroll...()
126 SetDlgItemInt(hDlg
, IDC_TXT_BOOT_TIMEOUT
, Settings
.TimeOut
, FALSE
);
127 if (Settings
.OSConfigurationCount
< 2)
129 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SET_DEFAULT_BOOT
), FALSE
);
130 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_MOVE_UP_BOOT_OPTION
), FALSE
);
131 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_MOVE_DOWN_BOOT_OPTION
), FALSE
);
138 FreeLdrPageWndProc(HWND hDlg
,
147 LPPROPSHEETPAGEW psp
= (LPPROPSHEETPAGEW
)lParam
;
150 LoadIniFile(hDlg
, (LPWSTR
)(psp
->lParam
));
156 switch (LOWORD(wParam
))
158 case IDC_BTN_ADVANCED_OPTIONS
:
159 // DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_FREELDR_ADVANCED_DIALOG), hDlg /* hMainWnd */, NULL /*FileExtractDialogWndProc*/);
166 switch (HIWORD(wParam
))
170 HWND hWnd
= (HWND
)lParam
;
173 pos
= ListBox_GetCurSel(hWnd
);
176 if (!ListBox_GetItemData(hWnd
, pos
)) // Line is not a default one
177 ListBox_SetCurSel(hWnd
, Settings
.szDefaultPos
);
179 Settings
.szDefaultPos
= (ULONG
)pos
;
181 // SendMessageW((HWND)lParam, WM_VSCROLL, SB_LINEDOWN, 0); // Or use SetScroll...()