Source code of Windows XP (NT5)
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.

292 lines
8.5 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  3. /* Houston, Texas */
  4. /*===========================================================================*/
  5. #define NOLSTRING TRUE /* jtf win3 mod */
  6. #include <windows.h>
  7. #include "port1632.h"
  8. #include "dcrc.h"
  9. #include "dynacomm.h"
  10. /*---------------------------------------------------------------------------*/
  11. #define PRTLISTSIZE 2048
  12. /*---------------------------------------------------------------------------*/
  13. /* Print Setup Utilities [mbb] */
  14. /*---------------------------------------------------------------------------*/
  15. BOOL NEAR PrtGetList(HANDLE *hList, LPSTR *lpList)
  16. {
  17. BYTE szDevices[MINRESSTR];
  18. if((*hList = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) PRTLISTSIZE)) == NULL)
  19. return(FALSE);
  20. if((*lpList = GlobalLock(*hList)) == NULL)
  21. {
  22. *hList = GlobalFree(*hList);
  23. return(FALSE);
  24. }
  25. LoadString(hInst, STR_INI_DEVICES, (LPSTR) szDevices, sizeof(szDevices));
  26. return(GetProfileString((LPSTR) szDevices, NULL, NULL_STR, *lpList, PRTLISTSIZE)); /* mbbx 2.01.97 ... */
  27. /* return(GetProfileString((LPSTR) szDevices, NULL, NULL, *lpList, PRTLISTSIZE)); */
  28. }
  29. /*---------------------------------------------------------------------------*/
  30. VOID NEAR PrtFreeList(HANDLE hList)
  31. {
  32. GlobalUnlock(hList);
  33. GlobalFree(hList);
  34. }
  35. /*---------------------------------------------------------------------------*/
  36. WORD NEAR PrtGetDevice(BYTE *pDevice, BYTE *pDriver, BYTE *pPort)
  37. {
  38. WORD PrtGetDevice;
  39. BYTE szDevice[MINRESSTR], work[STR255];
  40. BYTE *pch;
  41. LoadString(hInst, STR_INI_DEVICES, (LPSTR) szDevice, sizeof(szDevice));
  42. GetProfileString((LPSTR) szDevice, (LPSTR) pDevice, NULL_STR, (LPSTR) work, sizeof(work));
  43. *pDriver = 0;
  44. *pPort = 0;
  45. sscanf(work, "%[^,]%c%s", pDriver, szDevice, pPort);
  46. for(pch = pDriver + strlen(pDriver); (pch > pDriver) && (*(pch-1) == 0x20); pch -= 1);
  47. *pch = 0;
  48. if(PrtGetDevice = (*pPort != 0))
  49. {
  50. for(pch = pPort; *pch != 0; pch += 1)
  51. if(*pch == ',')
  52. {
  53. *pch = 0;
  54. PrtGetDevice += 1;
  55. }
  56. *(pch+1) = 0;
  57. }
  58. return(PrtGetDevice);
  59. }
  60. /*---------------------------------------------------------------------------*/
  61. BOOL NEAR PrtTestDevice(BYTE *pDevice, BYTE *pDriver, BYTE *pPort, BYTE *pResult)
  62. {
  63. BYTE szWindows[MINRESSTR], szDevice[MINRESSTR];
  64. BYTE work[STR255];
  65. sprintf(pResult, "%s,%s,%s", pDevice, pDriver, pPort);
  66. LoadString(hInst, STR_INI_WINDOWS, (LPSTR) szWindows, sizeof(szWindows));
  67. LoadString(hInst, STR_INI_DEVICE, (LPSTR) szDevice, sizeof(szDevice));
  68. GetProfileString((LPSTR) szWindows, (LPSTR) szDevice, NULL_STR, (LPSTR) work, sizeof(work));
  69. /* changed from strcmpi -sdj */
  70. return(lstrcmpi(pResult, work) == 0);
  71. }
  72. /*---------------------------------------------------------------------------*/
  73. /* PrtInitList() - [mbb] */
  74. /*---------------------------------------------------------------------------*/
  75. VOID NEAR PrtInitList(HWND hDlg)
  76. {
  77. HANDLE hList;
  78. LPSTR lpList;
  79. INT nSelect, nCount, ndx, ndx2;
  80. BYTE work[STR255], szDriver[80], szPort[128], szDevice[128];
  81. SetCursor(LoadCursor(NULL, IDC_WAIT));
  82. if(PrtGetList(&hList, &lpList))
  83. {
  84. nSelect = -1;
  85. nCount = 0;
  86. for(ndx = 0; (lpList[ndx] != 0) && (ndx < PRTLISTSIZE);
  87. ndx += (lstrlen(lpList + ndx) + 1))
  88. {
  89. lstrcpy((LPSTR) work, lpList + ndx);
  90. if(PrtGetDevice(work, szDriver, szPort))
  91. {
  92. for(ndx2 = 0; szPort[ndx2] != 0;
  93. ndx2 += (strlen(szPort + ndx2) + 1))
  94. {
  95. if(PrtTestDevice(work, szDriver, szPort + ndx2, szDevice))
  96. nSelect = nCount;
  97. strcpy(szDevice, work);
  98. LoadString(hInst, STR_INI_ON, (LPSTR) szDevice + strlen(szDevice), MINRESSTR);
  99. strcpy(szDevice + strlen(szDevice), szPort + ndx2);
  100. SendDlgItemMessage(hDlg, IDPRINTNAME, LB_INSERTSTRING, -1, (LPARAM) szDevice);
  101. nCount += 1;
  102. }
  103. }
  104. }
  105. if(nSelect != -1)
  106. SendDlgItemMessage(hDlg, IDPRINTNAME, LB_SETCURSEL, nSelect, 0L);
  107. else
  108. {
  109. EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
  110. EnableWindow(GetDlgItem(hDlg, IDPRTSETUP), FALSE);
  111. }
  112. PrtFreeList(hList);
  113. }
  114. SetCursor(LoadCursor(NULL, IDC_ARROW));
  115. }
  116. /*---------------------------------------------------------------------------*/
  117. /* PrtDoCommand() - [mbb] */
  118. /*---------------------------------------------------------------------------*/
  119. BOOL NEAR PrtDoCommand(HWND hDlg, BOOL bSetup)
  120. {
  121. HANDLE hList, hDriver;
  122. LPSTR lpList;
  123. INT nSelect, nPorts, ndx;
  124. CHAR work[STR255], szDriver[80], szPort[128], szDevice[128];
  125. FARPROC lpDriver;
  126. if((nSelect = (INT)SendDlgItemMessage(hDlg, IDPRINTNAME, LB_GETCURSEL, 0, 0L)) == -1)
  127. return(TRUE);
  128. SetCursor(LoadCursor(NULL, IDC_WAIT));
  129. if(PrtGetList(&hList, &lpList))
  130. {
  131. for(ndx = 0; nSelect >= 0; ndx += (lstrlen(lpList + ndx) + 1))
  132. {
  133. lstrcpy(work, lpList + ndx);
  134. if((nPorts = PrtGetDevice(work, szDriver, szPort)) > nSelect)
  135. {
  136. for(ndx = 0; nSelect > 0; ndx += (strlen(szPort + ndx) + 1))
  137. {
  138. if(szPort[ndx] == 0)
  139. break;
  140. nSelect -= 1;
  141. }
  142. break;
  143. }
  144. nSelect -= nPorts;
  145. }
  146. PrtFreeList(hList);
  147. if(nSelect == 0)
  148. {
  149. if(bSetup)
  150. {
  151. strcpy(szDriver + strlen(szDriver), DRIVER_FILE_TYPE+2);
  152. /* jtf 3.14 if((hDriver = fileLoadLibrary(szDriver)) != NULL) */
  153. /*if((hDriver = MLoadLibrary((LPSTR) szDriver)) >= 32)
  154. LoadLibrary >= 32 changed to LoadLibrary != NULL -sdj*/
  155. #ifdef ORGCODE
  156. if((hDriver = LoadLibrary((LPSTR) szDriver)) >= 32) /* jtf 3.14 */
  157. #else
  158. if((hDriver = LoadLibrary((LPSTR) szDriver)) != NULL) /* jtf 3.14 */
  159. #endif
  160. {
  161. LoadString(hInst, STR_INI_DEVICEMODE, (LPSTR) szDevice, sizeof(szDevice));
  162. if(lpDriver = GetProcAddress(hDriver, (LPSTR) szDevice))
  163. (*lpDriver) (hDlg, hDriver, (LPSTR) work, (LPSTR) szPort);
  164. FreeLibrary(hDriver);
  165. }
  166. }
  167. else if(!PrtTestDevice(work, szDriver, szPort + ndx, szDevice))
  168. {
  169. LoadString(hInst, STR_INI_WINDOWS, (LPSTR) work, sizeof(work));
  170. LoadString(hInst, STR_INI_DEVICE, (LPSTR) szDriver, sizeof(szDriver));
  171. WriteProfileString((LPSTR) work, (LPSTR) szDriver, (LPSTR) szDevice);
  172. }
  173. }
  174. }
  175. SetCursor(LoadCursor(NULL, IDC_ARROW));
  176. return(bSetup);
  177. }
  178. /*---------------------------------------------------------------------------*/
  179. /* dbPrtSetup() - [mbb] */
  180. /*---------------------------------------------------------------------------*/
  181. BOOL APIENTRY dbPrtSetup(HWND hDlg, WORD message, WPARAM wParam, LONG lParam)
  182. {
  183. BOOL result;
  184. switch(message)
  185. {
  186. case WM_INITDIALOG:
  187. initDlgPos(hDlg);
  188. PrtInitList(hDlg); /* mbbx 2.01.149 ... */
  189. return(TRUE);
  190. case WM_COMMAND:
  191. switch(GET_WM_COMMAND_ID(wParam, lParam))
  192. {
  193. case IDOK:
  194. case IDCANCEL:
  195. case IDPRTSETUP:
  196. result = (GET_WM_COMMAND_ID(wParam, lParam) != IDCANCEL);
  197. break;
  198. case IDPRINTNAME:
  199. switch(GET_WM_COMMAND_CMD(wParam, lParam))
  200. {
  201. case LBN_SELCHANGE:
  202. result = (SendDlgItemMessage(hDlg, IDPRINTNAME, LB_GETCURSEL, 0, 0L) != -1);
  203. EnableWindow(GetDlgItem(hDlg, IDOK), result);
  204. EnableWindow(GetDlgItem(hDlg, IDPRTSETUP), result);
  205. return(TRUE);
  206. case LBN_DBLCLK:
  207. result = TRUE;
  208. break;
  209. default:
  210. return(TRUE);
  211. }
  212. break;
  213. default:
  214. return(FALSE);
  215. }
  216. break;
  217. default:
  218. return(FALSE);
  219. }
  220. if(result) /* mbbx 2.01.149 ... */
  221. {
  222. if(PrtDoCommand(hDlg, GET_WM_COMMAND_ID(wParam, lParam) == IDPRTSETUP))
  223. return(TRUE);
  224. }
  225. EndDialog(hDlg, 0);
  226. return(TRUE);
  227. }