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.

735 lines
24 KiB

  1. //#define __DEBUG
  2. #include "compatadmin.h"
  3. #include "customlayer.h"
  4. BOOL CALLBACK CustomLayerProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  5. BOOL CALLBACK EditLayerProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  6. BOOL CheckExistingLayer(CSTRING & szNewLayerName);
  7. PDBLAYER g_pLayer;
  8. CCustomLayer * g_pCustomLayer;
  9. BOOL CCustomLayer::AddCustomLayer(void)
  10. {
  11. g_pLayer = NULL;
  12. g_pCustomLayer = this;
  13. m_uMode = LAYERMODE_ADD;
  14. if ( TRUE == DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_CUSTOMLAYER),g_theApp.m_hWnd,(DLGPROC)CustomLayerProc) )
  15. return TRUE;
  16. return FALSE;
  17. }
  18. BOOL CCustomLayer::EditCustomLayer(void)
  19. {
  20. g_pLayer = NULL;
  21. /*
  22. */
  23. g_pCustomLayer = this;
  24. m_uMode = LAYERMODE_EDIT;
  25. if ( TRUE == DialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_SELECTLAYER),g_theApp.m_hWnd,(DLGPROC)EditLayerProc,FALSE) ) {
  26. if ( TRUE == DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_CUSTOMLAYER),g_theApp.m_hWnd,(DLGPROC)CustomLayerProc) )
  27. return TRUE;
  28. }
  29. return FALSE;
  30. }
  31. BOOL CCustomLayer::RemoveCustomLayer(void)
  32. {
  33. g_pLayer = NULL;
  34. g_pCustomLayer = this;
  35. m_uMode = LAYERMODE_REMOVE;
  36. if ( TRUE == DialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_SELECTLAYER),g_theApp.m_hWnd,(DLGPROC)EditLayerProc,FALSE) ) {
  37. PDBLAYER pWalk = g_theApp.GetDBLocal().m_pLayerList;
  38. PDBLAYER pHold;
  39. PDBRECORD pRec = g_theApp.GetDBLocal().m_pRecordHead;
  40. // Validate the layer to remove.
  41. //g_pLayer has been properly set in the EditLayerProc function. Now it's not NULL
  42. while ( NULL != pRec ) {
  43. BOOL bInUse = FALSE;
  44. if ( (g_pLayer != NULL ) && (pRec->szLayerName == g_pLayer->szLayerName) ) //PREfast
  45. bInUse = TRUE;
  46. PDBRECORD pDups = pRec->pDup;
  47. while ( NULL != pDups ) {
  48. if ( (g_pLayer != NULL) && (pDups->szLayerName == g_pLayer->szLayerName) ) // PREfast !
  49. bInUse = TRUE;
  50. pDups = pDups->pDup;
  51. }
  52. if ( bInUse ) {
  53. MessageBox(g_theApp.m_hWnd,TEXT("Cannot remove custom layer while it's in use"),TEXT("Unable to remove custom layer"),MB_OK);
  54. return FALSE;
  55. }
  56. pRec = pRec->pNext;
  57. }
  58. while ( NULL != pWalk ) {
  59. if ( g_pLayer == pWalk ) {
  60. if ( pWalk == g_theApp.GetDBLocal().m_pLayerList )
  61. g_theApp.GetDBLocal().m_pLayerList = pWalk->pNext;
  62. else
  63. pHold->pNext = pWalk->pNext;
  64. delete pWalk;
  65. return TRUE;
  66. }
  67. pHold = pWalk;
  68. pWalk = pWalk->pNext;
  69. }
  70. }
  71. return FALSE;
  72. }
  73. void SyncList(HWND hDlg, UINT uMaster, UINT uSlave)
  74. //For all those strings that appear in uMaster, remove them from uSlave
  75. // For ADD: the params passed are IDC_LAYERLIST,IDC_SHIMLIST
  76. //For REMOVE: SyncList(hDlg,IDC_SHIMLIST,IDC_LAYERLIST);
  77. {
  78. UINT uTotal = SendDlgItemMessage(hDlg,uMaster,LB_GETCOUNT,0,0);
  79. UINT uCount;
  80. TCHAR szText[1024];
  81. for ( uCount=0; uCount<uTotal; ++uCount ) {
  82. int nIndex;
  83. SendDlgItemMessage(hDlg,uMaster,LB_GETTEXT,uCount,(LPARAM) szText);
  84. nIndex = SendDlgItemMessage(hDlg,uSlave,LB_FINDSTRING,0,(LPARAM) szText);
  85. //The DONE button might need to be disabled if there are no items in the IDC_LAYERLIST (2nd list box)
  86. if ( LB_ERR != nIndex )
  87. SendDlgItemMessage(hDlg,uSlave,LB_DELETESTRING,nIndex,0);
  88. }
  89. SendMessage(hDlg,WM_COMMAND,MAKELONG(IDC_NAME,EN_UPDATE),0);
  90. }
  91. BOOL CALLBACK CustomLayerProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  92. {
  93. static BOOL bNameChanged = FALSE;// Did the user change the name of the layer
  94. static CSTRING szPresentLayerName; // The IDC_NAME when the WM_INITDIALOG is called
  95. /*
  96. This is ued when we are editing a layer.
  97. Suppose we change the name of the layer then, we have to make this name change in the DBRECORD::szLayerName
  98. for all those EXEs which have this layer in the present database
  99. */
  100. /*
  101. With all the items in the Listbox IDC_SHIMLIST (The first list box), in the data section we have the
  102. pointer to the corresponding SHIMDESC in the g_theApp.m_pShimList (The list of shims,populated from the sysmain.sdb
  103. Only GENERAL shims are shown in the list.
  104. */
  105. switch ( uMsg ) {
  106. case WM_INITDIALOG:
  107. {
  108. SendMessage(
  109. GetDlgItem(hDlg,IDC_NAME), // handle to destination window
  110. EM_LIMITTEXT, // message to send
  111. (WPARAM) 150, // text length
  112. (LPARAM) 0
  113. );
  114. if (g_pLayer != NULL ) {
  115. szPresentLayerName = g_pLayer->szLayerName ;
  116. }
  117. else {
  118. szPresentLayerName = NULL;
  119. bNameChanged = FALSE;
  120. }
  121. PSHIMDESC pWalk = g_theApp.GetDBGlobal().m_pShimList;
  122. while ( NULL != pWalk ) {
  123. if ( pWalk->bGeneral ) {
  124. //int nItem = SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_ADDSTRING,0,(LPARAM) (LPSTR) (pWalk->szShimName));
  125. int nItem = SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_ADDSTRING,0,(LPARAM) (pWalk->szShimName).pszString);
  126. if ( LB_ERR != nItem )
  127. SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_SETITEMDATA,nItem,(LPARAM) pWalk);
  128. }
  129. pWalk = pWalk->pNext;
  130. }
  131. /*g_pLayer will be NULL when the Dialog box is invoked for adding a layer.
  132. When the IDD_CUSTOMLAYER dilaog box is invoked after a EDIT or a REMOVE option, then
  133. this variable will point to the layer selected.
  134. */
  135. if ( NULL != g_pLayer ) {
  136. PSHIMDESC pWalk = g_pLayer->pShimList;
  137. // Turn off repaints
  138. SendDlgItemMessage(hDlg,IDC_SHIMLIST,WM_SETREDRAW,FALSE,0);
  139. SendDlgItemMessage(hDlg,IDC_LAYERLIST,WM_SETREDRAW,FALSE,0);
  140. SendDlgItemMessage(hDlg,IDC_NAME,WM_SETTEXT,0,(LPARAM) (LPCTSTR) g_pLayer->szLayerName);
  141. // Move the items over to the add side.
  142. while ( NULL != pWalk ) {
  143. int nIndex = SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_FINDSTRING,0,(LPARAM)(LPCTSTR) pWalk->szShimName);
  144. if ( LB_ERR != nIndex ) {
  145. SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_SETSEL,TRUE,nIndex);
  146. SendMessage(hDlg,WM_COMMAND,IDC_ADD,0);
  147. }
  148. pWalk = pWalk->pNext;
  149. }
  150. SendDlgItemMessage(hDlg,IDC_SHIMLIST,WM_SETREDRAW,TRUE,0);
  151. SendDlgItemMessage(hDlg,IDC_LAYERLIST,WM_SETREDRAW,TRUE,0);
  152. InvalidateRect(GetDlgItem(hDlg,IDC_SHIMLIST),NULL,TRUE);
  153. UpdateWindow(GetDlgItem(hDlg,IDC_SHIMLIST));
  154. InvalidateRect(GetDlgItem(hDlg,IDC_LAYERLIST),NULL,TRUE);
  155. UpdateWindow(GetDlgItem(hDlg,IDC_LAYERLIST));
  156. }//if (NULL != g_pLayer)
  157. SendMessage(hDlg,WM_COMMAND,MAKELONG(IDC_NAME,EN_UPDATE),0);
  158. SetFocus( GetDlgItem(hDlg, IDC_NAME) );
  159. }
  160. break;
  161. case WM_COMMAND:
  162. switch ( LOWORD(wParam) ) {
  163. case IDC_NAME:
  164. {
  165. /*The DONE button will be enabled only if the IDC_NAME, text box is non-empty and the
  166. the number of elements in the IDC_LAYERLIST is > 0
  167. */
  168. if ( EN_UPDATE == HIWORD(wParam) ) {
  169. if ( g_pLayer != NULL ) bNameChanged = TRUE; // The existing name has been changed.
  170. TCHAR szText[MAX_PATH_BUFFSIZE];
  171. UINT uTotal = SendDlgItemMessage(hDlg,IDC_LAYERLIST,LB_GETCOUNT,0,0);
  172. BOOL bEnable = TRUE;
  173. if ( 0 == uTotal || uTotal == LB_ERR )
  174. bEnable = FALSE;
  175. GetWindowText(GetDlgItem(hDlg,IDC_NAME),szText,MAX_PATH);
  176. if ( CSTRING::Trim(szText) == 0 ) bEnable = FALSE;
  177. EnableWindow(GetDlgItem(hDlg,IDOK),bEnable ? TRUE:FALSE);
  178. }
  179. }
  180. break;
  181. case IDC_REMOVEALL:
  182. {
  183. SendDlgItemMessage(hDlg,IDC_SHIMLIST,WM_SETREDRAW,FALSE,0);
  184. SendDlgItemMessage(hDlg,IDC_LAYERLIST,WM_SETREDRAW,FALSE,0);
  185. int nCount;
  186. do {
  187. nCount = SendDlgItemMessage(hDlg,IDC_LAYERLIST,LB_GETCOUNT,0,0);
  188. SendDlgItemMessage(hDlg,IDC_LAYERLIST,LB_SETSEL,TRUE,0);
  189. SendMessage(hDlg,WM_COMMAND,IDC_REMOVE,0);
  190. }
  191. while ( 0 != nCount );
  192. SendDlgItemMessage(hDlg,IDC_SHIMLIST,WM_SETREDRAW,TRUE,0);
  193. SendDlgItemMessage(hDlg,IDC_LAYERLIST,WM_SETREDRAW,TRUE,0);
  194. InvalidateRect(GetDlgItem(hDlg,IDC_SHIMLIST),NULL,TRUE);
  195. UpdateWindow(GetDlgItem(hDlg,IDC_SHIMLIST));
  196. InvalidateRect(GetDlgItem(hDlg,IDC_LAYERLIST),NULL,TRUE);
  197. UpdateWindow(GetDlgItem(hDlg,IDC_LAYERLIST));
  198. }
  199. break;
  200. case IDC_COPY:
  201. {
  202. PDBLAYER pHold = g_pLayer;
  203. g_pCustomLayer->m_uMode = LAYERMODE_COPY;
  204. HWND hwndFocus = GetFocus();
  205. //The parameter TRUE in "DialogBoxParam" means load the list of global layers and the cutomr layers, FALSE means load the
  206. //lsit of custom layers. The names of the layers are obatained from g_theApp.pLayerList.
  207. if ( TRUE == DialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_SELECTLAYER),g_theApp.m_hWnd,(DLGPROC)EditLayerProc,TRUE) ) {
  208. //Now g_pLayer points to the layer which the user has selected.
  209. PDBLAYER pCopy = g_pLayer;
  210. //Now g_pLayer again reveerts back to its old value ! Perhaps this can be NULL as well
  211. g_pLayer = pHold;
  212. // Remove everything.
  213. //SendMessage(hDlg,WM_COMMAND,IDC_REMOVEALL,0);
  214. if ( NULL != pCopy ) {
  215. PSHIMDESC pWalk = pCopy->pShimList;
  216. // Turn off repaints
  217. SendDlgItemMessage(hDlg,IDC_SHIMLIST,WM_SETREDRAW,FALSE,0);
  218. SendDlgItemMessage(hDlg,IDC_LAYERLIST,WM_SETREDRAW,FALSE,0);
  219. // Move the items over to the add side.
  220. while ( NULL != pWalk ) {
  221. int nIndex = SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_FINDSTRING,0,(LPARAM)(LPCTSTR) pWalk->szShimName);
  222. if ( LB_ERR != nIndex ) {
  223. SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_SETSEL,TRUE,nIndex);
  224. SendMessage(hDlg,WM_COMMAND,IDC_ADD,0);
  225. }
  226. pWalk = pWalk->pNext;
  227. }
  228. SendDlgItemMessage(hDlg,IDC_SHIMLIST,WM_SETREDRAW,TRUE,0);
  229. SendDlgItemMessage(hDlg,IDC_LAYERLIST,WM_SETREDRAW,TRUE,0);
  230. InvalidateRect(GetDlgItem(hDlg,IDC_SHIMLIST),NULL,TRUE);
  231. UpdateWindow(GetDlgItem(hDlg,IDC_SHIMLIST));
  232. InvalidateRect(GetDlgItem(hDlg,IDC_LAYERLIST),NULL,TRUE);
  233. UpdateWindow(GetDlgItem(hDlg,IDC_LAYERLIST));
  234. }
  235. }//if (TRUE == DialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_SELECTLAYER),g_theApp.m_hWnd,EditLayerProc,TRUE))
  236. SetFocus( hwndFocus );
  237. }
  238. break;
  239. case IDC_ADD:
  240. {
  241. // PB. Remember #shims should not become more than this !!!
  242. int nItems[1024];
  243. int nCount;
  244. int nTotal;
  245. // Enumerate all the selected items and add them to the layer list
  246. nTotal = SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_GETSELITEMS,sizeof(nItems)/sizeof(int),(LPARAM) &nItems);
  247. for ( nCount=0; nCount < nTotal; ++nCount ) {
  248. PSHIMDESC pShim = (PSHIMDESC) SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_GETITEMDATA,nItems[nCount],0);
  249. int nIndex;
  250. nIndex = SendDlgItemMessage(hDlg,IDC_LAYERLIST,LB_ADDSTRING,0,(LPARAM)(LPCTSTR) pShim->szShimName);
  251. if ( LB_ERR != nIndex )
  252. SendDlgItemMessage(hDlg,IDC_LAYERLIST,LB_SETITEMDATA,nIndex,(LPARAM) pShim);
  253. }
  254. SyncList(hDlg,IDC_LAYERLIST,IDC_SHIMLIST);
  255. }
  256. break;
  257. case IDC_REMOVE:
  258. {
  259. int nItems[1024];
  260. int nCount;
  261. int nTotal;
  262. // Enumerate all the selected items and add them to the shim list
  263. nTotal = SendDlgItemMessage(hDlg,IDC_LAYERLIST,LB_GETSELITEMS,sizeof(nItems)/sizeof(int),(LPARAM) &nItems);
  264. for ( nCount=0; nCount < nTotal; ++nCount ) {
  265. PSHIMDESC pShim = (PSHIMDESC) SendDlgItemMessage(hDlg,IDC_LAYERLIST,LB_GETITEMDATA,nItems[nCount],0);
  266. int nIndex;
  267. nIndex = SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_ADDSTRING,0,(LPARAM)(LPCTSTR) pShim->szShimName);
  268. if ( LB_ERR != nIndex )
  269. SendDlgItemMessage(hDlg,IDC_SHIMLIST,LB_SETITEMDATA,nIndex,(LPARAM) pShim);
  270. }
  271. SyncList(hDlg,IDC_SHIMLIST,IDC_LAYERLIST);
  272. }
  273. break;
  274. case IDOK://DONE Button
  275. {
  276. PDBLAYER pLayer;
  277. // Creating a new layer list.
  278. TCHAR szText[MAX_PATH_BUFFSIZE];
  279. SendDlgItemMessage(hDlg,IDC_NAME,WM_GETTEXT,MAX_PATH,(LPARAM) szText);
  280. CSTRING strLayerName = szText;
  281. strLayerName.Trim();
  282. //
  283. //Check if the new name already exists, if yes give error.
  284. //
  285. if ( ( g_pLayer == NULL && CheckExistingLayer(strLayerName))
  286. ||
  287. (g_pLayer != NULL && g_pLayer->szLayerName != strLayerName && CheckExistingLayer(strLayerName) )
  288. )
  289. {
  290. MessageBox(hDlg,
  291. TEXT("A layer with the specified name already exists."),
  292. TEXT("Duplicate Layer"),
  293. MB_ICONWARNING
  294. );
  295. break;
  296. }
  297. if ( NULL == g_pLayer )
  298. pLayer = new DBLAYER;
  299. else {
  300. /*
  301. This will be called when this CustomLayerProc() has been called
  302. beause the user chose Edit or Remove Custom layer.
  303. In the member functions :
  304. 1. EditCustomLayer
  305. 2. RemoveCustomLayer
  306. g_pLayer is made NULL
  307. In EditLayerProc, The g_pLayer is set to the particular PDBLAYER entry in the linked list
  308. headed by g_theApp.pLayerList, which has the same name as the selectd layer
  309. */
  310. pLayer = g_pLayer;
  311. // Clear all the shims.
  312. while ( NULL != pLayer->pShimList ) {
  313. PSHIMDESC pHold = pLayer->pShimList->pNext;
  314. if ( pLayer->pShimList != NULL )
  315. delete pLayer->pShimList;
  316. pLayer->pShimList = pHold;
  317. }
  318. }
  319. if ( NULL != pLayer ) {
  320. int nCount;
  321. int nTotal;
  322. if ( NULL == g_pLayer )
  323. ZeroMemory(pLayer,sizeof(DBLAYER));
  324. SendDlgItemMessage(hDlg,IDC_NAME,WM_GETTEXT,MAX_PATH,(LPARAM) szText);
  325. TCHAR *pStart = szText,
  326. *pEnd = szText + lstrlen(szText) - 1,
  327. szNewText[MAX_PATH_BUFFSIZE];
  328. while ( *pStart== TEXT(' ') ) ++pStart;
  329. while ( (pEnd >= pStart) && ( *pEnd == TEXT(' ') ) ) --pEnd;
  330. *( pEnd + 1) = TEXT('\0');//Keep it safe
  331. if ( *pStart == TEXT('\0') ) {
  332. //This is just for protection, DONE will be disabled if the "Name " Text field is blank or has all spaces
  333. MessageBox(NULL,TEXT("Please give a valid name for the layer"),TEXT("Invalid layer name"),MB_ICONWARNING);
  334. }
  335. else {
  336. lstrcpyn(szNewText,pStart, MAX_PATH);
  337. if ( lstrcmpi(szText,szNewText) != 0 ) {
  338. SetWindowText(GetDlgItem(hDlg,IDC_NAME), szNewText);
  339. lstrcpyn(szText,szNewText,MAX_PATH);
  340. }
  341. }//else
  342. pLayer->szLayerName = szText;
  343. nTotal = SendDlgItemMessage(hDlg,IDC_LAYERLIST,LB_GETCOUNT,0,0);
  344. // Enumerate all the shims listed and add to the layer.
  345. for ( nCount=0; nCount < nTotal; ++nCount ) {
  346. PSHIMDESC pShim = (PSHIMDESC) SendDlgItemMessage(hDlg,IDC_LAYERLIST,LB_GETITEMDATA,nCount,0);
  347. PSHIMDESC pNew = new SHIMDESC;
  348. if ( NULL == pNew ) {
  349. MEM_ERR;
  350. break;
  351. //continue;
  352. }
  353. *pNew = *pShim;
  354. /*
  355. pNew->szShimName = pShim->szShimName;
  356. pNew->szShimDLLName = pShim->szShimDLLName;
  357. pNew->szShimCommandLine = pShim->szShimCommandLine;
  358. pNew->szShimDesc = pShim->szShimDesc;
  359. pNew->bShim = pNew->bShim;
  360. pNew->bPermanent = pNew->bPermanent;
  361. */
  362. pNew->pNext = pLayer->pShimList;
  363. pLayer->pShimList = pNew;
  364. }
  365. if ( NULL == g_pLayer )
  366. //CORRECTIT: That means this is a add option, better to check the mode of the class
  367. {
  368. pLayer->bPermanent = FALSE;
  369. pLayer->pNext = g_theApp.GetDBLocal().m_pLayerList;
  370. g_theApp.GetDBLocal().m_pLayerList = pLayer;
  371. }
  372. else if ( bNameChanged) {
  373. //
  374. //Replace the existing name in the DBRECORDs with the new name.
  375. //
  376. PDBRECORD pRecordApps = g_theApp.GetDBLocal().m_pRecordHead;
  377. while (pRecordApps) {
  378. PDBRECORD pRecordExe = pRecordApps;
  379. while (pRecordExe) {
  380. if (pRecordExe->szLayerName == szPresentLayerName) {
  381. pRecordExe->szLayerName = szText; // New name
  382. }
  383. pRecordExe = pRecordExe->pDup;
  384. }// while (pRecordExe)
  385. pRecordApps = pRecordApps->pNext;
  386. }//while (pRecordApps)
  387. }//else if ( bChanged)
  388. }
  389. EndDialog(hDlg,TRUE);
  390. }
  391. break;
  392. case IDCANCEL:
  393. {
  394. EndDialog(hDlg,FALSE);
  395. }
  396. break;
  397. }
  398. }
  399. return FALSE;
  400. }
  401. BOOL CALLBACK EditLayerProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  402. {
  403. switch ( uMsg ) {
  404. case WM_INITDIALOG:
  405. {
  406. switch ( g_pCustomLayer->m_uMode ) {
  407. case LAYERMODE_COPY:
  408. {
  409. SetWindowText(hDlg,TEXT("Select Mode To Copy"));
  410. }
  411. break;
  412. case LAYERMODE_EDIT:
  413. {
  414. SetWindowText(hDlg,TEXT("Edit Compatibility Mode"));
  415. }
  416. break;
  417. case LAYERMODE_REMOVE:
  418. {
  419. SetWindowText(hDlg,TEXT("Remove Compatibility Mode"));
  420. }
  421. break;
  422. }
  423. PDBLAYER pWalk = g_theApp.GetDBGlobal().m_pLayerList;
  424. for( int iLoop = 0; iLoop <= 1; ++ iLoop){
  425. while ( NULL != pWalk ) {
  426. //Add if this is a local/custom layer or we we want to show the layers(Permanent and custom),
  427. //because we are in copy layer option.
  428. if ( !pWalk->bPermanent || TRUE == lParam ) {
  429. int nIndex = SendDlgItemMessage(hDlg,IDC_LIST,LB_ADDSTRING,0,(LPARAM)(LPCTSTR)pWalk->szLayerName);
  430. if ( LB_ERR != nIndex )
  431. SendDlgItemMessage(hDlg,IDC_LIST,LB_SETITEMDATA,nIndex,(LPARAM) pWalk);
  432. }
  433. pWalk = pWalk->pNext;
  434. }
  435. pWalk = g_theApp.GetDBLocal().m_pLayerList;
  436. }//for
  437. // Force button update/ Make it disabled basically
  438. //SendMessage(hDlg,WM_COMMAND,IDC_LIST,0);
  439. //
  440. //Select the first item of the list box
  441. //
  442. SendMessage(
  443. (HWND) GetDlgItem(hDlg,IDC_LIST), // handle to destination window
  444. LB_SETCURSEL, // message to send
  445. (WPARAM) 0, // item index
  446. (LPARAM) 0 // not used; must be zero
  447. );
  448. SetFocus( GetDlgItem (hDlg, IDC_LIST) );
  449. }
  450. break;
  451. case WM_COMMAND:
  452. {
  453. switch ( LOWORD(wParam) ) {
  454. case IDC_LIST:
  455. {
  456. if ( LB_ERR == SendMessage(GetDlgItem(hDlg,IDC_LIST),LB_GETCURSEL,0,0) )
  457. EnableWindow(GetDlgItem(hDlg,IDOK),FALSE);
  458. else
  459. EnableWindow(GetDlgItem(hDlg,IDOK),TRUE);
  460. }
  461. break;
  462. case IDOK:
  463. {
  464. int nIndex = SendMessage(GetDlgItem(hDlg,IDC_LIST),LB_GETCURSEL,0,0);
  465. //Make g_pLayer point to the selected layer.
  466. g_pLayer = (PDBLAYER) SendDlgItemMessage(hDlg,IDC_LIST,LB_GETITEMDATA,nIndex,0);
  467. EndDialog(hDlg,1);
  468. }
  469. break;
  470. case IDCANCEL:
  471. EndDialog(hDlg,0);
  472. break;
  473. }
  474. }
  475. break;
  476. }
  477. return FALSE;
  478. }
  479. BOOL CheckExistingLayer(CSTRING & szNewLayerName)
  480. {
  481. PDBLAYER pLayer = g_theApp.GetDBLocal().m_pLayerList;
  482. while (pLayer != NULL) {
  483. if ( pLayer->szLayerName == szNewLayerName ) break;
  484. else pLayer = pLayer->pNext;
  485. }
  486. if (pLayer != NULL) return TRUE;
  487. pLayer = g_theApp.GetDBGlobal().m_pLayerList;
  488. while (pLayer != NULL) {
  489. if ( pLayer->szLayerName == szNewLayerName ) break;
  490. else pLayer = pLayer->pNext;
  491. }
  492. if (pLayer != NULL) return TRUE;
  493. return FALSE;
  494. }//CheckExistingLayer(CSTRING &)