ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dialogs.cpp
Go to the documentation of this file.
00001 /*
00002  *    common shell dialogs
00003  *
00004  * Copyright 2000 Juergen Schmied
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include <precomp.h>
00022 
00023 
00024 typedef struct
00025 {
00026     HWND hwndOwner ;
00027     HICON hIcon ;
00028     LPCWSTR lpstrDirectory ;
00029     LPCWSTR lpstrTitle ;
00030     LPCWSTR lpstrDescription ;
00031     UINT uFlags ;
00032 } RUNFILEDLGPARAMS ;
00033 
00034 typedef BOOL (WINAPI * LPFNOFN) (OPENFILENAMEW *) ;
00035 
00036 WINE_DEFAULT_DEBUG_CHANNEL(shell);
00037 static INT_PTR CALLBACK RunDlgProc (HWND, UINT, WPARAM, LPARAM) ;
00038 static void FillList (HWND, char *, BOOL) ;
00039 
00040 
00041 /*************************************************************************
00042  * PickIconDlg                    [SHELL32.62]
00043  *
00044  */
00045 
00046 typedef struct
00047 {
00048     HMODULE hLibrary;
00049     HWND hDlgCtrl;
00050     WCHAR szName[MAX_PATH];
00051     INT Index;
00052 } PICK_ICON_CONTEXT, *PPICK_ICON_CONTEXT;
00053 
00054 BOOL CALLBACK EnumPickIconResourceProc(HMODULE hModule,
00055     LPCWSTR lpszType,
00056     LPWSTR lpszName,
00057     LONG_PTR lParam
00058 )
00059 {
00060     WCHAR szName[100];
00061     int index;
00062     HICON  hIcon;
00063     PPICK_ICON_CONTEXT pIconContext = (PPICK_ICON_CONTEXT)lParam;
00064 
00065     if (IS_INTRESOURCE(lpszName))
00066         swprintf(szName, L"%u", lpszName);
00067     else
00068         wcscpy(szName, (WCHAR*)lpszName);
00069 
00070 
00071     hIcon = LoadIconW(pIconContext->hLibrary, (LPCWSTR)lpszName);
00072     if (hIcon == NULL)
00073         return TRUE;
00074 
00075     index = SendMessageW(pIconContext->hDlgCtrl, LB_ADDSTRING, 0, (LPARAM)szName);
00076     if (index != LB_ERR)
00077         SendMessageW(pIconContext->hDlgCtrl, LB_SETITEMDATA, index, (LPARAM)hIcon);
00078 
00079     return TRUE;
00080 }
00081 
00082 static void
00083 DestroyIconList(HWND hDlgCtrl)
00084 {
00085     int count;
00086     int index;
00087 
00088     count = SendMessage(hDlgCtrl, LB_GETCOUNT, 0, 0);
00089     if (count == LB_ERR)
00090         return;
00091 
00092     for(index = 0; index < count; index++)
00093     {
00094         HICON hIcon = (HICON)SendMessageW(hDlgCtrl, LB_GETITEMDATA, index, 0);
00095         DestroyIcon(hIcon);
00096     }
00097 }
00098 
00099 INT_PTR CALLBACK PickIconProc(HWND hwndDlg,
00100     UINT uMsg,
00101     WPARAM wParam,
00102     LPARAM lParam
00103 )
00104 {
00105     LPMEASUREITEMSTRUCT lpmis; 
00106     LPDRAWITEMSTRUCT lpdis; 
00107     HICON hIcon;
00108     INT index, count;
00109     WCHAR szText[MAX_PATH], szTitle[100], szFilter[100];
00110     OPENFILENAMEW ofn = {0};
00111 
00112     PPICK_ICON_CONTEXT pIconContext = (PPICK_ICON_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
00113 
00114     switch(uMsg)
00115     {
00116     case WM_INITDIALOG:
00117         pIconContext = (PPICK_ICON_CONTEXT)lParam;
00118         SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG)pIconContext);
00119         pIconContext->hDlgCtrl = GetDlgItem(hwndDlg, IDC_PICKICON_LIST);
00120         EnumResourceNamesW(pIconContext->hLibrary, RT_ICON, EnumPickIconResourceProc, (LPARAM)pIconContext);
00121         if (PathUnExpandEnvStringsW(pIconContext->szName, szText, MAX_PATH))
00122             SetDlgItemTextW(hwndDlg, IDC_EDIT_PATH, szText);
00123         else
00124             SetDlgItemTextW(hwndDlg, IDC_EDIT_PATH, pIconContext->szName);
00125 
00126         count = SendMessage(pIconContext->hDlgCtrl, LB_GETCOUNT, 0, 0);
00127         if (count != LB_ERR)
00128         {
00129             if (count > pIconContext->Index)
00130                 SendMessageW(pIconContext->hDlgCtrl, LB_SETCURSEL, pIconContext->Index, 0);
00131             else
00132                 SendMessageW(pIconContext->hDlgCtrl, LB_SETCURSEL, 0, 0);
00133         }
00134         return TRUE;
00135     case WM_COMMAND:
00136         switch(LOWORD(wParam))
00137         {
00138         case IDOK:
00139             index = SendMessageW(pIconContext->hDlgCtrl, LB_GETCURSEL, 0, 0);
00140             pIconContext->Index = index;
00141             GetDlgItemTextW(hwndDlg, IDC_EDIT_PATH, pIconContext->szName, MAX_PATH);
00142             DestroyIconList(pIconContext->hDlgCtrl);
00143             EndDialog(hwndDlg, 1);
00144             break;
00145         case IDCANCEL:
00146             DestroyIconList(pIconContext->hDlgCtrl);
00147             EndDialog(hwndDlg, 0);
00148             break;
00149         case IDC_PICKICON_LIST:
00150             if (HIWORD(wParam) == LBN_SELCHANGE)
00151                 InvalidateRect((HWND)lParam, NULL, TRUE); // FIXME USE UPDATE RECT
00152             break;
00153         case IDC_BUTTON_PATH:
00154             szText[0] = 0;
00155             szTitle[0] = 0;
00156             szFilter[0] = 0;
00157             ofn.lStructSize = sizeof(ofn);
00158             ofn.hwndOwner = hwndDlg;
00159             ofn.lpstrFile = szText;
00160             ofn.nMaxFile = MAX_PATH;
00161             LoadStringW(shell32_hInstance, IDS_PICK_ICON_TITLE, szTitle, sizeof(szTitle) / sizeof(WCHAR));
00162             ofn.lpstrTitle = szTitle;
00163             LoadStringW(shell32_hInstance, IDS_PICK_ICON_FILTER, szFilter, sizeof(szFilter) / sizeof(WCHAR));
00164             ofn.lpstrFilter = szFilter;
00165             if (GetOpenFileNameW(&ofn))
00166             {
00167                 HMODULE hLibrary;
00168 
00169                 if (!wcsicmp(pIconContext->szName, szText))
00170                     break;
00171 
00172                 DestroyIconList(pIconContext->hDlgCtrl);
00173 
00174                 hLibrary = LoadLibraryExW(szText, NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE);
00175                 if (hLibrary == NULL)
00176                     break;
00177                 FreeLibrary(pIconContext->hLibrary);
00178                 pIconContext->hLibrary = hLibrary;
00179                 wcscpy(pIconContext->szName, szText);
00180                 EnumResourceNamesW(pIconContext->hLibrary, RT_ICON, EnumPickIconResourceProc, (LPARAM)pIconContext);
00181                 if (PathUnExpandEnvStringsW(pIconContext->szName, szText, MAX_PATH))
00182                     SetDlgItemTextW(hwndDlg, IDC_EDIT_PATH, szText);
00183                 else
00184                     SetDlgItemTextW(hwndDlg, IDC_EDIT_PATH, pIconContext->szName);
00185 
00186                 SendMessageW(pIconContext->hDlgCtrl, LB_SETCURSEL, 0, 0);
00187             }
00188             break;
00189         }
00190         break;
00191         case WM_MEASUREITEM:
00192             lpmis = (LPMEASUREITEMSTRUCT) lParam; 
00193             lpmis->itemHeight = 32;
00194             lpmis->itemWidth = 64;
00195             return TRUE; 
00196         case WM_DRAWITEM: 
00197             lpdis = (LPDRAWITEMSTRUCT) lParam; 
00198            if (lpdis->itemID == (UINT)-1) 
00199             { 
00200                 break; 
00201             } 
00202             switch (lpdis->itemAction) 
00203             { 
00204                 case ODA_SELECT: 
00205                 case ODA_DRAWENTIRE:
00206                     index = SendMessageW(pIconContext->hDlgCtrl, LB_GETCURSEL, 0, 0);
00207                     hIcon =(HICON)SendMessage(lpdis->hwndItem, LB_GETITEMDATA, lpdis->itemID, (LPARAM) 0);
00208 
00209                     if (lpdis->itemID == (UINT)index)
00210                     {
00211                         HBRUSH hBrush;
00212                         hBrush = CreateSolidBrush(RGB(0, 0, 255));
00213                         FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
00214                         DeleteObject(hBrush);
00215                     }
00216                     else
00217                     {
00218                         HBRUSH hBrush;
00219                         hBrush = CreateSolidBrush(RGB(255, 255, 255));
00220                         FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
00221                         DeleteObject(hBrush);
00222                     }
00223                     DrawIconEx(lpdis->hDC, lpdis->rcItem.left,lpdis->rcItem.top, hIcon, 
00224                                 0,
00225                                 0,
00226                                 0,
00227                                 NULL,
00228                                 DI_NORMAL);
00229                     break;
00230             }
00231             break;
00232     }
00233 
00234     return FALSE;
00235 }
00236 
00237 BOOL WINAPI PickIconDlg(
00238     HWND hwndOwner,
00239     LPWSTR lpstrFile,
00240     UINT nMaxFile,
00241     INT* lpdwIconIndex)
00242 {
00243     HMODULE hLibrary;
00244     int res;
00245     PICK_ICON_CONTEXT IconContext;
00246 
00247     hLibrary = LoadLibraryExW(lpstrFile, NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE);
00248     IconContext.hLibrary = hLibrary;
00249     IconContext.Index = *lpdwIconIndex;
00250     wcscpy(IconContext.szName, lpstrFile);
00251 
00252     res = DialogBoxParamW(shell32_hInstance, MAKEINTRESOURCEW(IDD_PICK_ICON), hwndOwner, PickIconProc, (LPARAM)&IconContext);
00253     if (res)
00254     {
00255         wcscpy(lpstrFile, IconContext.szName);
00256         *lpdwIconIndex = IconContext.Index;
00257     }
00258 
00259     FreeLibrary(hLibrary);
00260     return res;
00261 }
00262 
00263 /*************************************************************************
00264  * RunFileDlg                    [internal]
00265  *
00266  * The Unicode function that is available as ordinal 61 on Windows NT/2000/XP/...
00267  */
00268 void WINAPI RunFileDlg(
00269     HWND hwndOwner,
00270     HICON hIcon,
00271     LPCWSTR lpstrDirectory,
00272     LPCWSTR lpstrTitle,
00273     LPCWSTR lpstrDescription,
00274     UINT uFlags)
00275 {
00276     TRACE("\n");
00277 
00278     RUNFILEDLGPARAMS rfdp;
00279     rfdp.hwndOwner        = hwndOwner;
00280     rfdp.hIcon            = hIcon;
00281     rfdp.lpstrDirectory   = lpstrDirectory;
00282     rfdp.lpstrTitle       = lpstrTitle;
00283     rfdp.lpstrDescription = lpstrDescription;
00284     rfdp.uFlags           = uFlags;
00285 
00286     DialogBoxParamW(shell32_hInstance, MAKEINTRESOURCEW(IDD_RUN), hwndOwner, RunDlgProc, (LPARAM)&rfdp);
00287 
00288 }
00289 
00290 
00291 /* find the directory that contains the file being run */
00292 static LPWSTR RunDlg_GetParentDir(LPCWSTR cmdline)
00293 {
00294     const WCHAR *src;
00295     WCHAR *dest, *result, *result_end=NULL;
00296     static const WCHAR dotexeW[] = L".exe";
00297 
00298     result = (WCHAR *)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(strlenW(cmdline)+5));
00299 
00300     if (NULL == result)
00301     {
00302         TRACE("HeapAlloc couldn't allocate %d bytes\n", sizeof(WCHAR)*(strlenW(cmdline)+5));
00303         return NULL;
00304     }
00305 
00306     src = cmdline;
00307     dest = result;
00308 
00309     if (*src == '"')
00310     {
00311         src++;
00312         while (*src && *src != '"')
00313         {
00314             if (*src == '\\')
00315                 result_end = dest;
00316             *dest++ = *src++;
00317         }
00318     }
00319     else {
00320         while (*src)
00321         {
00322             if (isspaceW(*src))
00323             {
00324                 *dest = 0;
00325                 if (INVALID_FILE_ATTRIBUTES != GetFileAttributesW(result))
00326                     break;
00327                 strcatW(dest, dotexeW);
00328                 if (INVALID_FILE_ATTRIBUTES != GetFileAttributesW(result))
00329                     break;
00330             }
00331             else if (*src == '\\')
00332                 result_end = dest;
00333             *dest++ = *src++;
00334         }
00335     }
00336 
00337     if (result_end)
00338     {
00339         *result_end = 0;
00340         return result;
00341     }
00342     else
00343     {
00344         HeapFree(GetProcessHeap(), 0, result);
00345         return NULL;
00346     }
00347 }
00348 
00349 
00350 /* Dialog procedure for RunFileDlg */
00351 static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00352 {
00353     RUNFILEDLGPARAMS *prfdp = (RUNFILEDLGPARAMS *)GetWindowLongPtrW(hwnd, DWLP_USER);
00354 
00355     switch (message)
00356         {
00357         case WM_INITDIALOG :
00358             prfdp = (RUNFILEDLGPARAMS *)lParam ;
00359             SetWindowLongPtrW(hwnd, DWLP_USER, (LONG_PTR)prfdp);
00360 
00361             if (prfdp->lpstrTitle)
00362                 SetWindowTextW(hwnd, prfdp->lpstrTitle);
00363             if (prfdp->lpstrDescription)
00364                 SetWindowTextW(GetDlgItem(hwnd, IDC_RUNDLG_DESCRIPTION), prfdp->lpstrDescription);
00365             if (prfdp->uFlags & RFF_NOBROWSE)
00366             {
00367                 HWND browse = GetDlgItem(hwnd, IDC_RUNDLG_BROWSE);
00368                 ShowWindow(browse, SW_HIDE);
00369                 EnableWindow(browse, FALSE);
00370             }
00371             if (prfdp->uFlags & RFF_NOLABEL)
00372                 ShowWindow(GetDlgItem(hwnd, IDC_RUNDLG_LABEL), SW_HIDE);
00373             if (prfdp->uFlags & RFF_CALCDIRECTORY)
00374                 FIXME("RFF_CALCDIRECTORY not supported\n");
00375 
00376             if (prfdp->hIcon == NULL)
00377                 prfdp->hIcon = LoadIconW(NULL, (LPCWSTR)IDI_WINLOGO);
00378             SendMessageW(hwnd, WM_SETICON, ICON_BIG, (LPARAM)prfdp->hIcon);
00379             SendMessageW(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)prfdp->hIcon);
00380             SendMessageW(GetDlgItem(hwnd, IDC_RUNDLG_ICON), STM_SETICON, (WPARAM)prfdp->hIcon, 0);
00381 
00382             FillList (GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH), NULL, (prfdp->uFlags & RFF_NODEFAULT) == 0) ;
00383             SetFocus (GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH)) ;
00384             return TRUE ;
00385 
00386         case WM_COMMAND :
00387             switch (LOWORD (wParam))
00388             {
00389                 case IDOK :
00390                 {
00391                     int ic ;
00392                     HWND htxt = GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH);
00393                     if ((ic = GetWindowTextLengthW (htxt)))
00394                     {
00395                         WCHAR *psz, *parent=NULL ;
00396                         SHELLEXECUTEINFOW sei ;
00397 
00398                         ZeroMemory (&sei, sizeof(sei)) ;
00399                         sei.cbSize = sizeof(sei) ;
00400                         psz = (WCHAR *)HeapAlloc( GetProcessHeap(), 0, (ic + 1)*sizeof(WCHAR) );
00401 
00402                         if (psz)
00403                         {
00404                             GetWindowTextW (htxt, psz, ic + 1) ;
00405 
00406                             /* according to http://www.codeproject.com/KB/shell/runfiledlg.aspx we should send a
00407                              * WM_NOTIFY before execution */
00408 
00409                             sei.hwnd = hwnd;
00410                             sei.nShow = SW_SHOWNORMAL;
00411                             sei.lpFile = psz;
00412 
00413                             if (prfdp->lpstrDirectory)
00414                                 sei.lpDirectory = prfdp->lpstrDirectory;
00415                             else
00416                                 sei.lpDirectory = parent = RunDlg_GetParentDir(sei.lpFile);
00417 
00418                             if (!ShellExecuteExW( &sei ))
00419                             {
00420                                 HeapFree(GetProcessHeap(), 0, psz);
00421                                 HeapFree(GetProcessHeap(), 0, parent);
00422                                 SendMessageA (htxt, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
00423                                 return TRUE ;
00424                             }
00425 
00426                             /* FillList is still ANSI */
00427                             GetWindowTextA (htxt, (LPSTR)psz, ic + 1) ;
00428                             FillList (htxt, (LPSTR)psz, FALSE) ;
00429 
00430                             HeapFree(GetProcessHeap(), 0, psz);
00431                             HeapFree(GetProcessHeap(), 0, parent);
00432                             EndDialog (hwnd, 0);
00433                         }
00434                     }
00435                 }
00436 
00437                 case IDCANCEL :
00438                     EndDialog (hwnd, 0) ;
00439                     return TRUE ;
00440 
00441                 case IDC_RUNDLG_BROWSE :
00442                     {
00443                     HMODULE hComdlg = NULL ;
00444                     LPFNOFN ofnProc = NULL ;
00445                     static const WCHAR comdlg32W[] = L"comdlg32";
00446                     WCHAR szFName[1024] = {0};
00447                     WCHAR filter[MAX_PATH], szCaption[MAX_PATH];
00448                     OPENFILENAMEW ofn;
00449 
00450                     LoadStringW(shell32_hInstance, IDS_RUNDLG_BROWSE_FILTER, filter, MAX_PATH);
00451                     LoadStringW(shell32_hInstance, IDS_RUNDLG_BROWSE_CAPTION, szCaption, MAX_PATH);
00452 
00453                     ZeroMemory(&ofn, sizeof(ofn));
00454                     ofn.lStructSize = sizeof(OPENFILENAMEW);
00455                     ofn.hwndOwner = hwnd;
00456                     ofn.lpstrFilter = filter;
00457                     ofn.lpstrFile = szFName;
00458                     ofn.nMaxFile = 1023;
00459                     ofn.lpstrTitle = szCaption;
00460                     ofn.Flags = OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
00461                     ofn.lpstrInitialDir = prfdp->lpstrDirectory;
00462 
00463                     if (NULL == (hComdlg = LoadLibraryExW (comdlg32W, NULL, 0)) ||
00464                         NULL == (ofnProc = (LPFNOFN)GetProcAddress (hComdlg, "GetOpenFileNameW")))
00465                     {
00466                         ERR("Couldn't get GetOpenFileName function entry (lib=%p, proc=%p)\n", hComdlg, ofnProc);
00467                         ShellMessageBoxW(shell32_hInstance, hwnd, MAKEINTRESOURCEW(IDS_RUNDLG_BROWSE_ERROR), NULL, MB_OK | MB_ICONERROR);
00468                         return TRUE ;
00469                     }
00470 
00471                     if (ofnProc(&ofn))
00472                     {
00473                         SetFocus (GetDlgItem (hwnd, IDOK)) ;
00474                         SetWindowTextW (GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH), szFName) ;
00475                         SendMessageW (GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH), CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
00476                         SetFocus (GetDlgItem (hwnd, IDOK)) ;
00477                     }
00478 
00479                     FreeLibrary (hComdlg) ;
00480 
00481                     return TRUE ;
00482                     }
00483                 }
00484             return TRUE ;
00485         }
00486     return FALSE ;
00487     }
00488 
00489 /* This grabs the MRU list from the registry and fills the combo for the "Run" dialog above */
00490 /* fShowDefault ignored if pszLatest != NULL */
00491 static void FillList(HWND hCb, char *pszLatest, BOOL fShowDefault)
00492 {
00493     HKEY hkey ;
00494 /*    char szDbgMsg[256] = "" ; */
00495     char *pszList = NULL, *pszCmd = NULL, cMatch = 0, cMax = 0x60, szIndex[2] = "-" ;
00496     DWORD icList = 0, icCmd = 0 ;
00497     UINT Nix ;
00498 
00499     SendMessageA (hCb, CB_RESETCONTENT, 0, 0) ;
00500 
00501     if (ERROR_SUCCESS != RegCreateKeyExA (
00502         HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU",
00503         0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL))
00504         MessageBoxA (hCb, "Unable to open registry key !", "Nix", MB_OK) ;
00505 
00506     RegQueryValueExA (hkey, "MRUList", NULL, NULL, NULL, &icList) ;
00507 
00508     if (icList > 0)
00509     {
00510         pszList = (char *)HeapAlloc( GetProcessHeap(), 0, icList) ;
00511 
00512         if (pszList)
00513         {
00514             if (ERROR_SUCCESS != RegQueryValueExA (hkey, "MRUList", NULL, NULL, (LPBYTE)pszList, &icList))
00515                 MessageBoxA (hCb, "Unable to grab MRUList !", "Nix", MB_OK);
00516         }
00517         else
00518         {
00519             TRACE("HeapAlloc failed to allocate %d bytes\n", icList);
00520         }
00521     }
00522     else
00523     {
00524         icList = 1 ;
00525         pszList = (char *)HeapAlloc( GetProcessHeap(), 0, icList) ;
00526         pszList[0] = 0 ;
00527     }
00528 
00529     for (Nix = 0 ; Nix < icList - 1 ; Nix++)
00530     {
00531         if (pszList[Nix] > cMax)
00532             cMax = pszList[Nix] ;
00533 
00534         szIndex[0] = pszList[Nix] ;
00535 
00536         if (ERROR_SUCCESS != RegQueryValueExA (hkey, szIndex, NULL, NULL, NULL, &icCmd))
00537             MessageBoxA (hCb, "Unable to grab size of index", "Nix", MB_OK) ;
00538         if( pszCmd )
00539             pszCmd = (char *)HeapReAlloc(GetProcessHeap(), 0, pszCmd, icCmd) ;
00540         else
00541             pszCmd = (char *)HeapAlloc(GetProcessHeap(), 0, icCmd) ;
00542         if (ERROR_SUCCESS != RegQueryValueExA (hkey, szIndex, NULL, NULL, (LPBYTE)pszCmd, &icCmd))
00543             MessageBoxA (hCb, "Unable to grab index", "Nix", MB_OK) ;
00544 
00545         if (NULL != pszLatest)
00546         {
00547             if (!lstrcmpiA(pszCmd, pszLatest))
00548             {
00549                 /*
00550                 sprintf (szDbgMsg, "Found existing (%d).\n", Nix) ;
00551                 MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
00552                 */
00553                 SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszCmd) ;
00554                 SetWindowTextA (hCb, pszCmd) ;
00555                 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
00556 
00557                 cMatch = pszList[Nix] ;
00558                 memmove (&pszList[1], pszList, Nix) ;
00559                 pszList[0] = cMatch ;
00560                 continue ;
00561             }
00562         }
00563 
00564         if (26 != icList - 1 || icList - 2 != Nix || cMatch || NULL == pszLatest)
00565         {
00566             /*
00567             sprintf (szDbgMsg, "Happily appending (%d).\n", Nix) ;
00568             MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
00569             */
00570             SendMessageA (hCb, CB_ADDSTRING, 0, (LPARAM)pszCmd) ;
00571             if (!Nix && fShowDefault)
00572             {
00573                 SetWindowTextA (hCb, pszCmd) ;
00574                 SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
00575             }
00576         }
00577         else
00578         {
00579             /*
00580             sprintf (szDbgMsg, "Doing loop thing.\n") ;
00581             MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
00582             */
00583             SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszLatest) ;
00584             SetWindowTextA (hCb, pszLatest) ;
00585             SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
00586 
00587             cMatch = pszList[Nix] ;
00588             memmove (&pszList[1], pszList, Nix) ;
00589             pszList[0] = cMatch ;
00590             szIndex[0] = cMatch ;
00591             RegSetValueExA (hkey, szIndex, 0, REG_SZ, (LPBYTE)pszLatest, strlen (pszLatest) + 1) ;
00592         }
00593     }
00594 
00595     if (!cMatch && NULL != pszLatest)
00596     {
00597         /*
00598         sprintf (szDbgMsg, "Simply inserting (increasing list).\n") ;
00599         MessageBoxA (hCb, szDbgMsg, "Nix", MB_OK) ;
00600         */
00601         SendMessageA (hCb, CB_INSERTSTRING, 0, (LPARAM)pszLatest) ;
00602         SetWindowTextA (hCb, pszLatest) ;
00603         SendMessageA (hCb, CB_SETEDITSEL, 0, MAKELPARAM (0, -1)) ;
00604 
00605         cMatch = ++cMax ;
00606         if (pszList)
00607             pszList = (char *)HeapReAlloc(GetProcessHeap(), 0, pszList, ++icList) ;
00608         else
00609             pszList = (char *)HeapAlloc(GetProcessHeap(), 0, ++icList) ;
00610 
00611         if (pszList)
00612         {
00613             memmove (&pszList[1], pszList, icList - 1) ;
00614             pszList[0] = cMatch ;
00615             szIndex[0] = cMatch ;
00616             RegSetValueExA (hkey, szIndex, 0, REG_SZ, (LPBYTE)pszLatest, strlen (pszLatest) + 1) ;
00617         }
00618         else
00619         {
00620             TRACE("HeapAlloc or HeapReAlloc failed to allocate enough bytes\n");
00621         }
00622     }
00623 
00624     RegSetValueExA (hkey, "MRUList", 0, REG_SZ, (LPBYTE)pszList, strlen (pszList) + 1) ;
00625 
00626     HeapFree( GetProcessHeap(), 0, pszCmd) ;
00627     HeapFree( GetProcessHeap(), 0, pszList) ;
00628 }
00629 
00630 
00631 /*************************************************************************
00632  * ConfirmDialog                [internal]
00633  *
00634  * Put up a confirm box, return TRUE if the user confirmed
00635  */
00636 static BOOL ConfirmDialog(HWND hWndOwner, UINT PromptId, UINT TitleId)
00637 {
00638   WCHAR Prompt[256];
00639   WCHAR Title[256];
00640 
00641   LoadStringW(shell32_hInstance, PromptId, Prompt, sizeof(Prompt) / sizeof(WCHAR));
00642   LoadStringW(shell32_hInstance, TitleId, Title, sizeof(Title) / sizeof(WCHAR));
00643   return MessageBoxW(hWndOwner, Prompt, Title, MB_YESNO|MB_ICONQUESTION) == IDYES;
00644 }
00645 
00646 
00647 /*************************************************************************
00648  * RestartDialogEx                [SHELL32.730]
00649  */
00650 
00651 int WINAPI RestartDialogEx(HWND hWndOwner, LPCWSTR lpwstrReason, DWORD uFlags, DWORD uReason)
00652 {
00653     TRACE("(%p)\n", hWndOwner);
00654 
00655     /* FIXME: use lpwstrReason */
00656     if (ConfirmDialog(hWndOwner, IDS_RESTART_PROMPT, IDS_RESTART_TITLE))
00657     {
00658         HANDLE hToken;
00659         TOKEN_PRIVILEGES npr;
00660 
00661         /* enable the shutdown privilege for the current process */
00662         if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
00663         {
00664             LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
00665             npr.PrivilegeCount = 1;
00666             npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
00667             AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
00668             CloseHandle(hToken);
00669         }
00670         ExitWindowsEx(EWX_REBOOT, uReason);
00671     }
00672 
00673     return 0;
00674 }
00675 
00676 
00677 /*************************************************************************
00678  * LogoffWindowsDialog  [SHELL32.54]
00679  */
00680 
00681 EXTERN_C int WINAPI LogoffWindowsDialog(HWND hWndOwner)
00682 {
00683     if (ConfirmDialog(hWndOwner, IDS_LOGOFF_PROMPT, IDS_LOGOFF_TITLE))
00684         ExitWindowsEx(EWX_LOGOFF, 0);
00685 
00686     return 0;
00687 }
00688 
00689 
00690 /*************************************************************************
00691  * RestartDialog                [SHELL32.59]
00692  */
00693 
00694 int WINAPI RestartDialog(HWND hWndOwner, LPCWSTR lpstrReason, DWORD uFlags)
00695 {
00696     return RestartDialogEx(hWndOwner, lpstrReason, uFlags, 0);
00697 }
00698 
00699 
00700 /*************************************************************************
00701  * ExitWindowsDialog                [SHELL32.60]
00702  *
00703  * NOTES
00704  *     exported by ordinal
00705  */
00706 void WINAPI ExitWindowsDialog(HWND hWndOwner)
00707 {
00708     TRACE("(%p)\n", hWndOwner);
00709 
00710     if (ConfirmDialog(hWndOwner, IDS_SHUTDOWN_PROMPT, IDS_SHUTDOWN_TITLE))
00711     {
00712         HANDLE hToken;
00713         TOKEN_PRIVILEGES npr;
00714 
00715         /* enable shutdown privilege for current process */
00716         if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
00717         {
00718             LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
00719             npr.PrivilegeCount = 1;
00720             npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
00721             AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
00722             CloseHandle(hToken);
00723         }
00724         ExitWindowsEx(EWX_SHUTDOWN, 0);
00725     }
00726 }

Generated on Sat May 26 2012 04:24:54 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.