Back to index

lightning-sunbird  0.9+nobinonly
dialogs.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Sean Su <ssu@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "extern.h"
00041 #include "extra.h"
00042 #include "dialogs.h"
00043 #include "ifuncns.h"
00044 #include "parser.h"
00045 #include "rdi.h"
00046 #include "shlobj.h"
00047 
00048 #define MOZ_HWND_BROADCAST_MSG_TIMEOUT 5000
00049 #define MOZ_CLIENT_BROWSER_KEY         "Software\\Clients\\StartMenuInternet"
00050 #define MOZ_CLIENT_MAIL_KEY            "Software\\Clients\\Mail"
00051 
00052 void SetDefault()
00053 {
00054   char szBuf[MAX_BUF];
00055   char szRegKey[MAX_BUF];
00056 
00057   GetPrivateProfileString(ugUninstall.szDefaultComponent, "ClientTypeName", "", szBuf, MAX_BUF, szFileIniDefaultsInfo);
00058   wsprintf(szRegKey, "SOFTWARE\\Clients\\%s", szBuf);
00059   GetPrivateProfileString(ugUninstall.szDefaultComponent, "ClientProductKey", "", szBuf, MAX_BUF, szFileIniDefaultsInfo);
00060 
00061   SetWinReg(HKEY_LOCAL_MACHINE, szRegKey, "", REG_SZ, szBuf, lstrlen(szBuf));
00062 }
00063 
00064 void ParseDefaultsInfo()
00065 {
00066   char szBuf[MAX_BUF];
00067   char szIniKey[MAX_BUF];
00068   char szStorageDir[MAX_BUF];
00069   char szShortcutPath[MAX_BUF];
00070   char szStoredShortcutPath[MAX_BUF];
00071   char szRegKey[MAX_BUF];
00072   char szClientTypeName[MAX_BUF];
00073   char szClientProductKey[MAX_BUF];
00074   int  iIndex;
00075   DWORD dwIconsVisible;
00076 
00077   // If szAppPath is a null string, i.e. we cannot find where the app has been installed:
00078   //   - HIDEICONS will still remove the shortcuts but
00079   //   - SHOWICONS will do nothing because we won't be able to find the shortcuts to display.
00080   ParsePath(ugUninstall.szAppPath, szStorageDir, MAX_BUF, PP_PATH_ONLY);
00081   lstrcat(szStorageDir, "defaults\\shortcuts\\");
00082 
00083   // CLEANUP ISSUE:  For all of the SHOWICON and HIDEICONS blocks below, there is a lot of
00084   //   redundancy:
00085   //   - Right now I'm just trying to create icons and, if I can't, trying under the PERSONAL
00086   //     key instead.  I would be cleaner to check for restricted access once, and then just
00087   //     create the appropriate key each time.
00088   //   - Creating a ShowIcon() and a HideIcon() function would rid us much of the redundency.
00089 
00090 
00091   // Deal with Desktop Icons
00092   iIndex = 0;
00093   wsprintf(szIniKey, "DesktopShortcut%d", iIndex);
00094   GetPrivateProfileString(ugUninstall.szDefaultComponent, szIniKey, "", szBuf, MAX_BUF, szFileIniDefaultsInfo);
00095   while(szBuf[0] != '\0')
00096   {
00097     strcpy(szShortcutPath, "COMMON_DESKTOP");
00098     DecryptVariable(szShortcutPath, MAX_BUF);
00099 
00100     if((ugUninstall.mode == SHOWICONS) && (szStorageDir[0] != '\0'))
00101     {
00102       wsprintf(szStoredShortcutPath, "%s%s", szStorageDir, szBuf);
00103       FileCopy(szStoredShortcutPath, szShortcutPath, 0);
00104       if( (!FileExists(szShortcutPath)) && (!(ulOSType & OS_WIN9x)) )
00105       {
00106         strcpy(szShortcutPath, "PERSONAL_DESKTOP");
00107         DecryptVariable(szShortcutPath, MAX_BUF);
00108         FileCopy(szStoredShortcutPath, szShortcutPath, 0);
00109       }
00110     }
00111 
00112     if (ugUninstall.mode == HIDEICONS)
00113     {
00114       AppendBackSlash(szShortcutPath, MAX_BUF);
00115       lstrcat(szShortcutPath, szBuf);
00116       if( (!FileExists(szShortcutPath)) && (!(ulOSType & OS_WIN9x)) )
00117       {
00118         strcpy(szShortcutPath, "PERSONAL_DESKTOP");
00119         DecryptVariable(szShortcutPath, MAX_BUF);
00120         AppendBackSlash(szShortcutPath, MAX_BUF);
00121         lstrcat(szShortcutPath, szBuf);
00122       }
00123 
00124       FileDelete(szShortcutPath);
00125     }
00126 
00127     iIndex++;
00128     wsprintf(szIniKey, "DesktopShortcut%d", iIndex);
00129     GetPrivateProfileString(ugUninstall.szDefaultComponent, szIniKey, "", szBuf, MAX_BUF, szFileIniDefaultsInfo);
00130   }
00131 
00132   // Deal with StartMenu Icons
00133   iIndex = 0;
00134   wsprintf(szIniKey, "StartMenuShortcut%d", iIndex);
00135   GetPrivateProfileString(ugUninstall.szDefaultComponent, szIniKey, "", szBuf, MAX_BUF, szFileIniDefaultsInfo);
00136   while(szBuf[0] != '\0')
00137   {
00138     strcpy(szShortcutPath, "COMMON_STARTMENU");
00139     DecryptVariable(szShortcutPath, MAX_BUF);
00140 
00141     if((ugUninstall.mode == SHOWICONS) && (szStorageDir[0] != '\0'))
00142     {
00143       lstrcpy(szStoredShortcutPath, szStorageDir);
00144       lstrcat(szStoredShortcutPath, szBuf);
00145       FileCopy(szStoredShortcutPath, szShortcutPath, 0);
00146       if( (!FileExists(szShortcutPath)) && (!(ulOSType & OS_WIN9x)) )
00147       {
00148         strcpy(szShortcutPath, "PERSONAL_STARTMENU");
00149         DecryptVariable(szShortcutPath, MAX_BUF);
00150         FileCopy(szStoredShortcutPath, szShortcutPath, 0);
00151       }
00152     }
00153 
00154     if (ugUninstall.mode == HIDEICONS)
00155     {
00156       AppendBackSlash(szShortcutPath, MAX_BUF);
00157       lstrcat(szShortcutPath, szBuf);
00158       if( (!FileExists(szShortcutPath)) && (!(ulOSType & OS_WIN9x)) )
00159       {
00160         strcpy(szShortcutPath, "PERSONAL_STARTMENU");
00161         DecryptVariable(szShortcutPath, MAX_BUF);
00162         AppendBackSlash(szShortcutPath, MAX_BUF);
00163         lstrcat(szShortcutPath, szBuf);
00164       }
00165 
00166       FileDelete(szShortcutPath);
00167     }
00168 
00169     iIndex++;
00170     wsprintf(szIniKey, "StartMenuShortcut%d", iIndex);
00171     GetPrivateProfileString(ugUninstall.szDefaultComponent, szIniKey, "", szBuf, MAX_BUF, szFileIniDefaultsInfo);
00172   }
00173 
00174   // Deal with QuickLaunch Bar Icons
00175   iIndex = 0;
00176   wsprintf(szIniKey, "QuickLaunchBarShortcut%d", iIndex);
00177   GetPrivateProfileString(ugUninstall.szDefaultComponent, szIniKey, "", szBuf, MAX_BUF, szFileIniDefaultsInfo);
00178   while(szBuf[0] != '\0')
00179   {
00180     GetWinReg(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData", szShortcutPath, MAX_BUF);
00181     lstrcat(szShortcutPath, "\\Microsoft\\Internet Explorer\\Quick Launch");
00182 
00183     if((ugUninstall.mode == SHOWICONS) && (szStorageDir[0] != '\0'))
00184     {
00185       wsprintf(szStoredShortcutPath, "%s%s", szStorageDir, szBuf);
00186       FileCopy(szStoredShortcutPath, szShortcutPath, 0);
00187       if( (!FileExists(szShortcutPath)) && (!(ulOSType & OS_WIN9x)) )
00188       {
00189         GetWinReg(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GrpConv\\MapGroups", "Quick Launch", szShortcutPath, MAX_BUF);
00190         FileCopy(szStoredShortcutPath, szShortcutPath, 0);
00191       }
00192     }
00193 
00194     if (ugUninstall.mode == HIDEICONS)
00195     {
00196       AppendBackSlash(szShortcutPath, MAX_BUF);
00197       lstrcat(szShortcutPath, szBuf);
00198       if( (!FileExists(szShortcutPath)) && (!(ulOSType & OS_WIN9x)) )
00199       {
00200         GetWinReg(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GrpConv\\MapGroups", "Quick Launch", szShortcutPath, MAX_BUF);
00201         AppendBackSlash(szShortcutPath, MAX_BUF);
00202         lstrcat(szShortcutPath, szBuf);
00203       }
00204 
00205       FileDelete(szShortcutPath);
00206     }
00207 
00208     ++iIndex;
00209     wsprintf(szIniKey, "QuickLaunchBarShortcut%d", iIndex);
00210     GetPrivateProfileString(ugUninstall.szDefaultComponent, szIniKey, "", szBuf, MAX_BUF, szFileIniDefaultsInfo);
00211   }
00212 
00213   GetPrivateProfileString(ugUninstall.szDefaultComponent, "ClientTypeName", "", szClientTypeName, MAX_BUF, szFileIniDefaultsInfo);
00214   GetPrivateProfileString(ugUninstall.szDefaultComponent, "ClientProductKey", "", szClientProductKey, MAX_BUF, szFileIniDefaultsInfo);
00215   wsprintf(szRegKey, "SOFTWARE\\Clients\\%s\\%s\\InstallInfo", szClientTypeName, szClientProductKey);
00216 
00217   if (ugUninstall.mode == SHOWICONS)
00218     dwIconsVisible = 1;
00219   else
00220     dwIconsVisible = 0;
00221 
00222   SetWinRegNumValue(HKEY_LOCAL_MACHINE, szRegKey, "IconsVisible", dwIconsVisible);
00223 }
00224 
00225 void ParseAllUninstallLogs()
00226 {
00227   char  szFileInstallLog[MAX_BUF];
00228   char  szKey[MAX_BUF];
00229   sil   *silFile;
00230   DWORD dwFileFound;
00231   DWORD dwRv = 0;
00232 
00233   UndoDesktopIntegration();
00234   CleanupMailIntegration();
00235   dwFileFound = GetLogFile(ugUninstall.szLogPath, ugUninstall.szLogFilename, szFileInstallLog, sizeof(szFileInstallLog));
00236   while(dwFileFound)
00237   {
00238     if((silFile = InitSilNodes(szFileInstallLog)) != NULL)
00239     {
00240       FileDelete(szFileInstallLog);
00241       dwRv = Uninstall(silFile);
00242       DeInitSilNodes(&silFile);
00243       if(dwRv == WTD_CANCEL)
00244         break;
00245     }
00246 
00247     dwFileFound = GetLogFile(ugUninstall.szLogPath, ugUninstall.szLogFilename, szFileInstallLog, sizeof(szFileInstallLog));
00248   }
00249 
00250   if(dwRv != WTD_CANCEL)
00251   {
00252     lstrcpy(szFileInstallLog, ugUninstall.szLogPath);
00253     AppendBackSlash(szFileInstallLog, MAX_BUF);
00254     lstrcat(szFileInstallLog, ugUninstall.szLogFilename);
00255     if(FileExists(szFileInstallLog))
00256     {
00257       if((silFile = InitSilNodes(szFileInstallLog)) != NULL)
00258       {
00259         FileDelete(szFileInstallLog);
00260         Uninstall(silFile);
00261         DeInitSilNodes(&silFile);
00262       }
00263     }
00264 
00265     /* clean up the uninstall windows registry key */
00266     lstrcpy(szKey, "Software\\Microsoft\\Windows\\CurrentVersion\\uninstall\\");
00267     lstrcat(szKey, ugUninstall.szUninstallKeyDescription);
00268     RegDeleteKey(HKEY_LOCAL_MACHINE, szKey);
00269 
00270     // Calling SHChangeNotify() will update the file association icons
00271     // in case they had been reset.
00272     SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
00273 
00274     // Note completion of the uninstall process.
00275     gbUninstallCompleted = TRUE;
00276   }
00277 
00278   /* Broadcast message only if the windows registry keys exist
00279    * in case they were changed during uninstallation.  If they
00280    * were, then the broadcast will alert the OS to update the appropriate UIs.
00281    * This needs to be done regardless if the user canceled the uninstall
00282    * process or not.
00283    */
00284   if(WinRegKeyExists(HKEY_LOCAL_MACHINE, MOZ_CLIENT_BROWSER_KEY))
00285   {
00286     SendMessageTimeout(HWND_BROADCAST,
00287                        WM_SETTINGCHANGE,
00288                        0,
00289                        (LPARAM)MOZ_CLIENT_BROWSER_KEY,
00290                        SMTO_NORMAL|SMTO_ABORTIFHUNG,
00291                        MOZ_HWND_BROADCAST_MSG_TIMEOUT,
00292                        NULL);
00293   }
00294   if(WinRegKeyExists(HKEY_LOCAL_MACHINE, MOZ_CLIENT_MAIL_KEY))
00295   {
00296     SendMessageTimeout(HWND_BROADCAST,
00297                        WM_SETTINGCHANGE,
00298                        0,
00299                        (LPARAM)MOZ_CLIENT_MAIL_KEY,
00300                        SMTO_NORMAL|SMTO_ABORTIFHUNG,
00301                        MOZ_HWND_BROADCAST_MSG_TIMEOUT,
00302                        NULL);
00303   }
00304 }
00305 
00306 LRESULT CALLBACK DlgProcUninstall(HWND hDlg, UINT msg, WPARAM wParam, LONG lParam)
00307 {
00308   char  szBuf[MAX_BUF];
00309   RECT  rDlg;
00310 
00311   switch(msg)
00312   {
00313     case WM_INITDIALOG:
00314       SetWindowText(hDlg, diUninstall.szTitle);
00315       wsprintf(szBuf, diUninstall.szMessage0, ugUninstall.szDescription);
00316       SetDlgItemText(hDlg, IDC_MESSAGE0, szBuf);
00317       GetPrivateProfileString("Dialog Uninstall", "Yes", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00318       SetDlgItemText(hDlg, IDWIZNEXT, szBuf);
00319       GetPrivateProfileString("Dialog Uninstall", "No", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00320       SetDlgItemText(hDlg, IDCANCEL, szBuf);
00321       SendDlgItemMessage (hDlg, IDC_MESSAGE0, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00322       SendDlgItemMessage (hDlg, IDWIZNEXT, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00323       SendDlgItemMessage (hDlg, IDCANCEL, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00324 
00325       if(GetClientRect(hDlg, &rDlg))
00326         SetWindowPos(hDlg, HWND_TOP, (dwScreenX/2)-(rDlg.right/2), (dwScreenY/2)-(rDlg.bottom/2), 0, 0, SWP_NOSIZE);
00327 
00328       break;
00329 
00330     case WM_COMMAND:
00331       switch(LOWORD(wParam))
00332       {
00333         case IDWIZNEXT:
00334           EnableWindow(GetDlgItem(hDlg, IDWIZNEXT), FALSE);
00335           EnableWindow(GetDlgItem(hDlg, IDCANCEL), FALSE);
00336           ParseAllUninstallLogs();
00337           // skip directory nuking for now (bug 233625) but may come back
00338           // if the issues can be resolved in a better way by bug 281235
00339           // VerifyAndDeleteInstallationFolder();
00340           DestroyWindow(hDlg);
00341           PostQuitMessage(0);
00342           break;
00343 
00344         case IDCANCEL:
00345           DestroyWindow(hDlg);
00346           PostQuitMessage(0);
00347           break;
00348 
00349         default:
00350           break;
00351       }
00352       break;
00353   }
00354   return(0);
00355 }
00356 
00357 LRESULT CALLBACK DlgProcWhatToDo(HWND hDlg, UINT msg, WPARAM wParam, LONG lParam)
00358 {
00359   char  szBuf[MAX_BUF];
00360   RECT  rDlg;
00361 
00362   switch(msg)
00363   {
00364     case WM_INITDIALOG:
00365       GetPrivateProfileString("Messages", "DLG_REMOVE_FILE_TITLE", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00366       SetWindowText(hDlg, szBuf);
00367 
00368       if((LPSTR)lParam != NULL)
00369         SetDlgItemText(hDlg, IDC_STATIC_SHARED_FILENAME, (LPSTR)lParam);
00370 
00371       GetPrivateProfileString("Dialog Uninstall", "Message1", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00372       SetDlgItemText(hDlg, IDC_MESSAGE0, szBuf);
00373       GetPrivateProfileString("Dialog Uninstall", "Message2", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00374       SetDlgItemText(hDlg, IDC_MESSAGE1, szBuf);
00375       GetPrivateProfileString("Dialog Uninstall", "FileName", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00376       SetDlgItemText(hDlg, IDC_STATIC, szBuf);
00377       GetPrivateProfileString("Dialog Uninstall", "No", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00378       SetDlgItemText(hDlg, ID_NO, szBuf);
00379       GetPrivateProfileString("Dialog Uninstall", "NoToAll", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00380       SetDlgItemText(hDlg, ID_NO_TO_ALL, szBuf);
00381       GetPrivateProfileString("Dialog Uninstall", "Yes", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00382       SetDlgItemText(hDlg, ID_YES, szBuf);
00383       GetPrivateProfileString("Dialog Uninstall", "YesToAll", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00384       SetDlgItemText(hDlg, ID_YES_TO_ALL, szBuf);
00385 
00386       SendDlgItemMessage (hDlg, IDC_MESSAGE0, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00387       SendDlgItemMessage (hDlg, IDC_MESSAGE1, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00388       SendDlgItemMessage (hDlg, IDC_STATIC, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00389       SendDlgItemMessage (hDlg, IDC_STATIC_SHARED_FILENAME, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00390       SendDlgItemMessage (hDlg, ID_NO, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00391       SendDlgItemMessage (hDlg, ID_NO_TO_ALL, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00392       SendDlgItemMessage (hDlg, ID_YES, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00393       SendDlgItemMessage (hDlg, ID_YES_TO_ALL, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00394 
00395       if(GetClientRect(hDlg, &rDlg))
00396         SetWindowPos(hDlg, HWND_TOP, (dwScreenX/2)-(rDlg.right/2), (dwScreenY/2)-(rDlg.bottom/2), 0, 0, SWP_NOSIZE);
00397 
00398       break;
00399 
00400     case WM_COMMAND:
00401       switch(LOWORD(wParam))
00402       {
00403         case ID_NO:
00404           EndDialog(hDlg, WTD_NO);
00405           break;
00406 
00407         case ID_NO_TO_ALL:
00408           EndDialog(hDlg, WTD_NO_TO_ALL);
00409           break;
00410 
00411         case ID_YES:
00412           EndDialog(hDlg, WTD_YES);
00413           break;
00414 
00415         case ID_YES_TO_ALL:
00416           EndDialog(hDlg, WTD_YES_TO_ALL);
00417           break;
00418 
00419         default:
00420           break;
00421       }
00422       break;
00423   }
00424   return(0);
00425 }
00426 
00427 LRESULT CALLBACK DlgProcMessage(HWND hDlg, UINT msg, WPARAM wParam, LONG lParam)
00428 {
00429   RECT      rDlg;
00430   HWND      hSTMessage = GetDlgItem(hDlg, IDC_MESSAGE); /* handle to the Static Text message window */
00431   HDC       hdcSTMessage;
00432   SIZE      sizeString;
00433   LOGFONT   logFont;
00434   HFONT     hfontTmp;
00435   HFONT     hfontOld;
00436   int       i;
00437 
00438   switch(msg)
00439   {
00440     case WM_INITDIALOG:
00441           SendDlgItemMessage (hDlg, IDC_MESSAGE, WM_SETFONT, (WPARAM)ugUninstall.definedFont, 0L); 
00442       break;
00443 
00444     case WM_COMMAND:
00445       switch(LOWORD(wParam))
00446       {
00447         case IDC_MESSAGE:
00448           hdcSTMessage = GetWindowDC(hSTMessage);
00449 
00450           SystemParametersInfo(SPI_GETICONTITLELOGFONT,
00451                                sizeof(logFont),
00452                                (PVOID)&logFont,
00453                                0);
00454           hfontTmp = CreateFontIndirect(&logFont);
00455 
00456           if(hfontTmp)
00457             hfontOld = SelectObject(hdcSTMessage, hfontTmp);
00458 
00459           GetTextExtentPoint32(hdcSTMessage, (LPSTR)lParam, lstrlen((LPSTR)lParam), &sizeString);
00460           SelectObject(hdcSTMessage, hfontOld);
00461           DeleteObject(hfontTmp);
00462           ReleaseDC(hSTMessage, hdcSTMessage);
00463 
00464           SetWindowPos(hDlg, HWND_TOP,
00465                       (dwScreenX/2)-((sizeString.cx + 40)/2), (dwScreenY/2)-((sizeString.cy + 40)/2),
00466                       sizeString.cx + 40, sizeString.cy + 40,
00467                       SWP_SHOWWINDOW);
00468 
00469           if(GetClientRect(hDlg, &rDlg))
00470             SetWindowPos(hSTMessage,
00471                          HWND_TOP,
00472                          rDlg.left,
00473                          rDlg.top,
00474                          rDlg.right,
00475                          rDlg.bottom,
00476                          SWP_SHOWWINDOW);
00477 
00478           for(i = 0; i < lstrlen((LPSTR)lParam); i++)
00479           {
00480             if((((LPSTR)lParam)[i] == '\r') || (((LPSTR)lParam)[i] == '\n')) 
00481               ((LPSTR)lParam)[i] = ' ';
00482           }
00483 
00484           SetDlgItemText(hDlg, IDC_MESSAGE, (LPSTR)lParam);
00485           break;
00486       }
00487       break;
00488   }
00489   return(0);
00490 }
00491 
00492 // This dialog proc must be used in conjunction with DLG_MESSAGE_CHK.
00493 LRESULT CALLBACK DlgProcComplete(HWND hDlg, UINT msg, WPARAM wParam, LONG lParam)
00494 {
00495   RECT rDlg;
00496   char text[256];
00497   LRESULT result = 0;
00498 
00499   switch(msg)
00500   {
00501     case WM_INITDIALOG:
00502       SetWindowText(hDlg, diUninstall.szTitle);
00503 
00504       GetPrivateProfileString("Dialog Uninstall", "OK", "",
00505                               text, sizeof(text), szFileIniUninstall);
00506       SetDlgItemText(hDlg, IDOK, text);
00507 
00508       GetPrivateProfileString("Messages", "MSG_UNINSTALL_COMPLETE", "",
00509                               text, sizeof(text), szFileIniUninstall);
00510       SetDlgItemText(hDlg, IDC_MESSAGE, text);
00511 
00512       GetPrivateProfileString("Messages", "MSG_UNINSTALL_SURVEY", "",
00513                               text, sizeof(text), szFileIniUninstall);
00514       if (text[0]) 
00515       {
00516         SetDlgItemText(hDlg, IDC_CHECKBOX, text);
00517       }
00518       else
00519       {
00520         // Hide the checkbox control if there is not survey text.
00521         ShowWindow(GetDlgItem(hDlg, IDC_CHECKBOX), SW_HIDE);
00522       }
00523 
00524       if(GetClientRect(hDlg, &rDlg))
00525         SetWindowPos(hDlg, HWND_TOP, (dwScreenX/2)-(rDlg.right/2), (dwScreenY/2)-(rDlg.bottom/2), 0, 0, SWP_NOSIZE);
00526 
00527       break;
00528 
00529     case WM_COMMAND:
00530       switch(LOWORD(wParam))
00531       {
00532         case IDOK:
00533           if (SendDlgItemMessage(hDlg, IDC_CHECKBOX, BM_GETCHECK, 0, 0) == BST_CHECKED)
00534           {
00535             EndDialog(hDlg, ID_YES_TO_ALL);
00536           }
00537           else 
00538           {
00539             EndDialog(hDlg, IDOK);
00540           }            
00541           break;
00542       }
00543       break;
00544 
00545     case WM_CLOSE:
00546       EndDialog(hDlg, IDOK);
00547       break;
00548   }
00549   return(0);
00550 }
00551 
00552 void ProcessWindowsMessages()
00553 {
00554   MSG msg;
00555 
00556   while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
00557   {
00558     TranslateMessage(&msg);
00559     DispatchMessage(&msg);
00560   }
00561 }
00562 
00563 void ShowMessage(LPSTR szMessage, BOOL bShow)
00564 {
00565   char szBuf[MAX_BUF];
00566 
00567   if(ugUninstall.mode != SILENT)
00568   {
00569     if((bShow) && (hDlgMessage == NULL))
00570     {
00571       ZeroMemory(szBuf, sizeof(szBuf));
00572       GetPrivateProfileString("Messages", "MB_MESSAGE_STR", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00573       hDlgMessage = InstantiateDialog(hWndMain, DLG_MESSAGE, szBuf, DlgProcMessage);
00574       SendMessage(hDlgMessage, WM_COMMAND, IDC_MESSAGE, (LPARAM)szMessage);
00575     }
00576     else if(!bShow && hDlgMessage)
00577     {
00578       DestroyWindow(hDlgMessage);
00579       hDlgMessage = NULL;
00580     }
00581   }
00582 }
00583 
00584 HWND InstantiateDialog(HWND hParent, DWORD dwDlgID, LPSTR szTitle, WNDPROC wpDlgProc)
00585 {
00586   char szBuf[MAX_BUF];
00587   HWND hDlg = NULL;
00588 
00589   if((hDlg = CreateDialog(hInst, MAKEINTRESOURCE(dwDlgID), hParent, wpDlgProc)) == NULL)
00590   {
00591     char szEDialogCreate[MAX_BUF];
00592 
00593     if(GetPrivateProfileString("Messages", "ERROR_DIALOG_CREATE", "", szEDialogCreate, sizeof(szEDialogCreate), szFileIniUninstall))
00594     {
00595       wsprintf(szBuf, szEDialogCreate, szTitle);
00596       PrintError(szBuf, ERROR_CODE_SHOW);
00597     }
00598 
00599     PostQuitMessage(1);
00600   }
00601 
00602   return(hDlg);
00603 }