Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

327 lines
9.1 KiB

  1. // ############################################################################
  2. // Miscellaneous support routines
  3. #include "pch.hpp"
  4. #ifdef WIN16
  5. #include <win16def.h>
  6. #endif
  7. #include "phbk.h"
  8. #define irgMaxSzs 5
  9. TCHAR szStrTable[irgMaxSzs][256];
  10. // ############################################################################
  11. LPTSTR GetSz(WORD wszID)
  12. {
  13. static int iSzTable=0;
  14. LPTSTR psz = (LPTSTR)&szStrTable[iSzTable][0];
  15. iSzTable++;
  16. if (iSzTable >= irgMaxSzs)
  17. iSzTable = 0;
  18. if (!LoadString(g_hInstDll, wszID, psz, 256))
  19. {
  20. TraceMsg(TF_GENERAL,"LoadString failed %d\n", (DWORD) wszID);
  21. *psz = 0;
  22. }
  23. return (psz);
  24. }
  25. // ############################################################################
  26. void SzCanonicalFromAE (LPTSTR psz, PACCESSENTRY pAE, LPLINECOUNTRYENTRY pLCE)
  27. {
  28. if (NO_AREA_CODE == pAE->dwAreaCode)
  29. {
  30. wsprintf(psz, TEXT("+%ld %s"), pLCE->dwCountryCode, pAE->szAccessNumber);
  31. }
  32. else
  33. {
  34. wsprintf(psz, TEXT("+%ld (%s) %s"), pLCE->dwCountryCode, pAE->szAreaCode, pAE->szAccessNumber);
  35. }
  36. return;
  37. }
  38. // ############################################################################
  39. int MyStrcmp(LPVOID pv1, LPVOID pv2)
  40. {
  41. LPTSTR pc1 = (LPTSTR) pv1;
  42. LPTSTR pc2 = (LPTSTR) pv2;
  43. int iRC = 0;
  44. // loop while not pointed at the ending NULL character and no difference has been found
  45. while (*pc1 && *pc2 && !iRC)
  46. {
  47. iRC = (int)(*pc1 - *pc2);
  48. pc1++;
  49. pc2++;
  50. }
  51. // if we exited because we got to the end of one string before we found a difference
  52. // return -1 if pv1 is longer, else return the character pointed at by pv2. If pv2
  53. // is longer than pv1 then the value at pv2 will be greater than 0. If both strings
  54. // ended at the same time, then pv2 will point to 0.
  55. if (!iRC)
  56. {
  57. iRC = (*pc1) ? -1 : (*pc2);
  58. }
  59. return iRC;
  60. }
  61. // ############################################################################
  62. int __cdecl Compare950Entry(const void*pv1, const void*pv2)
  63. {
  64. return (((NPABLOCK *) pv1)->wAreaCode - ((NPABLOCK *) pv2)->wAreaCode);
  65. }
  66. // ############################################################################
  67. int __cdecl CompareIDLookUpElements(const void *e1, const void *e2)
  68. {
  69. if (((LPIDLOOKUPELEMENT)e1)->dwID > ((LPIDLOOKUPELEMENT)e2)->dwID)
  70. return 1;
  71. if (((LPIDLOOKUPELEMENT)e1)->dwID < ((LPIDLOOKUPELEMENT)e2)->dwID)
  72. return -1;
  73. return 0;
  74. }
  75. // ############################################################################
  76. int __cdecl CompareCntryNameLookUpElements(const void *e1, const void *e2)
  77. {
  78. LPCNTRYNAMELOOKUPELEMENT pCUE1 = (LPCNTRYNAMELOOKUPELEMENT)e1;
  79. LPCNTRYNAMELOOKUPELEMENT pCUE2 = (LPCNTRYNAMELOOKUPELEMENT)e2;
  80. #ifdef WIN16
  81. return lstrcmpi(pCUE1->psCountryName, pCUE2->psCountryName);
  82. #else
  83. return CompareString(LOCALE_USER_DEFAULT,0,pCUE1->psCountryName,
  84. pCUE1->dwNameSize,pCUE2->psCountryName,
  85. pCUE2->dwNameSize) - 2;
  86. // return CompareString(LOCALE_USER_DEFAULT,0,((LPCNTRYNAMELOOKUPELEMENT)*e1)->psCountryName,
  87. // ((LPCNTRYNAMELOOKUPELEMENT)*e1)->dwNameSize,((LPCNTRYNAMELOOKUPELEMENT)*e2)->psCountryName,
  88. // ((LPCNTRYNAMELOOKUPELEMENT)*e2)->dwNameSize) - 2;
  89. #endif
  90. }
  91. // ############################################################################
  92. int __cdecl CompareIdxLookUpElements(const void *e1, const void *e2)
  93. {
  94. if (((LPIDXLOOKUPELEMENT)e1)->dwIndex > ((LPIDXLOOKUPELEMENT)e2)->dwIndex)
  95. return 1;
  96. if (((LPIDXLOOKUPELEMENT)e1)->dwIndex < ((LPIDXLOOKUPELEMENT)e2)->dwIndex)
  97. return -1;
  98. return 0;
  99. }
  100. // ############################################################################
  101. int __cdecl CompareIdxLookUpElementsFileOrder(const void *pv1, const void *pv2)
  102. {
  103. PACCESSENTRY pae1, pae2;
  104. int iSort;
  105. pae1 = ((LPIDXLOOKUPELEMENT)pv1)->pAE;
  106. pae2 = ((LPIDXLOOKUPELEMENT)pv2)->pAE;
  107. // sort empty enteries to the end of the list
  108. if (!(pae1 && pae2))
  109. {
  110. return (pae1 ? -1 : (pae2 ? 1 : 0));
  111. }
  112. // country ASC, state ASC, city ASC, toll free DESC, flip DESC, con spd max DESC
  113. if (pae1->dwCountryID != pae2->dwCountryID)
  114. {
  115. return (int)(pae1->dwCountryID - pae2->dwCountryID);
  116. }
  117. if (pae1->wStateID != pae2->wStateID)
  118. {
  119. return (pae1->wStateID - pae2->wStateID);
  120. }
  121. iSort = MyStrcmp((LPVOID)pae1->szCity, (LPVOID)pae2->szCity);
  122. if (iSort)
  123. {
  124. return (iSort);
  125. }
  126. if (pae1->fType != pae2->fType)
  127. {
  128. return ((int) (pae2->fType - pae1->fType));
  129. }
  130. if (pae1->bFlipFactor != pae2->bFlipFactor)
  131. {
  132. return (pae2->bFlipFactor - pae1->bFlipFactor);
  133. }
  134. if (pae1->dwConnectSpeedMax != pae2->dwConnectSpeedMax)
  135. {
  136. return (int)(pae2->dwConnectSpeedMax - pae1->dwConnectSpeedMax);
  137. }
  138. return 0;
  139. }
  140. // ############################################################################
  141. //inline BOOL FSz2Dw(PCSTR pSz,DWORD *dw)
  142. BOOL FSz2Dw(LPCTSTR pSz,DWORD far *dw)
  143. {
  144. DWORD val = 0;
  145. while (*pSz)
  146. {
  147. if (*pSz >= '0' && *pSz <= '9')
  148. {
  149. val *= 10;
  150. val += *pSz++ - '0';
  151. }
  152. else
  153. {
  154. return FALSE; //bad number
  155. }
  156. }
  157. *dw = val;
  158. return (TRUE);
  159. }
  160. // ############################################################################
  161. //inline BOOL FSz2W(PCSTR pSz,WORD *w)
  162. BOOL FSz2W(LPCTSTR pSz,WORD far *w)
  163. {
  164. DWORD dw;
  165. if (FSz2Dw(pSz,&dw))
  166. {
  167. *w = (WORD)dw;
  168. return TRUE;
  169. }
  170. return FALSE;
  171. }
  172. // ############################################################################
  173. //inline BOOL FSz2B(PCSTR pSz,BYTE *pb)
  174. BOOL FSz2B(LPCTSTR pSz,BYTE far *pb)
  175. {
  176. DWORD dw;
  177. if (FSz2Dw(pSz,&dw))
  178. {
  179. *pb = (BYTE)dw;
  180. return TRUE;
  181. }
  182. return FALSE;
  183. }
  184. // ############################################################################
  185. HRESULT ReleaseBold(HWND hwnd)
  186. {
  187. HFONT hfont = NULL;
  188. hfont = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0);
  189. if (hfont) DeleteObject(hfont);
  190. return ERROR_SUCCESS;
  191. }
  192. // ############################################################################
  193. HRESULT MakeBold (HWND hwnd)
  194. {
  195. HRESULT hr = ERROR_SUCCESS;
  196. HFONT hfont = NULL;
  197. HFONT hnewfont = NULL;
  198. LOGFONT far * plogfont = NULL;
  199. if (!hwnd) goto MakeBoldExit;
  200. hfont = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0);
  201. if (!hfont)
  202. {
  203. hr = GetLastError();
  204. goto MakeBoldExit;
  205. }
  206. plogfont = (LOGFONT far *)GlobalAlloc(GPTR,sizeof(LOGFONT));
  207. if (!plogfont)
  208. {
  209. hr = GetLastError();
  210. goto MakeBoldExit;
  211. }
  212. if (!GetObject(hfont,sizeof(LOGFONT),(LPVOID)plogfont))
  213. {
  214. hr = GetLastError();
  215. goto MakeBoldExit;
  216. }
  217. if (plogfont->lfHeight < 24)
  218. {
  219. plogfont->lfHeight = plogfont->lfHeight + (plogfont->lfHeight / 4);
  220. }
  221. plogfont->lfWeight = FW_BOLD;
  222. if (!(hnewfont = CreateFontIndirect(plogfont)))
  223. {
  224. hr = GetLastError();
  225. goto MakeBoldExit;
  226. }
  227. SendMessage(hwnd,WM_SETFONT,(WPARAM)hnewfont,MAKELPARAM(FALSE,0));
  228. GlobalFree(plogfont);
  229. plogfont = NULL;
  230. MakeBoldExit:
  231. //if (hfont) DeleteObject(hfont);
  232. // BUG:? Do I need to delete hnewfont at some time?
  233. return hr;
  234. }
  235. #if !defined(WIN16)
  236. //+----------------------------------------------------------------------------
  237. //
  238. // Function: DWGetWin32Platform
  239. //
  240. // Synopsis: Return a value to determine win32 platform
  241. //
  242. // Arguements: None
  243. //
  244. // Returns: platform enumeration (see GetVersionEx for details)
  245. //
  246. // History: 8/8/96 ChrisK Created
  247. //
  248. //-----------------------------------------------------------------------------
  249. DWORD DWGetWin32Platform()
  250. {
  251. OSVERSIONINFO osver;
  252. ZeroMemory(&osver,sizeof(osver));
  253. osver.dwOSVersionInfoSize = sizeof(osver);
  254. if (GetVersionEx(&osver))
  255. return osver.dwPlatformId;
  256. AssertMsg(0,"GetVersionEx failed.\r\n");
  257. return 0;
  258. }
  259. //+----------------------------------------------------------------------------
  260. //
  261. // Function: DWGetWin32BuildNumber
  262. //
  263. // Synopsis: Return a value to determine win32 build
  264. //
  265. // Arguements: None
  266. //
  267. // Returns: build number
  268. //
  269. // History: 9/26/96 ChrisK Created
  270. //
  271. //-----------------------------------------------------------------------------
  272. DWORD DWGetWin32BuildNumber()
  273. {
  274. OSVERSIONINFO osver;
  275. ZeroMemory(&osver,sizeof(osver));
  276. osver.dwOSVersionInfoSize = sizeof(osver);
  277. if (GetVersionEx(&osver))
  278. // dwBuildNumber
  279. // Identifies the build number of the operating system in the low-order
  280. // word. (The high-order word contains the major and minor version numbers.)
  281. return (osver.dwBuildNumber & 0xFFFF);
  282. AssertMsg(0,"GetVersionEx failed.\r\n");
  283. return 0;
  284. }
  285. #endif