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

RichEdit

开发平台:

Visual C++

  1. /******************************************************************************
  2. *
  3. *
  4. * Notepad2
  5. *
  6. * Helpers.h
  7. *   Definitions for general helper functions and macros
  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. extern HINSTANCE g_hInstance;
  21. extern UINT16 g_uWinVer;
  22. #define COUNTOF(ar) (sizeof(ar)/sizeof(ar[0]))
  23. extern WCHAR szIniFile[MAX_PATH];
  24. #define IniGetString(lpSection,lpName,lpDefault,lpReturnedStr,nSize) 
  25.   GetPrivateProfileString(lpSection,lpName,lpDefault,lpReturnedStr,nSize,szIniFile)
  26. #define IniGetInt(lpSection,lpName,nDefault) 
  27.   GetPrivateProfileInt(lpSection,lpName,nDefault,szIniFile)
  28. #define IniSetString(lpSection,lpName,lpString) 
  29.   WritePrivateProfileString(lpSection,lpName,lpString,szIniFile)
  30. #define IniDeleteSection(lpSection) 
  31.   WritePrivateProfileSection(lpSection,NULL,szIniFile)
  32. __inline BOOL IniSetInt(LPCWSTR lpSection,LPCWSTR lpName,int i) {
  33.   WCHAR tch[32]; wsprintf(tch,L"%i",i); return IniSetString(lpSection,lpName,tch);
  34. }
  35. #define LoadIniSection(lpSection,lpBuf,cchBuf) 
  36.   GetPrivateProfileSection(lpSection,lpBuf,cchBuf,szIniFile);
  37. #define SaveIniSection(lpSection,lpBuf) 
  38.   WritePrivateProfileSection(lpSection,lpBuf,szIniFile)
  39. int IniSectionGetString(LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,int);
  40. int IniSectionGetInt(LPCWSTR,LPCWSTR,int);
  41. BOOL IniSectionSetString(LPWSTR,LPCWSTR,LPCWSTR);
  42. __inline BOOL IniSectionSetInt(LPWSTR lpCachedIniSection,LPCWSTR lpName,int i) {
  43.   WCHAR tch[32]; wsprintf(tch,L"%i",i); return IniSectionSetString(lpCachedIniSection,lpName,tch);
  44. }
  45. void BeginWaitCursor();
  46. void EndWaitCursor();
  47. #define Is2k()    (g_uWinVer >= 0x0500)
  48. #define IsXP()    (g_uWinVer >= 0x0501)
  49. #define IsVista() (g_uWinVer >= 0x0600)
  50. #define IsW7()    (g_uWinVer >= 0x0601)
  51. BOOL PrivateIsAppThemed();
  52. HRESULT PrivateSetCurrentProcessExplicitAppUserModelID(PCWSTR);
  53. BOOL IsElevated();
  54. //BOOL SetExplorerTheme(HWND);
  55. BOOL VerifyContrast();
  56. BOOL SetWindowTitle(HWND,UINT,BOOL,UINT,LPCWSTR,int,BOOL,UINT,BOOL,LPCWSTR);
  57. void SetWindowTransparentMode(HWND,BOOL);
  58. void CenterDlgInParent(HWND);
  59. void GetDlgPos(HWND,LPINT,LPINT);
  60. void SetDlgPos(HWND,int,int);
  61. void ResizeDlg_Init(HWND,int,int,int);
  62. void ResizeDlg_Destroy(HWND,int*,int*);
  63. void ResizeDlg_Size(HWND,LPARAM,int*,int*);
  64. void ResizeDlg_GetMinMaxInfo(HWND,LPARAM);
  65. HDWP DeferCtlPos(HDWP,HWND,int,int,int,UINT);
  66. void MakeBitmapButton(HWND,int,HINSTANCE,UINT);
  67. void MakeColorPickButton(HWND,int,HINSTANCE,COLORREF);
  68. void DeleteBitmapButton(HWND,int);
  69. #define StatusSetSimple(hwnd,b) SendMessage(hwnd,SB_SIMPLE,(WPARAM)b,0)
  70. BOOL StatusSetText(HWND,UINT,LPCWSTR);
  71. BOOL StatusSetTextID(HWND,UINT,UINT);
  72. int  StatusCalcPaneWidth(HWND,LPCWSTR);
  73. int Toolbar_GetButtons(HWND,int,LPWSTR,int);
  74. int Toolbar_SetButtons(HWND,int,LPCWSTR,void*,int);
  75. LRESULT SendWMSize(HWND);
  76. #define EnableCmd(hmenu,id,b) EnableMenuItem(hmenu,id,(b)
  77.                                ?MF_BYCOMMAND|MF_ENABLED:MF_BYCOMMAND|MF_GRAYED)
  78. #define CheckCmd(hmenu,id,b)  CheckMenuItem(hmenu,id,(b)
  79.                                ?MF_BYCOMMAND|MF_CHECKED:MF_BYCOMMAND|MF_UNCHECKED)
  80. BOOL IsCmdEnabled(HWND, UINT);
  81. #define GetString(id,pb,cb) LoadString(g_hInstance,id,pb,cb)
  82. #define StrEnd(pStart) (pStart + lstrlen(pStart))
  83. int FormatString(LPWSTR,int,UINT,...);
  84. void PathRelativeToApp(LPWSTR,LPWSTR,int,BOOL,BOOL,BOOL);
  85. void PathAbsoluteFromApp(LPWSTR,LPWSTR,int,BOOL);
  86. BOOL PathIsLnkFile(LPCWSTR);
  87. BOOL PathGetLnkPath(LPCWSTR,LPWSTR,int);
  88. BOOL PathIsLnkToDirectory(LPCWSTR,LPWSTR,int);
  89. BOOL PathCreateDeskLnk(LPCWSTR);
  90. BOOL PathCreateFavLnk(LPCWSTR,LPCWSTR,LPCWSTR);
  91. BOOL TrimString(LPWSTR);
  92. BOOL ExtractFirstArgument(LPCWSTR, LPWSTR, LPWSTR);
  93. void PrepareFilterStr(LPWSTR);
  94. void StrTab2Space(LPWSTR);
  95. void  ExpandEnvironmentStringsEx(LPWSTR,DWORD);
  96. void  PathCanonicalizeEx(LPWSTR);
  97. DWORD GetLongPathNameEx(LPCWSTR,LPWSTR,DWORD);
  98. DWORD_PTR SHGetFileInfo2(LPCWSTR,DWORD,SHFILEINFO*,UINT,UINT);
  99. int  FormatNumberStr(LPWSTR);
  100. BOOL SetDlgItemIntEx(HWND,int,UINT);
  101. #define MBCSToWChar(c,a,w,i) MultiByteToWideChar(c,0,a,-1,w,i)
  102. #define WCharToMBCS(c,w,a,i) WideCharToMultiByte(c,0,w,-1,a,i,NULL,NULL)
  103. UINT    GetDlgItemTextA2W(UINT,HWND,int,LPSTR,int);
  104. UINT    SetDlgItemTextA2W(UINT,HWND,int,LPSTR);
  105. LRESULT ComboBox_AddStringA2W(UINT,HWND,LPCSTR);
  106. UINT CodePageFromCharSet(UINT);
  107. //==== MRU Functions ==========================================================
  108. #define MRU_MAXITEMS 24
  109. #define MRU_NOCASE    1
  110. #define MRU_UTF8      2
  111. typedef struct _mrulist {
  112.   WCHAR  szRegKey[256];
  113.   int   iFlags;
  114.   int   iSize;
  115.   LPWSTR pszItems[MRU_MAXITEMS];
  116. } MRULIST, *PMRULIST, *LPMRULIST;
  117. LPMRULIST MRU_Create(LPCWSTR,int,int);
  118. BOOL      MRU_Destroy(LPMRULIST);
  119. BOOL      MRU_Add(LPMRULIST,LPCWSTR);
  120. BOOL      MRU_AddFile(LPMRULIST,LPCWSTR,BOOL,BOOL);
  121. BOOL      MRU_Delete(LPMRULIST,int);
  122. BOOL      MRU_DeleteFileFromStore(LPMRULIST,LPCWSTR);
  123. BOOL      MRU_Empty(LPMRULIST);
  124. int       MRU_Enum(LPMRULIST,int,LPWSTR,int);
  125. BOOL      MRU_Load(LPMRULIST);
  126. BOOL      MRU_Save(LPMRULIST);
  127. BOOL      MRU_MergeSave(LPMRULIST,BOOL,BOOL,BOOL);
  128. //==== Themed Dialogs =========================================================
  129. #ifndef DLGTEMPLATEEX
  130. #pragma pack(push, 1)
  131. typedef struct {
  132.   WORD      dlgVer;
  133.   WORD      signature;
  134.   DWORD     helpID;
  135.   DWORD     exStyle;
  136.   DWORD     style;
  137.   WORD      cDlgItems;
  138.   short     x;
  139.   short     y;
  140.   short     cx;
  141.   short     cy;
  142. } DLGTEMPLATEEX;
  143. #pragma pack(pop)
  144. #endif
  145. BOOL GetThemedDialogFont(LPWSTR,WORD*);
  146. DLGTEMPLATE* LoadThemedDialogTemplate(LPCTSTR,HINSTANCE);
  147. #define ThemedDialogBox(hInstance,lpTemplate,hWndParent,lpDialogFunc) 
  148.   ThemedDialogBoxParam(hInstance,lpTemplate,hWndParent,lpDialogFunc,0)
  149. INT_PTR ThemedDialogBoxParam(HINSTANCE,LPCTSTR,HWND,DLGPROC,LPARAM);
  150. HWND    CreateThemedDialogParam(HINSTANCE,LPCTSTR,HWND,DLGPROC,LPARAM);
  151. //==== UnSlash Functions ======================================================
  152. void TransformBackslashes(char*,BOOL);
  153. //==== MinimizeToTray Functions - see comments in Helpers.c ===================
  154. VOID MinimizeWndToTray(HWND hWnd);
  155. VOID RestoreWndFromTray(HWND hWnd);
  156. ///   End of Helpers.h   \