@@ -128,6 +128,12 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPara
128128 if (res != LB_ERR )
129129 {
130130 selected_index = res ;
131+ int tabIndex = TabCtrl_GetCurSel (hWndTab );
132+ int tabSize = sizeof (tabCounts ) / sizeof (tabCounts [0 ]);
133+ for (int i = 0 ; i < tabIndex ; i ++ )
134+ {
135+ selected_index += tabCounts [i ];
136+ }
131137 PostQuitMessage (WM_QUIT );
132138 }
133139 break ;
@@ -157,7 +163,7 @@ int ShowMessageBox(const char* title, const char* message)
157163 return MessageBox (NULL , message , title , MB_OK | MB_ICONEXCLAMATION );
158164}
159165
160- int SelectionDialog (const wchar_t * title , int count , const char * * list , int modsCount , const char * * modsList , int selection )
166+ int SelectionDialog (const char * title , int count , const char * * list , int modsCount , const char * * modsList , int selection )
161167{
162168 INITCOMMONCONTROLSEX icex ;
163169 icex .dwSize = sizeof (INITCOMMONCONTROLSEX );
@@ -201,7 +207,7 @@ int SelectionDialog(const wchar_t* title, int count, const char** list, int mods
201207
202208 RegisterClassExW (& wc );
203209
204- const wchar_t * unicodeTitle = title ;
210+ const wchar_t * unicodeTitle = ConvertStringToUnicode ( title ) ;
205211
206212 hWnd = CreateWindowExW (
207213 WS_EX_CLIENTEDGE ,
@@ -214,34 +220,40 @@ int SelectionDialog(const wchar_t* title, int count, const char** list, int mods
214220 hInstance , NULL
215221 );
216222
217- // free(unicodeTitle);
223+ free (unicodeTitle );
218224
219- for (int i = 0 ; i < count ; ++ i )
225+ // Find current tab and selection, and populate the ListBox
226+ int tabIndex ;
227+ int tabSize = sizeof (tabCounts ) / sizeof (tabCounts [0 ]);
228+ for (tabIndex = 0 ; tabIndex < tabSize ; tabIndex ++ )
220229 {
221- wchar_t * unicodeGameName = ConvertStringToUnicode (list [i ]);
222- SendMessageW (hWndList , LB_ADDSTRING , 0 , (LPARAM )(LPCWSTR )unicodeGameName );
223- free (unicodeGameName );
230+ if (tabCounts [tabIndex ] < selection ) {
231+ selection -= tabCounts [tabIndex ];
232+ } else {
233+ break ;
234+ }
224235 }
236+ PopulateListBoxWithSelection (tabIndex , selection );
225237
226- SendMessageW (hWndList , LB_SETCURSEL , selection , 0 );
227-
238+ // Show window and get all events
228239 ShowWindow (hWnd , SW_SHOWNORMAL );
229240
230- // TODO: Start at where game is matched
231- PopulateListBox (0 );
232-
233241 while (GetMessage (& Msg , NULL , 0 , 0 ))
234242 {
235243 TranslateMessage (& Msg );
236244 DispatchMessage (& Msg );
237245 }
238246
247+ // Return the current selection
239248 return selected_index ;
240249}
241250
242- void PopulateListBox (int tabIndex )
251+ // Load values into current ListBox with a highlighted option
252+ void PopulateListBoxWithSelection (int tabIndex , int selection )
243253{
244- SendMessage (hWndList , LB_RESETCONTENT , 0 , 0 );
254+ SendMessageW (hWndList , LB_RESETCONTENT , 0 , 0 );
255+ /*SendMessageW(hWndList, TCM_SETCURSEL, 0, (LPARAM)tabIndex);*/
256+ TabCtrl_SetCurSel (hWndTab , tabIndex );
245257
246258 for (int i = 0 ; i < tabCounts [tabIndex ]; ++ i )
247259 {
@@ -250,11 +262,17 @@ void PopulateListBox(int tabIndex)
250262 free (unicode );
251263 }
252264
253- if (tabCounts [ tabIndex ] > 0 ) {
254- SendMessage (hWndList , LB_SETCURSEL , 0 , 0 );
265+ if (selection > -1 ) {
266+ SendMessageW (hWndList , LB_SETCURSEL , selection , 0 );
255267 }
256268}
257269
270+ // Load valuies into current ListBox without a highlighted option
271+ void PopulateListBox (int tabIndex )
272+ {
273+ PopulateListBoxWithSelection (tabIndex , -1 );
274+ }
275+
258276
259277// Convert ANSI string to unicode (char to widechar)
260278wchar_t * ConvertStringToUnicode (const char * string )
0 commit comments