Dialogs.c
上传用户:tj_dwf
上传日期:2020-11-17
资源大小:215k
文件大小:60k
源码类别:

RichEdit

开发平台:

Visual C++

  1. /******************************************************************************
  2. *
  3. *
  4. * Notepad2
  5. *
  6. * Dialogs.c
  7. *   Notepad2 dialog boxes implementation
  8. *
  9. * See Readme.txt for more information about this source code.
  10. * Please send me your comments to this work.
  11. *
  12. * See License.txt for details about distribution and modification.
  13. *
  14. *                                              (c) Florian Balmer 1996-2010
  15. *                                                  florian.balmer@gmail.com
  16. *                                               http://www.flos-freeware.ch
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _WIN32_WINNT 0x501
  21. #include <windows.h>
  22. #include <commctrl.h>
  23. #include <shlobj.h>
  24. #include <shellapi.h>
  25. #include <shlwapi.h>
  26. #include <commdlg.h>
  27. #include <string.h>
  28. #include "notepad2.h"
  29. #include "scintilla.h"
  30. #include "edit.h"
  31. #include "helpers.h"
  32. #include "dlapi.h"
  33. #include "dialogs.h"
  34. #include "resource.h"
  35. extern HWND  hwndMain;
  36. extern HWND  hwndEdit;
  37. extern HINSTANCE g_hInstance;
  38. extern LPMALLOC  g_lpMalloc;
  39. extern DWORD dwLastIOError;
  40. extern BOOL bSkipUnicodeDetection;
  41. extern BOOL bLoadASCIIasUTF8;
  42. extern int fNoFileVariables;
  43. extern BOOL bNoEncodingTags;
  44. extern BOOL bFixLineEndings;
  45. extern BOOL bAutoStripBlanks;
  46. extern WCHAR szCurFile[MAX_PATH+40];
  47. //=============================================================================
  48. //
  49. //  MsgBox()
  50. //
  51. int MsgBox(int iType,UINT uIdMsg,...)
  52. {
  53.   WCHAR szText [1024];
  54.   WCHAR szBuf  [1024];
  55.   WCHAR szTitle[64];
  56.   int iIcon = 0;
  57.   HWND hwnd;
  58.   if (!GetString(uIdMsg,szBuf,COUNTOF(szBuf)))
  59.     return(0);
  60.   wvsprintf(szText,szBuf,(LPVOID)((PUINT_PTR)&uIdMsg + 1));
  61.   if (uIdMsg == IDS_ERR_LOADFILE || uIdMsg == IDS_ERR_SAVEFILE ||
  62.       uIdMsg == IDS_CREATEINI_FAIL || uIdMsg == IDS_WRITEINI_FAIL) {
  63.     LPVOID lpMsgBuf;
  64.     WCHAR wcht;
  65.     FormatMessage(
  66.       FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
  67.       NULL,
  68.       dwLastIOError,
  69.       MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
  70.       (LPTSTR)&lpMsgBuf,
  71.       0,
  72.       NULL);
  73.     StrTrim(lpMsgBuf,L" abfnrtv");
  74.     StrCatBuff(szText,L"n",COUNTOF(szText));
  75.     StrCatBuff(szText,lpMsgBuf,COUNTOF(szText));
  76.     LocalFree(lpMsgBuf);
  77.     wcht = *CharPrev(szText,StrEnd(szText));
  78.     if (IsCharAlphaNumeric(wcht) || wcht == '"' || wcht == ''')
  79.       StrCatBuff(szText,L".",COUNTOF(szText));
  80.   }
  81.   GetString(IDS_APPTITLE,szTitle,COUNTOF(szTitle));
  82.   switch (iType) {
  83.     case MBINFO: iIcon = MB_ICONEXCLAMATION; break;
  84.     case MBWARN: iIcon = MB_ICONEXCLAMATION; break;
  85.     case MBYESNO: iIcon = MB_ICONEXCLAMATION | MB_YESNO; break;
  86.     case MBYESNOCANCEL: iIcon = MB_ICONEXCLAMATION | MB_YESNOCANCEL; break;
  87.     case MBYESNOWARN: iIcon = MB_ICONEXCLAMATION | MB_YESNO; break;
  88.     case MBOKCANCEL: iIcon = MB_ICONEXCLAMATION | MB_OKCANCEL; break;
  89.   }
  90.   if (!(hwnd = GetFocus()))
  91.     hwnd = hwndMain;
  92.   return MessageBoxEx(hwnd,
  93.            szText,szTitle,
  94.            MB_SETFOREGROUND | iIcon,
  95.            MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT));
  96. }
  97. //=============================================================================
  98. //
  99. //  DisplayCmdLineHelp()
  100. //
  101. void DisplayCmdLineHelp()
  102. {
  103.   MSGBOXPARAMS mbp;
  104.   WCHAR szTitle[32];
  105.   WCHAR szText[2048];
  106.   GetString(IDS_APPTITLE,szTitle,COUNTOF(szTitle));
  107.   GetString(IDS_CMDLINEHELP,szText,COUNTOF(szText));
  108.   mbp.cbSize = sizeof(MSGBOXPARAMS);
  109.   mbp.hwndOwner = NULL;
  110.   mbp.hInstance = g_hInstance;
  111.   mbp.lpszText = szText;
  112.   mbp.lpszCaption = szTitle;
  113.   mbp.dwStyle = MB_OK | MB_USERICON | MB_SETFOREGROUND;
  114.   mbp.lpszIcon = MAKEINTRESOURCE(IDR_MAINWND);
  115.   mbp.dwContextHelpId = 0;
  116.   mbp.lpfnMsgBoxCallback = NULL;
  117.   mbp.dwLanguageId = MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL);
  118.   MessageBoxIndirect(&mbp);
  119. }
  120. //=============================================================================
  121. //
  122. //  BFFCallBack()
  123. //
  124. int CALLBACK BFFCallBack(HWND hwnd,UINT umsg,LPARAM lParam,LPARAM lpData)
  125. {
  126.   if (umsg == BFFM_INITIALIZED)
  127.     SendMessage(hwnd,BFFM_SETSELECTION,TRUE,lpData);
  128.   return(0);
  129.   lParam;
  130. }
  131. //=============================================================================
  132. //
  133. //  GetDirectory()
  134. //
  135. BOOL GetDirectory(HWND hwndParent,int iTitle,LPWSTR pszFolder,LPCWSTR pszBase,BOOL bNewDialogStyle)
  136. {
  137.   BROWSEINFO bi;
  138.   LPITEMIDLIST pidl;
  139.   //LPMALLOC lpMalloc;
  140.   WCHAR szTitle[256];
  141.   WCHAR szBase[MAX_PATH];
  142.   BOOL fOk = FALSE;
  143.   lstrcpy(szTitle,L"");
  144.   GetString(iTitle,szTitle,COUNTOF(szTitle));
  145.   if (!pszBase || !*pszBase)
  146.     GetCurrentDirectory(MAX_PATH,szBase);
  147.   else
  148.     lstrcpy(szBase,pszBase);
  149.   bi.hwndOwner = hwndParent;
  150.   bi.pidlRoot = NULL;
  151.   bi.pszDisplayName = pszFolder;
  152.   bi.lpszTitle = szTitle;
  153.   bi.ulFlags = BIF_RETURNONLYFSDIRS;
  154.   if (bNewDialogStyle)
  155.     bi.ulFlags |= BIF_NEWDIALOGSTYLE;
  156.   bi.lpfn = &BFFCallBack;
  157.   bi.lParam = (LPARAM)szBase;
  158.   bi.iImage = 0;
  159.   //if (SHGetMalloc(&lpMalloc) != NOERROR)
  160.   //   return FALSE;
  161.   pidl = SHBrowseForFolder(&bi);
  162.   if (pidl)
  163.   {
  164.     SHGetPathFromIDList(pidl,pszFolder);
  165.     g_lpMalloc->lpVtbl->Free(g_lpMalloc,pidl);
  166.     fOk = TRUE;
  167.   }
  168.   //lpMalloc->lpVtbl->Release(lpMalloc);
  169.   return fOk;
  170. }
  171. //=============================================================================
  172. //
  173. //  AboutDlgProc()
  174. //
  175. static const DWORD  dwVerMajor    = 4;
  176. static const DWORD  dwVerMinor    = 1;
  177. static const DWORD  dwBuildNumber = 24;
  178. static const WCHAR* szRevision    = L"";
  179. static const WCHAR* szExtra       = L"";
  180. static const BOOL   bReleaseBuild = TRUE;
  181. BOOL CALLBACK AboutDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  182. {
  183.   static HFONT hFontTitle;
  184.   switch(umsg)
  185.   {
  186.     case WM_INITDIALOG:
  187.       {
  188.         WCHAR  szVersion[64];
  189.         WCHAR  szDate[64];
  190.         WCHAR  szLink[256];
  191.         WCHAR  szLinkCode[256];
  192.         LOGFONT lf;
  193.         if (bReleaseBuild) {
  194.           wsprintf(szVersion,L"Notepad2 %u.%u.%0.2u%s",
  195.             dwVerMajor,dwVerMinor,dwBuildNumber,szRevision);
  196.           SetDlgItemText(hwnd,IDC_VERSION,szVersion);
  197.         }
  198.         else {
  199.           MultiByteToWideChar(CP_ACP,0,__DATE__,-1,szDate,COUNTOF(szDate));
  200.           wsprintf(szVersion,L"Notepad2 %u.%u.%0.2u%s%s %s",
  201.             dwVerMajor,dwVerMinor,dwBuildNumber,szRevision,szExtra,szDate);
  202.           SetDlgItemText(hwnd,IDC_VERSION,szVersion);
  203.         }
  204.         if (hFontTitle)
  205.           DeleteObject(hFontTitle);
  206.         if (NULL == (hFontTitle = (HFONT)SendDlgItemMessage(hwnd,IDC_VERSION,WM_GETFONT,0,0)))
  207.           hFontTitle = GetStockObject(DEFAULT_GUI_FONT);
  208.         GetObject(hFontTitle,sizeof(LOGFONT),&lf);
  209.         lf.lfWeight = FW_BOLD;
  210.         hFontTitle = CreateFontIndirect(&lf);
  211.         SendDlgItemMessage(hwnd,IDC_VERSION,WM_SETFONT,(WPARAM)hFontTitle,TRUE);
  212.         if (GetDlgItem(hwnd,IDC_WEBPAGE) == NULL)
  213.           ShowWindow(GetDlgItem(hwnd,IDC_WEBPAGE2),SW_SHOWNORMAL);
  214.         else {
  215.           GetDlgItemText(hwnd,IDC_WEBPAGE2,szLink,COUNTOF(szLink));
  216.           wsprintf(szLinkCode,L"<A>%s</A>",szLink);
  217.           SetDlgItemText(hwnd,IDC_WEBPAGE,szLinkCode);
  218.         }
  219.         if (GetDlgItem(hwnd,IDC_EMAIL) == NULL)
  220.           ShowWindow(GetDlgItem(hwnd,IDC_EMAIL2),SW_SHOWNORMAL);
  221.         else {
  222.           GetDlgItemText(hwnd,IDC_EMAIL2,szLink,COUNTOF(szLink));
  223.           wsprintf(szLinkCode,L"<A>%s</A>",szLink);
  224.           SetDlgItemText(hwnd,IDC_EMAIL,szLinkCode);
  225.         }
  226.         CenterDlgInParent(hwnd);
  227.       }
  228.       return TRUE;
  229.     case WM_NOTIFY:
  230.       {
  231.         LPNMHDR pnmhdr = (LPNMHDR)lParam;
  232.         switch (pnmhdr->code) {
  233.           case NM_CLICK:
  234.           case NM_RETURN:
  235.             {
  236.               if (pnmhdr->idFrom == IDC_WEBPAGE) {
  237.                 ShellExecute(hwnd,L"open",L"http://www.flos-freeware.ch",NULL,NULL,SW_SHOWNORMAL);
  238.               }
  239.               else if (pnmhdr->idFrom == IDC_EMAIL) {
  240.                 ShellExecute(hwnd,L"open",L"mailto:florian.balmer@gmail.com",NULL,NULL,SW_SHOWNORMAL);
  241.               }
  242.             }
  243.             break;
  244.         }
  245.       }
  246.       break;
  247.     case WM_COMMAND:
  248.       switch(LOWORD(wParam))
  249.       {
  250.         case IDOK:
  251.         case IDCANCEL:
  252.           EndDialog(hwnd,IDOK);
  253.           break;
  254.       }
  255.       return TRUE;
  256.   }
  257.   return FALSE;
  258. }
  259. //=============================================================================
  260. //
  261. //  RunDlgProc()
  262. //
  263. BOOL CALLBACK RunDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  264. {
  265.   switch(umsg)
  266.   {
  267.     case WM_INITDIALOG:
  268.       {
  269.         MakeBitmapButton(hwnd,IDC_SEARCHEXE,g_hInstance,IDB_OPEN);
  270.         SendDlgItemMessage(hwnd,IDC_COMMANDLINE,EM_LIMITTEXT,MAX_PATH - 1,0);
  271.         SetDlgItemText(hwnd,IDC_COMMANDLINE,(LPCWSTR)lParam);
  272.         SHAutoComplete(GetDlgItem(hwnd,IDC_COMMANDLINE),SHACF_FILESYSTEM);
  273.         CenterDlgInParent(hwnd);
  274.       }
  275.       return TRUE;
  276.     case WM_DESTROY:
  277.       DeleteBitmapButton(hwnd,IDC_SEARCHEXE);
  278.       return FALSE;
  279.     case WM_COMMAND:
  280.       switch(LOWORD(wParam))
  281.       {
  282.         case IDC_SEARCHEXE:
  283.           {
  284.             WCHAR szArgs[MAX_PATH];
  285.             WCHAR szArg2[MAX_PATH];
  286.             WCHAR szFile[MAX_PATH * 2];
  287.             WCHAR szFilter[256];
  288.             OPENFILENAME ofn;
  289.             ZeroMemory(&ofn,sizeof(OPENFILENAME));
  290.             GetDlgItemText(hwnd,IDC_COMMANDLINE,szArgs,COUNTOF(szArgs));
  291.             ExpandEnvironmentStringsEx(szArgs,COUNTOF(szArgs));
  292.             ExtractFirstArgument(szArgs,szFile,szArg2);
  293.             GetString(IDS_FILTER_EXE,szFilter,COUNTOF(szFilter));
  294.             PrepareFilterStr(szFilter);
  295.             ofn.lStructSize = sizeof(OPENFILENAME);
  296.             ofn.hwndOwner = hwnd;
  297.             ofn.lpstrFilter = szFilter;
  298.             ofn.lpstrFile = szFile;
  299.             ofn.nMaxFile = COUNTOF(szFile);
  300.             ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT
  301.                       | OFN_PATHMUSTEXIST | OFN_SHAREAWARE | OFN_NODEREFERENCELINKS;
  302.             if (GetOpenFileName(&ofn)) {
  303.               PathQuoteSpaces(szFile);
  304.               if (lstrlen(szArg2))
  305.               {
  306.                 lstrcat(szFile,L" ");
  307.                 lstrcat(szFile,szArg2);
  308.               }
  309.               SetDlgItemText(hwnd,IDC_COMMANDLINE,szFile);
  310.             }
  311.             PostMessage(hwnd,WM_NEXTDLGCTL,1,0);
  312.           }
  313.           break;
  314.         case IDC_COMMANDLINE:
  315.           {
  316.             BOOL bEnableOK = FALSE;
  317.             WCHAR args[MAX_PATH];
  318.             if (GetDlgItemText(hwnd,IDC_COMMANDLINE,args,MAX_PATH))
  319.               if (ExtractFirstArgument(args,args,NULL))
  320.                 if (lstrlen(args))
  321.                   bEnableOK = TRUE;
  322.             EnableWindow(GetDlgItem(hwnd,IDOK),bEnableOK);
  323.           }
  324.           break;
  325.         case IDOK:
  326.           {
  327.             WCHAR arg1[MAX_PATH];
  328.             WCHAR arg2[MAX_PATH];
  329.             SHELLEXECUTEINFO sei;
  330.             WCHAR wchDirectory[MAX_PATH] = L"";
  331.             if (GetDlgItemText(hwnd,IDC_COMMANDLINE,arg1,MAX_PATH))
  332.             {
  333.               BOOL bQuickExit = FALSE;
  334.               ExpandEnvironmentStringsEx(arg1,COUNTOF(arg1));
  335.               ExtractFirstArgument(arg1,arg1,arg2);
  336.               if (lstrcmpi(arg1,L"notepad2") == 0 ||
  337.                   lstrcmpi(arg1,L"notepad2.exe") == 0) {
  338.                 GetModuleFileName(NULL,arg1,COUNTOF(arg1));
  339.                 bQuickExit = TRUE;
  340.               }
  341.               if (lstrlen(szCurFile)) {
  342.                 lstrcpy(wchDirectory,szCurFile);
  343.                 PathRemoveFileSpec(wchDirectory);
  344.               }
  345.               ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO));
  346.               sei.cbSize = sizeof(SHELLEXECUTEINFO);
  347.               sei.fMask = 0;
  348.               sei.hwnd = hwnd;
  349.               sei.lpVerb = NULL;
  350.               sei.lpFile = arg1;
  351.               sei.lpParameters = arg2;
  352.               sei.lpDirectory = wchDirectory;
  353.               sei.nShow = SW_SHOWNORMAL;
  354.               if (bQuickExit) {
  355.                 sei.fMask |= /*SEE_MASK_NOZONECHECKS*/0x00800000;
  356.                 EndDialog(hwnd,IDOK);
  357.                 ShellExecuteEx(&sei);
  358.               }
  359.               else {
  360.                 if (ShellExecuteEx(&sei))
  361.                   EndDialog(hwnd,IDOK);
  362.                 else
  363.                   PostMessage(hwnd,WM_NEXTDLGCTL,
  364.                     (WPARAM)(GetDlgItem(hwnd,IDC_COMMANDLINE)),1);
  365.               }
  366.             }
  367.           }
  368.           break;
  369.         case IDCANCEL:
  370.           EndDialog(hwnd,IDCANCEL);
  371.           break;
  372.       }
  373.       return TRUE;
  374.   }
  375.   return FALSE;
  376. }
  377. //=============================================================================
  378. //
  379. //  RunDlg()
  380. //
  381. void RunDlg(HWND hwnd,LPCWSTR lpstrDefault)
  382. {
  383.   ThemedDialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_RUN),
  384.     hwnd,RunDlgProc,(LPARAM)lpstrDefault);
  385. }
  386. //=============================================================================
  387. //
  388. //  OpenWithDlgProc()
  389. //
  390. extern WCHAR tchOpenWithDir[MAX_PATH];
  391. extern int  flagNoFadeHidden;
  392. extern int cxOpenWithDlg;
  393. extern int cyOpenWithDlg;
  394. BOOL CALLBACK OpenWithDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  395. {
  396.   switch(umsg)
  397.   {
  398.     case WM_INITDIALOG:
  399.       {
  400.         LVCOLUMN lvc = { LVCF_FMT|LVCF_TEXT, LVCFMT_LEFT, 0, L"", -1, 0, 0, 0 };
  401.         ResizeDlg_Init(hwnd,cxOpenWithDlg,cyOpenWithDlg,IDC_RESIZEGRIP3);
  402.         SetWindowLongPtr(hwnd,DWLP_USER,lParam);
  403.         //SetExplorerTheme(GetDlgItem(hwnd,IDC_OPENWITHDIR));
  404.         ListView_SetExtendedListViewStyle(GetDlgItem(hwnd,IDC_OPENWITHDIR),/*LVS_EX_FULLROWSELECT|*/LVS_EX_DOUBLEBUFFER|LVS_EX_LABELTIP);
  405.         ListView_InsertColumn(GetDlgItem(hwnd,IDC_OPENWITHDIR),0,&lvc);
  406.         DirList_Init(GetDlgItem(hwnd,IDC_OPENWITHDIR),NULL);
  407.         DirList_Fill(GetDlgItem(hwnd,IDC_OPENWITHDIR),tchOpenWithDir,DL_ALLOBJECTS,NULL,FALSE,flagNoFadeHidden,DS_NAME,FALSE);
  408.         DirList_StartIconThread(GetDlgItem(hwnd,IDC_OPENWITHDIR));
  409.         ListView_SetItemState(GetDlgItem(hwnd,IDC_OPENWITHDIR),0,LVIS_FOCUSED,LVIS_FOCUSED);
  410.         MakeBitmapButton(hwnd,IDC_GETOPENWITHDIR,g_hInstance,IDB_OPEN);
  411.         CenterDlgInParent(hwnd);
  412.       }
  413.       return TRUE;
  414.     case WM_DESTROY:
  415.       DirList_Destroy(GetDlgItem(hwnd,IDC_OPENWITHDIR));
  416.       DeleteBitmapButton(hwnd,IDC_GETOPENWITHDIR);
  417.       ResizeDlg_Destroy(hwnd,&cxOpenWithDlg,&cyOpenWithDlg);
  418.       return FALSE;
  419.     case WM_SIZE:
  420.       {
  421.         int dx;
  422.         int dy;
  423.         HDWP hdwp;
  424.         ResizeDlg_Size(hwnd,lParam,&dx,&dy);
  425.         hdwp = BeginDeferWindowPos(6);
  426.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_RESIZEGRIP3,dx,dy,SWP_NOSIZE);
  427.         hdwp = DeferCtlPos(hdwp,hwnd,IDOK,dx,dy,SWP_NOSIZE);
  428.         hdwp = DeferCtlPos(hdwp,hwnd,IDCANCEL,dx,dy,SWP_NOSIZE);
  429.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_OPENWITHDIR,dx,dy,SWP_NOMOVE);
  430.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_GETOPENWITHDIR,0,dy,SWP_NOSIZE);
  431.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_OPENWITHDESCR,0,dy,SWP_NOSIZE);
  432.         EndDeferWindowPos(hdwp);
  433.         ListView_SetColumnWidth(GetDlgItem(hwnd,IDC_OPENWITHDIR),0,LVSCW_AUTOSIZE_USEHEADER);
  434.       }
  435.       return TRUE;
  436.     case WM_GETMINMAXINFO:
  437.       ResizeDlg_GetMinMaxInfo(hwnd,lParam);
  438.       return TRUE;
  439.     case WM_NOTIFY:
  440.       {
  441.         LPNMHDR pnmh = (LPNMHDR)lParam;
  442.         if (pnmh->idFrom == IDC_OPENWITHDIR)
  443.         {
  444.           switch(pnmh->code)
  445.           {
  446.             case LVN_GETDISPINFO:
  447.               DirList_GetDispInfo(GetDlgItem(hwnd,IDC_OPENWITHDIR),lParam,flagNoFadeHidden);
  448.               break;
  449.             case LVN_DELETEITEM:
  450.               DirList_DeleteItem(GetDlgItem(hwnd,IDC_OPENWITHDIR),lParam);
  451.               break;
  452.             case LVN_ITEMCHANGED: {
  453.                 NM_LISTVIEW *pnmlv = (NM_LISTVIEW*)lParam;
  454.                 EnableWindow(GetDlgItem(hwnd,IDOK),(pnmlv->uNewState & LVIS_SELECTED));
  455.               }
  456.               break;
  457.             case NM_DBLCLK:
  458.               if (ListView_GetSelectedCount(GetDlgItem(hwnd,IDC_OPENWITHDIR)))
  459.                 SendMessage(hwnd,WM_COMMAND,MAKELONG(IDOK,1),0);
  460.               break;
  461.           }
  462.         }
  463.       }
  464.       return TRUE;
  465.     case WM_COMMAND:
  466.       switch(LOWORD(wParam))
  467.       {
  468.         case IDC_GETOPENWITHDIR:
  469.           {
  470.             if (GetDirectory(hwnd,IDS_OPENWITH,tchOpenWithDir,tchOpenWithDir,TRUE))
  471.             {
  472.               DirList_Fill(GetDlgItem(hwnd,IDC_OPENWITHDIR),tchOpenWithDir,DL_ALLOBJECTS,NULL,FALSE,flagNoFadeHidden,DS_NAME,FALSE);
  473.               DirList_StartIconThread(GetDlgItem(hwnd,IDC_OPENWITHDIR));
  474.               ListView_EnsureVisible(GetDlgItem(hwnd,IDC_OPENWITHDIR),0,FALSE);
  475.               ListView_SetItemState(GetDlgItem(hwnd,IDC_OPENWITHDIR),0,LVIS_FOCUSED,LVIS_FOCUSED);
  476.             }
  477.             PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_OPENWITHDIR)),1);
  478.           }
  479.           break;
  480.         case IDOK: {
  481.             LPDLITEM lpdli = (LPDLITEM)GetWindowLongPtr(hwnd,DWLP_USER);
  482.             lpdli->mask = DLI_FILENAME | DLI_TYPE;
  483.             lpdli->ntype = DLE_NONE;
  484.             DirList_GetItem(GetDlgItem(hwnd,IDC_OPENWITHDIR),(-1),lpdli);
  485.             if (lpdli->ntype != DLE_NONE)
  486.               EndDialog(hwnd,IDOK);
  487.             else
  488.               MessageBeep(0);
  489.           }
  490.           break;
  491.         case IDCANCEL:
  492.           EndDialog(hwnd,IDCANCEL);
  493.           break;
  494.       }
  495.       return TRUE;
  496.   }
  497.   return FALSE;
  498. }
  499. //=============================================================================
  500. //
  501. //  OpenWithDlg()
  502. //
  503. BOOL OpenWithDlg(HWND hwnd,LPCWSTR lpstrFile)
  504. {
  505.   DLITEM dliOpenWith;
  506.   dliOpenWith.mask = DLI_FILENAME;
  507.   if (IDOK == ThemedDialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_OPENWITH),
  508.                              hwnd,OpenWithDlgProc,(LPARAM)&dliOpenWith))
  509.   {
  510.     SHELLEXECUTEINFO sei;
  511.     WCHAR szParam[MAX_PATH];
  512.     WCHAR wchDirectory[MAX_PATH] = L"";
  513.     if (lstrlen(szCurFile)) {
  514.       lstrcpy(wchDirectory,szCurFile);
  515.       PathRemoveFileSpec(wchDirectory);
  516.     }
  517.     ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO));
  518.     sei.cbSize = sizeof(SHELLEXECUTEINFO);
  519.     sei.fMask = 0;
  520.     sei.hwnd = hwnd;
  521.     sei.lpVerb = NULL;
  522.     sei.lpFile = dliOpenWith.szFileName;
  523.     sei.lpParameters = szParam;
  524.     sei.lpDirectory = wchDirectory;
  525.     sei.nShow = SW_SHOWNORMAL;
  526.     // resolve links and get short path name
  527.     if (!(PathIsLnkFile(lpstrFile) && PathGetLnkPath(lpstrFile,szParam,COUNTOF(szParam))))
  528.       lstrcpy(szParam,lpstrFile);
  529.     //GetShortPathName(szParam,szParam,sizeof(WCHAR)*COUNTOF(szParam));
  530.     PathQuoteSpaces(szParam);
  531.     ShellExecuteEx(&sei);
  532.     return(TRUE);
  533.   }
  534.   return(FALSE);
  535. }
  536. //=============================================================================
  537. //
  538. //  FavoritesDlgProc()
  539. //
  540. extern WCHAR tchFavoritesDir[MAX_PATH];
  541. //extern int  flagNoFadeHidden;
  542. extern int cxFavoritesDlg;
  543. extern int cyFavoritesDlg;
  544. BOOL CALLBACK FavoritesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  545. {
  546.   static HWND hwndLV;
  547.   switch(umsg)
  548.   {
  549.     case WM_INITDIALOG:
  550.       {
  551.         LVCOLUMN lvc = { LVCF_FMT|LVCF_TEXT, LVCFMT_LEFT, 0, L"", -1, 0, 0, 0 };
  552.         ResizeDlg_Init(hwnd,cxFavoritesDlg,cyFavoritesDlg,IDC_RESIZEGRIP3);
  553.         SetWindowLongPtr(hwnd,DWLP_USER,lParam);
  554.         //SetExplorerTheme(GetDlgItem(hwnd,IDC_FAVORITESDIR));
  555.         ListView_SetExtendedListViewStyle(GetDlgItem(hwnd,IDC_FAVORITESDIR),/*LVS_EX_FULLROWSELECT|*/LVS_EX_DOUBLEBUFFER|LVS_EX_LABELTIP);
  556.         ListView_InsertColumn(GetDlgItem(hwnd,IDC_FAVORITESDIR),0,&lvc);
  557.         DirList_Init(GetDlgItem(hwnd,IDC_FAVORITESDIR),NULL);
  558.         DirList_Fill(GetDlgItem(hwnd,IDC_FAVORITESDIR),tchFavoritesDir,DL_ALLOBJECTS,NULL,FALSE,flagNoFadeHidden,DS_NAME,FALSE);
  559.         DirList_StartIconThread(GetDlgItem(hwnd,IDC_FAVORITESDIR));
  560.         ListView_SetItemState(GetDlgItem(hwnd,IDC_FAVORITESDIR),0,LVIS_FOCUSED,LVIS_FOCUSED);
  561.         MakeBitmapButton(hwnd,IDC_GETFAVORITESDIR,g_hInstance,IDB_OPEN);
  562.         CenterDlgInParent(hwnd);
  563.       }
  564.       return TRUE;
  565.     case WM_DESTROY:
  566.       DirList_Destroy(GetDlgItem(hwnd,IDC_FAVORITESDIR));
  567.       DeleteBitmapButton(hwnd,IDC_GETFAVORITESDIR);
  568.       ResizeDlg_Destroy(hwnd,&cxFavoritesDlg,&cyFavoritesDlg);
  569.       return FALSE;
  570.     case WM_SIZE:
  571.       {
  572.         int dx;
  573.         int dy;
  574.         HDWP hdwp;
  575.         ResizeDlg_Size(hwnd,lParam,&dx,&dy);
  576.         hdwp = BeginDeferWindowPos(6);
  577.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_RESIZEGRIP3,dx,dy,SWP_NOSIZE);
  578.         hdwp = DeferCtlPos(hdwp,hwnd,IDOK,dx,dy,SWP_NOSIZE);
  579.         hdwp = DeferCtlPos(hdwp,hwnd,IDCANCEL,dx,dy,SWP_NOSIZE);
  580.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_FAVORITESDIR,dx,dy,SWP_NOMOVE);
  581.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_GETFAVORITESDIR,0,dy,SWP_NOSIZE);
  582.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_FAVORITESDESCR,0,dy,SWP_NOSIZE);
  583.         EndDeferWindowPos(hdwp);
  584.         ListView_SetColumnWidth(GetDlgItem(hwnd,IDC_FAVORITESDIR),0,LVSCW_AUTOSIZE_USEHEADER);
  585.       }
  586.       return TRUE;
  587.     case WM_GETMINMAXINFO:
  588.       ResizeDlg_GetMinMaxInfo(hwnd,lParam);
  589.       return TRUE;
  590.     case WM_NOTIFY:
  591.       {
  592.         LPNMHDR pnmh = (LPNMHDR)lParam;
  593.         if (pnmh->idFrom == IDC_FAVORITESDIR)
  594.         {
  595.           switch(pnmh->code)
  596.           {
  597.             case LVN_GETDISPINFO:
  598.               DirList_GetDispInfo(GetDlgItem(hwnd,IDC_OPENWITHDIR),lParam,flagNoFadeHidden);
  599.               break;
  600.             case LVN_DELETEITEM:
  601.               DirList_DeleteItem(GetDlgItem(hwnd,IDC_FAVORITESDIR),lParam);
  602.               break;
  603.             case LVN_ITEMCHANGED: {
  604.                 NM_LISTVIEW *pnmlv = (NM_LISTVIEW*)lParam;
  605.                 EnableWindow(GetDlgItem(hwnd,IDOK),(pnmlv->uNewState & LVIS_SELECTED));
  606.               }
  607.               break;
  608.             case NM_DBLCLK:
  609.               if (ListView_GetSelectedCount(GetDlgItem(hwnd,IDC_FAVORITESDIR)))
  610.                 SendMessage(hwnd,WM_COMMAND,MAKELONG(IDOK,1),0);
  611.               break;
  612.           }
  613.         }
  614.       }
  615.       return TRUE;
  616.     case WM_COMMAND:
  617.       switch(LOWORD(wParam))
  618.       {
  619.         case IDC_GETFAVORITESDIR:
  620.           {
  621.             if (GetDirectory(hwnd,IDS_FAVORITES,tchFavoritesDir,tchFavoritesDir,TRUE))
  622.             {
  623.               DirList_Fill(GetDlgItem(hwnd,IDC_FAVORITESDIR),tchFavoritesDir,DL_ALLOBJECTS,NULL,FALSE,flagNoFadeHidden,DS_NAME,FALSE);
  624.               DirList_StartIconThread(GetDlgItem(hwnd,IDC_FAVORITESDIR));
  625.               ListView_EnsureVisible(GetDlgItem(hwnd,IDC_FAVORITESDIR),0,FALSE);
  626.               ListView_SetItemState(GetDlgItem(hwnd,IDC_FAVORITESDIR),0,LVIS_FOCUSED,LVIS_FOCUSED);
  627.             }
  628.             PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_FAVORITESDIR)),1);
  629.           }
  630.           break;
  631.         case IDOK: {
  632.             LPDLITEM lpdli = (LPDLITEM)GetWindowLongPtr(hwnd,DWLP_USER);
  633.             lpdli->mask = DLI_FILENAME | DLI_TYPE;
  634.             lpdli->ntype = DLE_NONE;
  635.             DirList_GetItem(GetDlgItem(hwnd,IDC_FAVORITESDIR),(-1),lpdli);
  636.             if (lpdli->ntype != DLE_NONE)
  637.               EndDialog(hwnd,IDOK);
  638.             else
  639.               MessageBeep(0);
  640.           }
  641.           break;
  642.         case IDCANCEL:
  643.           EndDialog(hwnd,IDCANCEL);
  644.           break;
  645.       }
  646.       return TRUE;
  647.   }
  648.   return FALSE;
  649. }
  650. //=============================================================================
  651. //
  652. //  FavoritesDlg()
  653. //
  654. BOOL FavoritesDlg(HWND hwnd,LPWSTR lpstrFile)
  655. {
  656.   DLITEM dliFavorite;
  657.   dliFavorite.mask = DLI_FILENAME;
  658.   if (IDOK == ThemedDialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_FAVORITES),
  659.                              hwnd,FavoritesDlgProc,(LPARAM)&dliFavorite))
  660.   {
  661.     lstrcpyn(lpstrFile,dliFavorite.szFileName,MAX_PATH);
  662.     return(TRUE);
  663.   }
  664.   return(FALSE);
  665. }
  666. //=============================================================================
  667. //
  668. //  AddToFavDlgProc()
  669. //
  670. //  Controls: 100 Edit
  671. //
  672. BOOL CALLBACK AddToFavDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  673. {
  674.   switch(umsg)
  675.   {
  676.     WCHAR *pszName;
  677.     case WM_INITDIALOG:
  678.       pszName = (LPWSTR)lParam;
  679.       SetWindowLongPtr(hwnd,DWLP_USER,(LONG_PTR)pszName);
  680.       SendDlgItemMessage(hwnd,100,EM_LIMITTEXT,MAX_PATH-1,0);
  681.       SetDlgItemText(hwnd,100,pszName);
  682.       CenterDlgInParent(hwnd);
  683.       return TRUE;
  684.     case WM_COMMAND:
  685.       switch(LOWORD(wParam))
  686.       {
  687.         case 100:
  688.             EnableWindow(GetDlgItem(hwnd,IDOK),
  689.               GetWindowTextLength(GetDlgItem(hwnd,100)));
  690.           break;
  691.         case IDOK:
  692.           pszName = (LPWSTR)GetWindowLongPtr(hwnd,DWLP_USER);
  693.           GetDlgItemText(hwnd,100,pszName,
  694.             MAX_PATH-1);
  695.           EndDialog(hwnd,IDOK);
  696.           break;
  697.         case IDCANCEL:
  698.           EndDialog(hwnd,IDCANCEL);
  699.           break;
  700.       }
  701.       return TRUE;
  702.   }
  703.   return FALSE;
  704. }
  705. //=============================================================================
  706. //
  707. //  AddToFavDlg()
  708. //
  709. BOOL AddToFavDlg(HWND hwnd,LPCWSTR lpszName,LPCWSTR lpszTarget)
  710. {
  711.   int iResult;
  712.   WCHAR pszName[MAX_PATH];
  713.   lstrcpy(pszName,lpszName);
  714.   iResult = ThemedDialogBoxParam(
  715.               g_hInstance,
  716.               MAKEINTRESOURCE(IDD_ADDTOFAV),
  717.               hwnd,
  718.               AddToFavDlgProc,(LPARAM)pszName);
  719.   if (iResult == IDOK)
  720.   {
  721.     if (!PathCreateFavLnk(pszName,lpszTarget,tchFavoritesDir)) {
  722.       MsgBox(MBWARN,IDS_FAV_FAILURE);
  723.       return FALSE;
  724.     }
  725.     else {
  726.       MsgBox(MBINFO,IDS_FAV_SUCCESS);
  727.       return TRUE;
  728.     }
  729.   }
  730.   else
  731.     return FALSE;
  732. }
  733. //=============================================================================
  734. //
  735. //  FileMRUDlgProc()
  736. //
  737. //
  738. extern LPMRULIST pFileMRU;
  739. extern BOOL bSaveRecentFiles;
  740. extern int  cxFileMRUDlg;
  741. extern int  cyFileMRUDlg;
  742. extern int  flagNoFadeHidden;
  743. typedef struct tagIconThreadInfo
  744. {
  745.   HWND hwnd;                 // HWND of ListView Control
  746.   HANDLE hExitThread;        // Flag is set when Icon Thread should terminate
  747.   HANDLE hTerminatedThread;  // Flag is set when Icon Thread has terminated
  748. } ICONTHREADINFO, *LPICONTHREADINFO;
  749. DWORD WINAPI FileMRUIconThread(LPVOID lpParam) {
  750.   HWND hwnd;
  751.   LPICONTHREADINFO lpit;
  752.   LV_ITEM lvi;
  753.   WCHAR tch[MAX_PATH];
  754.   SHFILEINFO shfi;
  755.   DWORD dwFlags = SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED;
  756.   DWORD dwAttr  = 0;
  757.   int iItem = 0;
  758.   int iMaxItem;
  759.   lpit = (LPICONTHREADINFO)lpParam;
  760.   ResetEvent(lpit->hTerminatedThread);
  761.   hwnd = lpit->hwnd;
  762.   iMaxItem = ListView_GetItemCount(hwnd);
  763.   CoInitialize(NULL);
  764.   ZeroMemory(&lvi,sizeof(LV_ITEM));
  765.   while (iItem < iMaxItem && WaitForSingleObject(lpit->hExitThread,0) != WAIT_OBJECT_0) {
  766.     lvi.mask = LVIF_TEXT;
  767.     lvi.pszText = tch;
  768.     lvi.cchTextMax = COUNTOF(tch);
  769.     lvi.iItem = iItem;
  770.     if (ListView_GetItem(hwnd,&lvi)) {
  771.       if (PathIsUNC(tch) || !PathFileExists(tch)) {
  772.         dwFlags |= SHGFI_USEFILEATTRIBUTES;
  773.         dwAttr = FILE_ATTRIBUTE_NORMAL;
  774.         shfi.dwAttributes = 0;
  775.         SHGetFileInfo(PathFindFileName(tch),dwAttr,&shfi,sizeof(SHFILEINFO),dwFlags);
  776.       }
  777.       else {
  778.         shfi.dwAttributes = SFGAO_LINK | SFGAO_SHARE;
  779.         SHGetFileInfo(tch,dwAttr,&shfi,sizeof(SHFILEINFO),dwFlags);
  780.       }
  781.       lvi.mask = LVIF_IMAGE;
  782.       lvi.iImage = shfi.iIcon;
  783.       lvi.stateMask = 0;
  784.       lvi.state = 0;
  785.       if (shfi.dwAttributes & SFGAO_LINK) {
  786.         lvi.mask |= LVIF_STATE;
  787.         lvi.stateMask |= LVIS_OVERLAYMASK;
  788.         lvi.state |= INDEXTOOVERLAYMASK(2);
  789.       }
  790.       if (shfi.dwAttributes & SFGAO_SHARE) {
  791.         lvi.mask |= LVIF_STATE;
  792.         lvi.stateMask |= LVIS_OVERLAYMASK;
  793.         lvi.state |= INDEXTOOVERLAYMASK(1);
  794.       }
  795.       if (PathIsUNC(tch))
  796.         dwAttr = FILE_ATTRIBUTE_NORMAL;
  797.       else
  798.         dwAttr = GetFileAttributes(tch);
  799.       if (!flagNoFadeHidden &&
  800.           dwAttr != INVALID_FILE_ATTRIBUTES &&
  801.           dwAttr & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) {
  802.         lvi.mask |= LVIF_STATE;
  803.         lvi.stateMask |= LVIS_CUT;
  804.         lvi.state |= LVIS_CUT;
  805.       }
  806.       lvi.iSubItem = 0;
  807.       ListView_SetItem(hwnd,&lvi);
  808.     }
  809.     iItem++;
  810.   }
  811.   CoUninitialize();
  812.   SetEvent(lpit->hTerminatedThread);
  813.   ExitThread(0);
  814.   return(0);
  815. }
  816. BOOL CALLBACK FileMRUDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  817. {
  818.   switch(umsg)
  819.   {
  820.     case WM_INITDIALOG:
  821.       {
  822.         SHFILEINFO shfi;
  823.         LVCOLUMN lvc = { LVCF_FMT|LVCF_TEXT, LVCFMT_LEFT, 0, L"", -1, 0, 0, 0 };
  824.         LPICONTHREADINFO lpit = (LPVOID)GlobalAlloc(GPTR,sizeof(ICONTHREADINFO));
  825.         SetProp(hwnd,L"it",(HANDLE)lpit);
  826.         lpit->hwnd = GetDlgItem(hwnd,IDC_FILEMRU);
  827.         lpit->hExitThread = CreateEvent(NULL,TRUE,FALSE,NULL);
  828.         lpit->hTerminatedThread = CreateEvent(NULL,TRUE,TRUE,NULL);
  829.         SetWindowLongPtr(hwnd,DWLP_USER,lParam);
  830.         ResizeDlg_Init(hwnd,cxFileMRUDlg,cyFileMRUDlg,IDC_RESIZEGRIP);
  831.         ListView_SetImageList(GetDlgItem(hwnd,IDC_FILEMRU),
  832.           (HIMAGELIST)SHGetFileInfo(L"C:\",0,&shfi,sizeof(SHFILEINFO),SHGFI_SMALLICON | SHGFI_SYSICONINDEX),
  833.           LVSIL_SMALL);
  834.         ListView_SetImageList(GetDlgItem(hwnd,IDC_FILEMRU),
  835.           (HIMAGELIST)SHGetFileInfo(L"C:\",0,&shfi,sizeof(SHFILEINFO),SHGFI_LARGEICON | SHGFI_SYSICONINDEX),
  836.           LVSIL_NORMAL);
  837.         //SetExplorerTheme(GetDlgItem(hwnd,IDC_FILEMRU));
  838.         ListView_SetExtendedListViewStyle(GetDlgItem(hwnd,IDC_FILEMRU),/*LVS_EX_FULLROWSELECT|*/LVS_EX_DOUBLEBUFFER|LVS_EX_LABELTIP);
  839.         ListView_InsertColumn(GetDlgItem(hwnd,IDC_FILEMRU),0,&lvc);
  840.         // Update view
  841.         SendMessage(hwnd,WM_COMMAND,MAKELONG(0x00A0,1),0);
  842.         if (bSaveRecentFiles)
  843.           CheckDlgButton(hwnd,IDC_SAVEMRU,BST_CHECKED);
  844.         CenterDlgInParent(hwnd);
  845.       }
  846.       return TRUE;
  847.     case WM_DESTROY:
  848.       {
  849.         LPICONTHREADINFO lpit = (LPVOID)GetProp(hwnd,L"it");
  850.         SetEvent(lpit->hExitThread);
  851.         while (WaitForSingleObject(lpit->hTerminatedThread,0) != WAIT_OBJECT_0) {
  852.           MSG msg;
  853.           if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
  854.             TranslateMessage(&msg);
  855.             DispatchMessage(&msg);
  856.           }
  857.         }
  858.         CloseHandle(lpit->hExitThread);
  859.         CloseHandle(lpit->hTerminatedThread);
  860.         RemoveProp(hwnd,L"it");
  861.         GlobalFree(lpit);
  862.         bSaveRecentFiles = (IsDlgButtonChecked(hwnd,IDC_SAVEMRU)) ? 1 : 0;
  863.         ResizeDlg_Destroy(hwnd,&cxFileMRUDlg,&cyFileMRUDlg);
  864.       }
  865.       return FALSE;
  866.     case WM_SIZE:
  867.       {
  868.         int dx;
  869.         int dy;
  870.         HDWP hdwp;
  871.         ResizeDlg_Size(hwnd,lParam,&dx,&dy);
  872.         hdwp = BeginDeferWindowPos(5);
  873.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_RESIZEGRIP,dx,dy,SWP_NOSIZE);
  874.         hdwp = DeferCtlPos(hdwp,hwnd,IDOK,dx,dy,SWP_NOSIZE);
  875.         hdwp = DeferCtlPos(hdwp,hwnd,IDCANCEL,dx,dy,SWP_NOSIZE);
  876.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_FILEMRU,dx,dy,SWP_NOMOVE);
  877.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_SAVEMRU,0,dy,SWP_NOSIZE);
  878.         EndDeferWindowPos(hdwp);
  879.         ListView_SetColumnWidth(GetDlgItem(hwnd,IDC_FILEMRU),0,LVSCW_AUTOSIZE_USEHEADER);
  880.       }
  881.       return TRUE;
  882.     case WM_GETMINMAXINFO:
  883.       ResizeDlg_GetMinMaxInfo(hwnd,lParam);
  884.       return TRUE;
  885.     case WM_NOTIFY: {
  886.       if (((LPNMHDR)(lParam))->idFrom == IDC_FILEMRU) {
  887.       switch (((LPNMHDR)(lParam))->code) {
  888.         case NM_DBLCLK:
  889.           SendMessage(hwnd,WM_COMMAND,MAKELONG(IDOK,1),0);
  890.           break;
  891.         case LVN_GETDISPINFO: {
  892.             /*
  893.             LV_DISPINFO *lpdi = (LPVOID)lParam;
  894.             if (lpdi->item.mask & LVIF_IMAGE) {
  895.               WCHAR tch[MAX_PATH];
  896.               LV_ITEM lvi;
  897.               SHFILEINFO shfi;
  898.               DWORD dwFlags = SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED;
  899.               DWORD dwAttr  = 0;
  900.               ZeroMemory(&lvi,sizeof(LV_ITEM));
  901.               lvi.mask = LVIF_TEXT;
  902.               lvi.pszText = tch;
  903.               lvi.cchTextMax = COUNTOF(tch);
  904.               lvi.iItem = lpdi->item.iItem;
  905.               ListView_GetItem(GetDlgItem(hwnd,IDC_FILEMRU),&lvi);
  906.               if (!PathFileExists(tch)) {
  907.                 dwFlags |= SHGFI_USEFILEATTRIBUTES;
  908.                 dwAttr = FILE_ATTRIBUTE_NORMAL;
  909.                 shfi.dwAttributes = 0;
  910.                 SHGetFileInfo(PathFindFileName(tch),dwAttr,&shfi,sizeof(SHFILEINFO),dwFlags);
  911.               }
  912.               else {
  913.                 shfi.dwAttributes = SFGAO_LINK | SFGAO_SHARE;
  914.                 SHGetFileInfo(tch,dwAttr,&shfi,sizeof(SHFILEINFO),dwFlags);
  915.               }
  916.               lpdi->item.iImage = shfi.iIcon;
  917.               lpdi->item.mask |= LVIF_DI_SETITEM;
  918.               lpdi->item.stateMask = 0;
  919.               lpdi->item.state = 0;
  920.               if (shfi.dwAttributes & SFGAO_LINK) {
  921.                 lpdi->item.mask |= LVIF_STATE;
  922.                 lpdi->item.stateMask |= LVIS_OVERLAYMASK;
  923.                 lpdi->item.state |= INDEXTOOVERLAYMASK(2);
  924.               }
  925.               if (shfi.dwAttributes & SFGAO_SHARE) {
  926.                 lpdi->item.mask |= LVIF_STATE;
  927.                 lpdi->item.stateMask |= LVIS_OVERLAYMASK;
  928.                 lpdi->item.state |= INDEXTOOVERLAYMASK(1);
  929.               }
  930.               dwAttr = GetFileAttributes(tch);
  931.               if (!flagNoFadeHidden &&
  932.                   dwAttr != INVALID_FILE_ATTRIBUTES &&
  933.                   dwAttr & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) {
  934.                 lpdi->item.mask |= LVIF_STATE;
  935.                 lpdi->item.stateMask |= LVIS_CUT;
  936.                 lpdi->item.state |= LVIS_CUT;
  937.               }
  938.             }
  939.             */
  940.           }
  941.           break;
  942.         case LVN_ITEMCHANGED:
  943.         case LVN_DELETEITEM:
  944.             EnableWindow(GetDlgItem(hwnd,IDOK),ListView_GetSelectedCount(GetDlgItem(hwnd,IDC_FILEMRU)));
  945.             break;
  946.           }
  947.         }
  948.       }
  949.       return TRUE;
  950.     case WM_COMMAND:
  951.       switch(LOWORD(wParam))
  952.       {
  953.         case 0x00A0:
  954.           {
  955.             int i;
  956.             WCHAR tch[MAX_PATH];
  957.             LV_ITEM lvi;
  958.             SHFILEINFO shfi;
  959.             DWORD dwtid;
  960.             LPICONTHREADINFO lpit = (LPVOID)GetProp(hwnd,L"it");
  961.             SetEvent(lpit->hExitThread);
  962.             while (WaitForSingleObject(lpit->hTerminatedThread,0) != WAIT_OBJECT_0) {
  963.               MSG msg;
  964.               if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
  965.                 TranslateMessage(&msg);
  966.                 DispatchMessage(&msg);
  967.               }
  968.             }
  969.             ResetEvent(lpit->hExitThread);
  970.             SetEvent(lpit->hTerminatedThread);
  971.             ListView_DeleteAllItems(GetDlgItem(hwnd,IDC_FILEMRU));
  972.             ZeroMemory(&lvi,sizeof(LV_ITEM));
  973.             lvi.mask = LVIF_TEXT | LVIF_IMAGE;
  974.             SHGetFileInfo(L"Icon",FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(SHFILEINFO),
  975.               SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON | SHGFI_SYSICONINDEX);
  976.             lvi.iImage = shfi.iIcon;
  977.             for (i = 0; i < MRU_Enum(pFileMRU,0,NULL,0); i++) {
  978.               MRU_Enum(pFileMRU,i,tch,COUNTOF(tch));
  979.               PathAbsoluteFromApp(tch,NULL,0,TRUE);
  980.               //  SendDlgItemMessage(hwnd,IDC_FILEMRU,LB_ADDSTRING,0,(LPARAM)tch); }
  981.               //  SendDlgItemMessage(hwnd,IDC_FILEMRU,LB_SETCARETINDEX,0,FALSE);
  982.               lvi.iItem = i;
  983.               lvi.pszText = tch;
  984.               ListView_InsertItem(GetDlgItem(hwnd,IDC_FILEMRU),&lvi);
  985.             }
  986.             ListView_SetItemState(GetDlgItem(hwnd,IDC_FILEMRU),0,LVIS_FOCUSED,LVIS_FOCUSED);
  987.             ListView_SetColumnWidth(GetDlgItem(hwnd,IDC_FILEMRU),0,LVSCW_AUTOSIZE_USEHEADER);
  988.             CreateThread(NULL,0,FileMRUIconThread,(LPVOID)lpit,0,&dwtid);
  989.           }
  990.           break;
  991.         case IDC_FILEMRU:
  992.           break;
  993.         case IDOK:
  994.           {
  995.             WCHAR tch[MAX_PATH];
  996.             //int  iItem;
  997.             //if ((iItem = SendDlgItemMessage(hwnd,IDC_FILEMRU,LB_GETCURSEL,0,0)) != LB_ERR)
  998.             if (ListView_GetSelectedCount(GetDlgItem(hwnd,IDC_FILEMRU)))
  999.             {
  1000.               //SendDlgItemMessage(hwnd,IDC_FILEMRU,LB_GETTEXT,(WPARAM)iItem,(LPARAM)tch);
  1001.               LV_ITEM lvi;
  1002.               ZeroMemory(&lvi,sizeof(LV_ITEM));
  1003.               lvi.mask = LVIF_TEXT;
  1004.               lvi.pszText = tch;
  1005.               lvi.cchTextMax = COUNTOF(tch);
  1006.               lvi.iItem = ListView_GetNextItem(GetDlgItem(hwnd,IDC_FILEMRU),-1,LVNI_ALL | LVNI_SELECTED);
  1007.               ListView_GetItem(GetDlgItem(hwnd,IDC_FILEMRU),&lvi);
  1008.               PathUnquoteSpaces(tch);
  1009.               if (!PathFileExists(tch)) {
  1010.                 // Ask...
  1011.                 if (IDYES == MsgBox(MBYESNO,IDS_ERR_MRUDLG)) {
  1012.                     MRU_Delete(pFileMRU,lvi.iItem);
  1013.                     MRU_DeleteFileFromStore(pFileMRU,tch);
  1014.                     //SendDlgItemMessage(hwnd,IDC_FILEMRU,LB_DELETESTRING,(WPARAM)iItem,0);
  1015.                     //ListView_DeleteItem(GetDlgItem(hwnd,IDC_FILEMRU),lvi.iItem);
  1016.                     // must use IDM_VIEW_REFRESH, index might change...
  1017.                     SendMessage(hwnd,WM_COMMAND,MAKELONG(0x00A0,1),0);
  1018.                     //EnableWindow(GetDlgItem(hwnd,IDOK),
  1019.                     //  (LB_ERR != SendDlgItemMessage(hwnd,IDC_GOTO,LB_GETCURSEL,0,0)));
  1020.                     EnableWindow(GetDlgItem(hwnd,IDOK),
  1021.                       ListView_GetSelectedCount(GetDlgItem(hwnd,IDC_FILEMRU)));
  1022.                 }
  1023.               }
  1024.               else {
  1025.                 lstrcpy((LPWSTR)GetWindowLongPtr(hwnd,DWLP_USER),tch);
  1026.                 EndDialog(hwnd,IDOK);
  1027.               }
  1028.             }
  1029.           }
  1030.           break;
  1031.         case IDCANCEL:
  1032.           EndDialog(hwnd,IDCANCEL);
  1033.           break;
  1034.       }
  1035.       return TRUE;
  1036.   }
  1037.   return FALSE;
  1038. }
  1039. //=============================================================================
  1040. //
  1041. //  FileMRUDlg()
  1042. //
  1043. //
  1044. BOOL FileMRUDlg(HWND hwnd,LPWSTR lpstrFile)
  1045. {
  1046.   if (IDOK == ThemedDialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_FILEMRU),
  1047.                 hwnd,FileMRUDlgProc,(LPARAM)lpstrFile))
  1048.     return TRUE;
  1049.   else
  1050.     return FALSE;
  1051. }
  1052. //=============================================================================
  1053. //
  1054. //  ChangeNotifyDlgProc()
  1055. //
  1056. //  Controls: 100 Radio Button
  1057. //            101 Radio Button
  1058. //            102 Radio Button
  1059. //            103 Check Box
  1060. //
  1061. extern int iFileWatchingMode;
  1062. extern BOOL bResetFileWatching;
  1063. BOOL CALLBACK ChangeNotifyDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  1064. {
  1065.   switch(umsg)
  1066.   {
  1067.     case WM_INITDIALOG:
  1068.       CheckRadioButton(hwnd,100,102,100+iFileWatchingMode);
  1069.       if (bResetFileWatching)
  1070.         CheckDlgButton(hwnd,103,BST_CHECKED);
  1071.       CenterDlgInParent(hwnd);
  1072.       return TRUE;
  1073.     case WM_COMMAND:
  1074.       switch(LOWORD(wParam))
  1075.       {
  1076.         case IDOK:
  1077.           if (IsDlgButtonChecked(hwnd,100) == BST_CHECKED)
  1078.             iFileWatchingMode = 0;
  1079.           else if (IsDlgButtonChecked(hwnd,101) == BST_CHECKED)
  1080.             iFileWatchingMode = 1;
  1081.           else
  1082.             iFileWatchingMode = 2;
  1083.           bResetFileWatching = (IsDlgButtonChecked(hwnd,103) == BST_CHECKED) ? TRUE : FALSE;
  1084.           EndDialog(hwnd,IDOK);
  1085.           break;
  1086.         case IDCANCEL:
  1087.           EndDialog(hwnd,IDCANCEL);
  1088.           break;
  1089.       }
  1090.       return TRUE;
  1091.   }
  1092.   return FALSE;
  1093. }
  1094. //=============================================================================
  1095. //
  1096. //  ChangeNotifyDlg()
  1097. //
  1098. BOOL ChangeNotifyDlg(HWND hwnd)
  1099. {
  1100.   int iResult;
  1101.   iResult = ThemedDialogBoxParam(
  1102.               g_hInstance,
  1103.               MAKEINTRESOURCEW(IDD_CHANGENOTIFY),
  1104.               hwnd,
  1105.               ChangeNotifyDlgProc,
  1106.               0);
  1107.   return (iResult == IDOK) ? TRUE : FALSE;
  1108. }
  1109. //=============================================================================
  1110. //
  1111. //  ColumnWrapDlgProc()
  1112. //
  1113. //  Controls: 100 Edit
  1114. //
  1115. BOOL CALLBACK ColumnWrapDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  1116. {
  1117.   static int *piNumber;
  1118.   switch(umsg)
  1119.   {
  1120.     case WM_INITDIALOG:
  1121.       {
  1122.         piNumber = (int*)lParam;
  1123.         SetDlgItemInt(hwnd,100,*piNumber,FALSE);
  1124.         SendDlgItemMessage(hwnd,100,EM_LIMITTEXT,15,0);
  1125.         CenterDlgInParent(hwnd);
  1126.       }
  1127.       return TRUE;
  1128.     case WM_COMMAND:
  1129.       switch(LOWORD(wParam))
  1130.       {
  1131.         case IDOK: {
  1132.           BOOL fTranslated;
  1133.           int iNewNumber = GetDlgItemInt(hwnd,100,&fTranslated,FALSE);
  1134.           if (fTranslated)
  1135.           {
  1136.             *piNumber = iNewNumber;
  1137.             EndDialog(hwnd,IDOK);
  1138.           }
  1139.           else
  1140.             PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,100)),1);
  1141.           }
  1142.           break;
  1143.         case IDCANCEL:
  1144.           EndDialog(hwnd,IDCANCEL);
  1145.           break;
  1146.       }
  1147.       return TRUE;
  1148.   }
  1149.   return FALSE;
  1150. }
  1151. //=============================================================================
  1152. //
  1153. //  ColumnWrapDlg()
  1154. //
  1155. BOOL ColumnWrapDlg(HWND hwnd,UINT uidDlg,int *iNumber)
  1156. {
  1157.   int iResult;
  1158.   iResult = ThemedDialogBoxParam(
  1159.               g_hInstance,
  1160.               MAKEINTRESOURCE(uidDlg),
  1161.               hwnd,
  1162.               ColumnWrapDlgProc,(LPARAM)iNumber);
  1163.   return (iResult == IDOK) ? TRUE : FALSE;
  1164. }
  1165. //=============================================================================
  1166. //
  1167. //  WordWrapSettingsDlgProc()
  1168. //
  1169. //  Controls: 100 Combo
  1170. //            101 Combo
  1171. //            102 Combo
  1172. //            103 Combo
  1173. //            200 Text
  1174. //            201 Text
  1175. //            202 Text
  1176. //            203 Text
  1177. //
  1178. extern int  iWordWrapMode;
  1179. extern int  iWordWrapIndent;
  1180. extern int  iWordWrapSymbols;
  1181. extern BOOL bShowWordWrapSymbols;
  1182. BOOL CALLBACK WordWrapSettingsDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  1183. {
  1184.   switch(umsg)
  1185.   {
  1186.     case WM_INITDIALOG:
  1187.       {
  1188.         WCHAR tch[512];
  1189.         WCHAR *p1, *p2;
  1190.         int i;
  1191.         for (i = 0; i < 4; i++) {
  1192.           GetDlgItemText(hwnd,200+i,tch,COUNTOF(tch));
  1193.           lstrcat(tch,L"|");
  1194.           p1 = tch;
  1195.           while (p2 = StrChr(p1,L'|')) {
  1196.             *p2++ = L'';
  1197.             if (*p1)
  1198.               SendDlgItemMessage(hwnd,100+i,CB_ADDSTRING,0,(LPARAM)p1);
  1199.             p1 = p2;
  1200.           }
  1201.           SendDlgItemMessage(hwnd,100+i,CB_SETEXTENDEDUI,TRUE,0);
  1202.         }
  1203.         SendDlgItemMessage(hwnd,100,CB_SETCURSEL,(WPARAM)iWordWrapIndent,0);
  1204.         SendDlgItemMessage(hwnd,101,CB_SETCURSEL,(WPARAM)(bShowWordWrapSymbols) ? iWordWrapSymbols%10 : 0,0);
  1205.         SendDlgItemMessage(hwnd,102,CB_SETCURSEL,(WPARAM)(bShowWordWrapSymbols) ? ((iWordWrapSymbols%100)-(iWordWrapSymbols%10))/10 : 0,0);
  1206.         SendDlgItemMessage(hwnd,103,CB_SETCURSEL,(WPARAM)iWordWrapMode,0);
  1207.         CenterDlgInParent(hwnd);
  1208.       }
  1209.       return TRUE;
  1210.     case WM_COMMAND:
  1211.       switch(LOWORD(wParam))
  1212.       {
  1213.         case IDOK: {
  1214.             int iSel, iSel2;
  1215.             iSel = SendDlgItemMessage(hwnd,100,CB_GETCURSEL,0,0);
  1216.             iWordWrapIndent = iSel;
  1217.             bShowWordWrapSymbols = FALSE;
  1218.             iSel = SendDlgItemMessage(hwnd,101,CB_GETCURSEL,0,0);
  1219.             iSel2 = SendDlgItemMessage(hwnd,102,CB_GETCURSEL,0,0);
  1220.             if (iSel > 0 || iSel2 > 0) {
  1221.               bShowWordWrapSymbols = TRUE;
  1222.               iWordWrapSymbols = iSel + iSel2*10;
  1223.             }
  1224.             iSel = SendDlgItemMessage(hwnd,103,CB_GETCURSEL,0,0);
  1225.             iWordWrapMode = iSel;
  1226.             EndDialog(hwnd,IDOK);
  1227.           }
  1228.           break;
  1229.         case IDCANCEL:
  1230.           EndDialog(hwnd,IDCANCEL);
  1231.           break;
  1232.       }
  1233.       return TRUE;
  1234.   }
  1235.   return FALSE;
  1236. }
  1237. //=============================================================================
  1238. //
  1239. //  WordWrapSettingsDlg()
  1240. //
  1241. BOOL WordWrapSettingsDlg(HWND hwnd,UINT uidDlg,int *iNumber)
  1242. {
  1243.   int iResult;
  1244.   iResult = ThemedDialogBoxParam(
  1245.               g_hInstance,
  1246.               MAKEINTRESOURCE(uidDlg),
  1247.               hwnd,
  1248.               WordWrapSettingsDlgProc,(LPARAM)iNumber);
  1249.   return (iResult == IDOK) ? TRUE : FALSE;
  1250. }
  1251. //=============================================================================
  1252. //
  1253. //  LongLineSettingsDlgProc()
  1254. //
  1255. //  Controls: 100 Edit
  1256. //            101 Radio1
  1257. //            102 Radio2
  1258. //
  1259. extern int iLongLineMode;
  1260. BOOL CALLBACK LongLineSettingsDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  1261. {
  1262.   static int *piNumber;
  1263.   switch(umsg)
  1264.   {
  1265.     case WM_INITDIALOG:
  1266.       {
  1267.         piNumber = (int*)lParam;
  1268.         SetDlgItemInt(hwnd,100,*piNumber,FALSE);
  1269.         SendDlgItemMessage(hwnd,100,EM_LIMITTEXT,15,0);
  1270.         if (iLongLineMode == EDGE_LINE)
  1271.           CheckRadioButton(hwnd,101,102,101);
  1272.         else
  1273.           CheckRadioButton(hwnd,101,102,102);
  1274.         CenterDlgInParent(hwnd);
  1275.       }
  1276.       return TRUE;
  1277.     case WM_COMMAND:
  1278.       switch(LOWORD(wParam))
  1279.       {
  1280.         case IDOK: {
  1281.           BOOL fTranslated;
  1282.           int iNewNumber = GetDlgItemInt(hwnd,100,&fTranslated,FALSE);
  1283.           if (fTranslated)
  1284.           {
  1285.             *piNumber = iNewNumber;
  1286.             iLongLineMode = (IsDlgButtonChecked(hwnd,101)) ? EDGE_LINE : EDGE_BACKGROUND;
  1287.             EndDialog(hwnd,IDOK);
  1288.           }
  1289.           else
  1290.             PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,100)),1);
  1291.           }
  1292.           break;
  1293.         case IDCANCEL:
  1294.           EndDialog(hwnd,IDCANCEL);
  1295.           break;
  1296.       }
  1297.       return TRUE;
  1298.   }
  1299.   return FALSE;
  1300. }
  1301. //=============================================================================
  1302. //
  1303. //  LongLineSettingsDlg()
  1304. //
  1305. BOOL LongLineSettingsDlg(HWND hwnd,UINT uidDlg,int *iNumber)
  1306. {
  1307.   int iResult;
  1308.   iResult = ThemedDialogBoxParam(
  1309.               g_hInstance,
  1310.               MAKEINTRESOURCE(uidDlg),
  1311.               hwnd,
  1312.               LongLineSettingsDlgProc,(LPARAM)iNumber);
  1313.   return (iResult == IDOK) ? TRUE : FALSE;
  1314. }
  1315. //=============================================================================
  1316. //
  1317. //  TabSettingsDlgProc()
  1318. //
  1319. //  Controls: 100 Edit
  1320. //            101 Edit
  1321. //            102 Check
  1322. //            103 Check
  1323. //
  1324. extern int iTabWidth;
  1325. extern int iIndentWidth;
  1326. extern BOOL bTabsAsSpaces;
  1327. extern BOOL bTabIndents;
  1328. BOOL CALLBACK TabSettingsDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  1329. {
  1330.   switch(umsg)
  1331.   {
  1332.     case WM_INITDIALOG:
  1333.       {
  1334.         SetDlgItemInt(hwnd,100,iTabWidth,FALSE);
  1335.         SendDlgItemMessage(hwnd,100,EM_LIMITTEXT,15,0);
  1336.         SetDlgItemInt(hwnd,101,iIndentWidth,FALSE);
  1337.         SendDlgItemMessage(hwnd,101,EM_LIMITTEXT,15,0);
  1338.         if (bTabsAsSpaces)
  1339.           CheckDlgButton(hwnd,102,BST_CHECKED);
  1340.         if (bTabIndents)
  1341.           CheckDlgButton(hwnd,103,BST_CHECKED);
  1342.         CenterDlgInParent(hwnd);
  1343.       }
  1344.       return TRUE;
  1345.     case WM_COMMAND:
  1346.       switch(LOWORD(wParam))
  1347.       {
  1348.         case IDOK: {
  1349.           BOOL fTranslated1,fTranslated2;
  1350.           int iNewTabWidth = GetDlgItemInt(hwnd,100,&fTranslated1,FALSE);
  1351.           int iNewIndentWidth = GetDlgItemInt(hwnd,101,&fTranslated2,FALSE);
  1352.           if (fTranslated1 && fTranslated2)
  1353.           {
  1354.             iTabWidth = iNewTabWidth;
  1355.             iIndentWidth = iNewIndentWidth;
  1356.             bTabsAsSpaces = (IsDlgButtonChecked(hwnd,102)) ? TRUE : FALSE;
  1357.             bTabIndents = (IsDlgButtonChecked(hwnd,103)) ? TRUE : FALSE;
  1358.             EndDialog(hwnd,IDOK);
  1359.           }
  1360.           else
  1361.             PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,(fTranslated1) ? 101 : 100)),1);
  1362.           }
  1363.           break;
  1364.         case IDCANCEL:
  1365.           EndDialog(hwnd,IDCANCEL);
  1366.           break;
  1367.       }
  1368.       return TRUE;
  1369.   }
  1370.   return FALSE;
  1371. }
  1372. //=============================================================================
  1373. //
  1374. //  TabSettingsDlg()
  1375. //
  1376. BOOL TabSettingsDlg(HWND hwnd,UINT uidDlg,int *iNumber)
  1377. {
  1378.   int iResult;
  1379.   iResult = ThemedDialogBoxParam(
  1380.               g_hInstance,
  1381.               MAKEINTRESOURCE(uidDlg),
  1382.               hwnd,
  1383.               TabSettingsDlgProc,(LPARAM)iNumber);
  1384.   return (iResult == IDOK) ? TRUE : FALSE;
  1385. }
  1386. //=============================================================================
  1387. //
  1388. //  SelectDefEncodingDlgProc()
  1389. //
  1390. //
  1391. typedef struct encodedlg {
  1392.   BOOL bRecodeOnly;
  1393.   int  idEncoding;
  1394.   int  cxDlg;
  1395.   int  cyDlg;
  1396. } ENCODEDLG, *PENCODEDLG;
  1397. BOOL CALLBACK SelectDefEncodingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  1398. {
  1399.   static PENCODEDLG pdd;
  1400.   switch(umsg)
  1401.   {
  1402.     case WM_INITDIALOG:
  1403.       {
  1404.         HBITMAP hbmp;
  1405.         HIMAGELIST himl;
  1406.         pdd = (PENCODEDLG)lParam;
  1407.         hbmp = LoadImage(g_hInstance,MAKEINTRESOURCE(IDB_ENCODING),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
  1408.         himl = ImageList_Create(16,16,ILC_COLOR32|ILC_MASK,0,0);
  1409.         ImageList_AddMasked(himl,hbmp,CLR_DEFAULT);
  1410.         DeleteObject(hbmp);
  1411.         SendDlgItemMessage(hwnd,IDC_ENCODINGLIST,CBEM_SETIMAGELIST,0,(LPARAM)himl);
  1412.         SendDlgItemMessage(hwnd,IDC_ENCODINGLIST,CB_SETEXTENDEDUI,TRUE,0);
  1413.         Encoding_AddToComboboxEx(GetDlgItem(hwnd,IDC_ENCODINGLIST),pdd->idEncoding,0);
  1414.         if (bSkipUnicodeDetection)
  1415.           CheckDlgButton(hwnd,IDC_NOUNICODEDETECTION,BST_CHECKED);
  1416.         if (bLoadASCIIasUTF8)
  1417.           CheckDlgButton(hwnd,IDC_ASCIIASUTF8,BST_CHECKED);
  1418.         if (bNoEncodingTags)
  1419.           CheckDlgButton(hwnd,IDC_ENCODINGFROMFILEVARS,BST_CHECKED);
  1420.         CenterDlgInParent(hwnd);
  1421.       }
  1422.       return TRUE;
  1423.     case WM_COMMAND:
  1424.       switch(LOWORD(wParam))
  1425.       {
  1426.         case IDOK: {
  1427.             if (Encoding_GetFromComboboxEx(GetDlgItem(hwnd,IDC_ENCODINGLIST),&pdd->idEncoding)) {
  1428.               bSkipUnicodeDetection = (IsDlgButtonChecked(hwnd,IDC_NOUNICODEDETECTION) == BST_CHECKED) ? 1 : 0;
  1429.               bLoadASCIIasUTF8 = (IsDlgButtonChecked(hwnd,IDC_ASCIIASUTF8) == BST_CHECKED) ? 1 : 0;
  1430.               bNoEncodingTags = (IsDlgButtonChecked(hwnd,IDC_ENCODINGFROMFILEVARS) == BST_CHECKED) ? 1 : 0;
  1431.               EndDialog(hwnd,IDOK);
  1432.             }
  1433.             else
  1434.               PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_ENCODINGLIST)),1);
  1435.           }
  1436.           break;
  1437.         case IDCANCEL:
  1438.           EndDialog(hwnd,IDCANCEL);
  1439.           break;
  1440.       }
  1441.       return TRUE;
  1442.   }
  1443.   return FALSE;
  1444. }
  1445. //=============================================================================
  1446. //
  1447. //  SelectDefEncodingDlg()
  1448. //
  1449. BOOL SelectDefEncodingDlg(HWND hwnd,int *pidREncoding)
  1450. {
  1451.   int iResult;
  1452.   ENCODEDLG dd;
  1453.   dd.bRecodeOnly = FALSE;
  1454.   dd.idEncoding = *pidREncoding;
  1455.   iResult = ThemedDialogBoxParam(
  1456.               g_hInstance,
  1457.               MAKEINTRESOURCE(IDD_DEFENCODING),
  1458.               hwnd,
  1459.               SelectDefEncodingDlgProc,
  1460.               (LPARAM)&dd);
  1461.   if (iResult == IDOK) {
  1462.     *pidREncoding = dd.idEncoding;
  1463.     return(TRUE);
  1464.   }
  1465.   else
  1466.     return(FALSE);
  1467. }
  1468. //=============================================================================
  1469. //
  1470. //  SelectEncodingDlgProc()
  1471. //
  1472. //
  1473. BOOL CALLBACK SelectEncodingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  1474. {
  1475.   static PENCODEDLG pdd;
  1476.   static HWND hwndLV;
  1477.   switch(umsg)
  1478.   {
  1479.     case WM_INITDIALOG:
  1480.       {
  1481.         LVCOLUMN lvc = { LVCF_FMT|LVCF_TEXT, LVCFMT_LEFT, 0, L"", -1, 0, 0, 0 };
  1482.         HBITMAP hbmp;
  1483.         HIMAGELIST himl;
  1484.         pdd = (PENCODEDLG)lParam;
  1485.         ResizeDlg_Init(hwnd,pdd->cxDlg,pdd->cyDlg,IDC_RESIZEGRIP4);
  1486.         hwndLV = GetDlgItem(hwnd,IDC_ENCODINGLIST);
  1487.         hbmp = LoadImage(g_hInstance,MAKEINTRESOURCE(IDB_ENCODING),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
  1488.         himl = ImageList_Create(16,16,ILC_COLOR32|ILC_MASK,0,0);
  1489.         ImageList_AddMasked(himl,hbmp,CLR_DEFAULT);
  1490.         DeleteObject(hbmp);
  1491.         ListView_SetImageList(GetDlgItem(hwnd,IDC_ENCODINGLIST),himl,LVSIL_SMALL);
  1492.         //SetExplorerTheme(hwndLV);
  1493.         ListView_SetExtendedListViewStyle(hwndLV,/*LVS_EX_FULLROWSELECT|*/LVS_EX_DOUBLEBUFFER|LVS_EX_LABELTIP);
  1494.         ListView_InsertColumn(hwndLV,0,&lvc);
  1495.         Encoding_AddToListView(hwndLV,pdd->idEncoding,pdd->bRecodeOnly);
  1496.         ListView_SetColumnWidth(hwndLV,0,LVSCW_AUTOSIZE_USEHEADER);
  1497.         CenterDlgInParent(hwnd);
  1498.       }
  1499.       return TRUE;
  1500.     case WM_DESTROY:
  1501.       ResizeDlg_Destroy(hwnd,&pdd->cxDlg,&pdd->cyDlg);
  1502.       return FALSE;
  1503.     case WM_SIZE:
  1504.       {
  1505.         int dx;
  1506.         int dy;
  1507.         HDWP hdwp;
  1508.         ResizeDlg_Size(hwnd,lParam,&dx,&dy);
  1509.         hdwp = BeginDeferWindowPos(4);
  1510.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_RESIZEGRIP4,dx,dy,SWP_NOSIZE);
  1511.         hdwp = DeferCtlPos(hdwp,hwnd,IDOK,dx,dy,SWP_NOSIZE);
  1512.         hdwp = DeferCtlPos(hdwp,hwnd,IDCANCEL,dx,dy,SWP_NOSIZE);
  1513.         hdwp = DeferCtlPos(hdwp,hwnd,IDC_ENCODINGLIST,dx,dy,SWP_NOMOVE);
  1514.         EndDeferWindowPos(hdwp);
  1515.         ListView_SetColumnWidth(GetDlgItem(hwnd,IDC_ENCODINGLIST),0,LVSCW_AUTOSIZE_USEHEADER);
  1516.       }
  1517.       return TRUE;
  1518.     case WM_GETMINMAXINFO:
  1519.       ResizeDlg_GetMinMaxInfo(hwnd,lParam);
  1520.       return TRUE;
  1521.     case WM_NOTIFY: {
  1522.         if (((LPNMHDR)(lParam))->idFrom == IDC_ENCODINGLIST) {
  1523.         switch (((LPNMHDR)(lParam))->code) {
  1524.           case NM_DBLCLK:
  1525.             SendMessage(hwnd,WM_COMMAND,MAKELONG(IDOK,1),0);
  1526.             break;
  1527.           case LVN_ITEMCHANGED:
  1528.           case LVN_DELETEITEM: {
  1529.               int i = ListView_GetNextItem(hwndLV,-1,LVNI_ALL | LVNI_SELECTED);
  1530.               EnableWindow(GetDlgItem(hwnd,IDOK),i != -1);
  1531.             }
  1532.             break;
  1533.           }
  1534.         }
  1535.       }
  1536.       return TRUE;
  1537.     case WM_COMMAND:
  1538.       switch(LOWORD(wParam))
  1539.       {
  1540.         case IDOK:
  1541.           if (Encoding_GetFromListView(hwndLV,&pdd->idEncoding))
  1542.             EndDialog(hwnd,IDOK);
  1543.           else
  1544.             PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,IDC_ENCODINGLIST)),1);
  1545.           break;
  1546.         case IDCANCEL:
  1547.           EndDialog(hwnd,IDCANCEL);
  1548.           break;
  1549.       }
  1550.       return TRUE;
  1551.   }
  1552.   return FALSE;
  1553. }
  1554. //=============================================================================
  1555. //
  1556. //  SelectEncodingDlg()
  1557. //
  1558. extern int cxEncodingDlg;
  1559. extern int cyEncodingDlg;
  1560. BOOL SelectEncodingDlg(HWND hwnd,int *pidREncoding)
  1561. {
  1562.   int iResult;
  1563.   ENCODEDLG dd;
  1564.   dd.bRecodeOnly = FALSE;
  1565.   dd.idEncoding = *pidREncoding;
  1566.   dd.cxDlg = cxEncodingDlg;
  1567.   dd.cyDlg = cyEncodingDlg;
  1568.   iResult = ThemedDialogBoxParam(
  1569.               g_hInstance,
  1570.               MAKEINTRESOURCE(IDD_ENCODING),
  1571.               hwnd,
  1572.               SelectEncodingDlgProc,
  1573.               (LPARAM)&dd);
  1574.   cxEncodingDlg = dd.cxDlg;
  1575.   cyEncodingDlg = dd.cyDlg;
  1576.   if (iResult == IDOK) {
  1577.     *pidREncoding = dd.idEncoding;
  1578.     return(TRUE);
  1579.   }
  1580.   else
  1581.     return(FALSE);
  1582. }
  1583. //=============================================================================
  1584. //
  1585. //  RecodeDlg()
  1586. //
  1587. extern int cxRecodeDlg;
  1588. extern int cyRecodeDlg;
  1589. BOOL RecodeDlg(HWND hwnd,int *pidREncoding)
  1590. {
  1591.   int iResult;
  1592.   ENCODEDLG dd;
  1593.   dd.bRecodeOnly = TRUE;
  1594.   dd.idEncoding = *pidREncoding;
  1595.   dd.cxDlg = cxRecodeDlg;
  1596.   dd.cyDlg = cyRecodeDlg;
  1597.   iResult = ThemedDialogBoxParam(
  1598.               g_hInstance,
  1599.               MAKEINTRESOURCE(IDD_RECODE),
  1600.               hwnd,
  1601.               SelectEncodingDlgProc,
  1602.               (LPARAM)&dd);
  1603.   cxRecodeDlg = dd.cxDlg;
  1604.   cyRecodeDlg = dd.cyDlg;
  1605.   if (iResult == IDOK) {
  1606.     *pidREncoding = dd.idEncoding;
  1607.     return(TRUE);
  1608.   }
  1609.   else
  1610.     return(FALSE);
  1611. }
  1612. //=============================================================================
  1613. //
  1614. //  SelectDefLineEndingDlgProc()
  1615. //
  1616. //  Controls: 100 Combo
  1617. //            IDC_CONSISTENTEOLS
  1618. //            IDC_AUTOSTRIPBLANKS
  1619. //
  1620. BOOL CALLBACK SelectDefLineEndingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  1621. {
  1622.   static int *piOption;
  1623.   switch(umsg)
  1624.   {
  1625.     case WM_INITDIALOG:
  1626.       {
  1627.         int i;
  1628.         WCHAR wch[128];
  1629.         piOption = (int*)lParam;
  1630.         // Load options
  1631.         for (i = 0; i < 3; i++) {
  1632.           GetString(IDS_EOLMODENAME0+i,wch,COUNTOF(wch));
  1633.           SendDlgItemMessage(hwnd,100,CB_ADDSTRING,0,(LPARAM)wch);
  1634.         }
  1635.         SendDlgItemMessage(hwnd,100,CB_SETCURSEL,(WPARAM)*piOption,0);
  1636.         SendDlgItemMessage(hwnd,100,CB_SETEXTENDEDUI,TRUE,0);
  1637.         if (bFixLineEndings)
  1638.           CheckDlgButton(hwnd,IDC_CONSISTENTEOLS,BST_CHECKED);
  1639.         if (bAutoStripBlanks)
  1640.           CheckDlgButton(hwnd,IDC_AUTOSTRIPBLANKS, BST_CHECKED);
  1641.         CenterDlgInParent(hwnd);
  1642.       }
  1643.       return TRUE;
  1644.     case WM_COMMAND:
  1645.       switch(LOWORD(wParam))
  1646.       {
  1647.         case IDOK: {
  1648.             *piOption = SendDlgItemMessage(hwnd,100,CB_GETCURSEL,0,0);
  1649.             bFixLineEndings = (IsDlgButtonChecked(hwnd,IDC_CONSISTENTEOLS) == BST_CHECKED) ? 1 : 0;
  1650.             bAutoStripBlanks = (IsDlgButtonChecked(hwnd,IDC_AUTOSTRIPBLANKS) == BST_CHECKED) ? 1 : 0;
  1651.             EndDialog(hwnd,IDOK);
  1652.           }
  1653.           break;
  1654.         case IDCANCEL:
  1655.           EndDialog(hwnd,IDCANCEL);
  1656.           break;
  1657.       }
  1658.       return TRUE;
  1659.   }
  1660.   return FALSE;
  1661. }
  1662. //=============================================================================
  1663. //
  1664. //  SelectDefLineEndingDlg()
  1665. //
  1666. BOOL SelectDefLineEndingDlg(HWND hwnd,int *iOption)
  1667. {
  1668.   int iResult;
  1669.   iResult = ThemedDialogBoxParam(
  1670.               g_hInstance,
  1671.               MAKEINTRESOURCE(IDD_DEFEOLMODE),
  1672.               hwnd,
  1673.               SelectDefLineEndingDlgProc,
  1674.               (LPARAM)iOption);
  1675.   return (iResult == IDOK) ? TRUE : FALSE;
  1676. }
  1677. //=============================================================================
  1678. //
  1679. //  InfoBoxDlgProc()
  1680. //
  1681. //
  1682. typedef struct _infobox {
  1683.   LPWSTR lpstrMessage;
  1684.   LPWSTR lpstrSetting;
  1685.   BOOL   bDisableCheckBox;
  1686. } INFOBOX, *LPINFOBOX;
  1687. BOOL CALLBACK InfoBoxDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
  1688. {
  1689.   LPINFOBOX lpib;
  1690.   switch(umsg)
  1691.   {
  1692.     case WM_INITDIALOG:
  1693.       lpib = (LPINFOBOX)lParam;
  1694.       SetWindowLongPtr(hwnd,DWLP_USER,lParam);
  1695.       SendDlgItemMessage(hwnd,IDC_INFOBOXICON,STM_SETICON,
  1696.         (WPARAM)LoadIcon(NULL,IDI_EXCLAMATION),0);
  1697.       SetDlgItemText(hwnd,IDC_INFOBOXTEXT,lpib->lpstrMessage);
  1698.       if (lpib->bDisableCheckBox)
  1699.         EnableWindow(GetDlgItem(hwnd,IDC_INFOBOXCHECK),FALSE);
  1700.       LocalFree(lpib->lpstrMessage);
  1701.       CenterDlgInParent(hwnd);
  1702.       return TRUE;
  1703.     case WM_COMMAND:
  1704.       switch(LOWORD(wParam))
  1705.       {
  1706.         case IDOK:
  1707.         case IDCANCEL:
  1708.         case IDYES:
  1709.         case IDNO:
  1710.           lpib = (LPINFOBOX)GetWindowLongPtr(hwnd,DWLP_USER);
  1711.           if (IsDlgButtonChecked(hwnd,IDC_INFOBOXCHECK))
  1712.             IniSetInt(L"Suppressed Messages",lpib->lpstrSetting,1);
  1713.           EndDialog(hwnd,LOWORD(wParam));
  1714.           break;
  1715.       }
  1716.       return TRUE;
  1717.   }
  1718.   return FALSE;
  1719. }
  1720. //=============================================================================
  1721. //
  1722. //  InfoBox()
  1723. //
  1724. //
  1725. extern WCHAR szIniFile[MAX_PATH];
  1726. int InfoBox(int iType,LPCWSTR lpstrSetting,int uidMessage,...)
  1727. {
  1728.   HWND hwnd;
  1729.   int idDlg = IDD_INFOBOX;
  1730.   INFOBOX ib;
  1731.   WCHAR wchFormat[512];
  1732.   if (IniGetInt(L"Suppressed Messages",lpstrSetting,0))
  1733.     return (iType == MBYESNO) ? IDYES : IDOK;
  1734.   if (!GetString(uidMessage,wchFormat,COUNTOF(wchFormat)))
  1735.     return(-1);
  1736.   ib.lpstrMessage = LocalAlloc(LPTR,1024 * sizeof(WCHAR));
  1737.   wvsprintf(ib.lpstrMessage,wchFormat,(LPVOID)((PUINT_PTR)&uidMessage + 1));
  1738.   ib.lpstrSetting = (LPWSTR)lpstrSetting;
  1739.   ib.bDisableCheckBox = (lstrlen(szIniFile) == 0) ? TRUE : FALSE;
  1740.   if (iType == MBYESNO)
  1741.     idDlg = IDD_INFOBOX2;
  1742.   else if (iType == MBOKCANCEL)
  1743.     idDlg = IDD_INFOBOX3;
  1744.   if (!(hwnd = GetFocus()))
  1745.     hwnd = hwndMain;
  1746.   MessageBeep(MB_ICONEXCLAMATION);
  1747.   return ThemedDialogBoxParam(
  1748.            g_hInstance,
  1749.            MAKEINTRESOURCE(idDlg),
  1750.            hwnd,
  1751.            InfoBoxDlgProc,
  1752.            (LPARAM)&ib);
  1753. }
  1754. //  End of Dialogs.c