static int GetMessIcon(int drvindex, int nSoftwareType) { int the_index = 0; int nIconPos = 0; HICON hIcon = 0; const game_driver *drv; char buffer[256]; const char *iconname; assert(drvindex >= 0); assert(drvindex < driver_list::total()); if ((nSoftwareType >= 0) && (nSoftwareType < IO_COUNT)) { iconname = device_image_interface::device_brieftypename((iodevice_t)nSoftwareType); the_index = (drvindex * IO_COUNT) + nSoftwareType; nIconPos = mess_icon_index[the_index]; if (nIconPos >= 0) { drv = &driver_list::driver(drvindex); while (drv) { _snprintf(buffer, ARRAY_LENGTH(buffer), "%s/%s", drv->name, iconname); hIcon = LoadIconFromFile(buffer); if (hIcon) break; int cl = driver_list::clone(*drv); if (cl!=-1) drv = &driver_list::driver(cl); else drv = NULL; } if (hIcon) { nIconPos = ImageList_AddIcon(GetSmallImageList(), hIcon); ImageList_AddIcon(GetLargeImageList(), hIcon); if (nIconPos != -1) mess_icon_index[the_index] = nIconPos; } } } return nIconPos; }
BOOL CreateMessIcons(void) { int i = 0; HWND hwndSoftwareList; HIMAGELIST hSmall; HIMAGELIST hLarge; // create the icon index, if we haven't already if (!mess_icon_index) { mess_icon_index = (int*)pool_malloc_lib(GetMameUIMemoryPool(), driver_list::total() * IO_COUNT * sizeof(*mess_icon_index)); } for (i = 0; i < (driver_list::total() * IO_COUNT); i++) mess_icon_index[i] = 0; // Associate the image lists with the list view control. hwndSoftwareList = GetDlgItem(GetMainWindow(), IDC_SWLIST); hSmall = GetSmallImageList(); hLarge = GetLargeImageList(); (void)ListView_SetImageList(hwndSoftwareList, hSmall, LVSIL_SMALL); (void)ListView_SetImageList(hwndSoftwareList, hLarge, LVSIL_NORMAL); return TRUE; }
BOOL CALLBACK PropDlg::run_dlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) { case WM_INITDIALOG: { /* set discription */ TCHAR szBuffer[256]; /* change language previously to avoid change of dynamic text*/ NLChangeDialog(_hInst, _hParent, _hSelf, _T("FavProp")); _stprintf(szBuffer, _T("%s:"), _pDesc); ::SetWindowText(::GetDlgItem(_hSelf, IDC_STATIC_FAVES_DESC), szBuffer); /* if name is not defined extract from link */ _tcscpy(szBuffer, _pLink); if ((_pName[0] == '\0') && (szBuffer[0] != '\0')) { if (szBuffer[_tcslen(szBuffer)-1] == '\\') { szBuffer[_tcslen(szBuffer)-1] = '\0'; } if (szBuffer[_tcslen(szBuffer)-1] == ':') { _tcscpy(_pName, szBuffer); } else { _tcscpy(_pName, (_tcsrchr(szBuffer, '\\')+1)); } } /* set name and link */ ::SetWindowText(::GetDlgItem(_hSelf, IDC_EDIT_NAME), _pName); ::SetWindowText(::GetDlgItem(_hSelf, IDC_EDIT_LINK), _pLink); SetFocus(::GetDlgItem(_hSelf, IDC_EDIT_NAME)); _hTreeCtrl = ::GetDlgItem(_hSelf, IDC_TREE_SELECT); goToCenter(); if (_linkDlg == LINK_DLG_NONE) { RECT rcName, rcLink; ::ShowWindow(::GetDlgItem(_hSelf, IDC_BTN_OPENDLG), SW_HIDE); ::GetWindowRect(::GetDlgItem(_hSelf, IDC_EDIT_NAME), &rcName); ::GetWindowRect(::GetDlgItem(_hSelf, IDC_EDIT_LINK), &rcLink); rcLink.right = rcName.right; ScreenToClient(_hSelf, &rcLink); ::SetWindowPos(::GetDlgItem(_hSelf, IDC_EDIT_LINK), NULL, rcLink.left, rcLink.top, rcLink.right-rcLink.left, rcLink.bottom-rcLink.top, SWP_NOZORDER); } if (_seeDetails == FALSE) { RECT rc = {0}; ::DestroyWindow(::GetDlgItem(_hSelf, IDC_TREE_SELECT)); ::DestroyWindow(::GetDlgItem(_hSelf, IDC_STATIC_SELECT)); ::DestroyWindow(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS)); /* resize window */ ::GetWindowRect(_hSelf, &rc); rc.top += 74; rc.bottom -= 74; /* resize window and keep sure to resize correct */ ::SetWindowPos(_hSelf, NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); } else { /* get current icon offset */ UINT iIconPos = _pElem->uParam & FAVES_PARAM; /* set image list */ ::SendMessage(_hTreeCtrl, TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)GetSmallImageList(FALSE)); HTREEITEM hItem = InsertItem(_pElem->pszName, iIconPos, _iUImgPos, 0, 0, TVI_ROOT, TVI_LAST, TRUE, (LPARAM)_pElem); TreeView_SelectItem(_hTreeCtrl, hItem); if (!NLGetText(_hInst, _hParent, _T("Details"), _szDetails, 20)) { _tcscpy(_szDetails, _T("Details %s")); } _stprintf(szBuffer, _szDetails, _T("<<")); ::SetWindowText(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), szBuffer); } break; } case WM_COMMAND : { switch (LOWORD(wParam)) { case IDC_BUTTON_DETAILS: { RECT rc = {0}; TCHAR szBuffer[20]; /* toggle visibility state */ _seeDetails ^= TRUE; /* resize window */ ::GetWindowRect(_hSelf, &rc); if (_seeDetails == FALSE) { ::ShowWindow(::GetDlgItem(_hSelf, IDC_TREE_SELECT), SW_HIDE); ::ShowWindow(::GetDlgItem(_hSelf, IDC_STATIC_SELECT), SW_HIDE); _stprintf(szBuffer, _szDetails, _T(">>")); ::SetWindowText(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), szBuffer); rc.bottom -= 148; } else { ::ShowWindow(::GetDlgItem(_hSelf, IDC_TREE_SELECT), SW_SHOW); ::ShowWindow(::GetDlgItem(_hSelf, IDC_STATIC_SELECT), SW_SHOW); _stprintf(szBuffer, _szDetails, _T("<<")); ::SetWindowText(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), szBuffer); rc.bottom += 148; } ::SetWindowPos(_hSelf, NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); break; } case IDC_BTN_OPENDLG: { if (_linkDlg == LINK_DLG_FOLDER) { // This code was copied and slightly modifed from: // http://www.bcbdev.com/faqs/faq62.htm // SHBrowseForFolder returns a PIDL. The memory for the PIDL is // allocated by the shell. Eventually, we will need to free this // memory, so we need to get a pointer to the shell malloc COM // object that will free the PIDL later on. LPMALLOC pShellMalloc = 0; if (::SHGetMalloc(&pShellMalloc) == NO_ERROR) { // If we were able to get the shell malloc object, // then proceed by initializing the BROWSEINFO stuct BROWSEINFO info; ZeroMemory(&info, sizeof(info)); info.hwndOwner = _hParent; info.pidlRoot = NULL; info.pszDisplayName = (LPTSTR)new TCHAR[MAX_PATH]; info.lpszTitle = _T("Select a folder:"); info.ulFlags = BIF_RETURNONLYFSDIRS; info.lpfn = BrowseCallbackProc; info.lParam = (LPARAM)_pLink; // Execute the browsing dialog. LPITEMIDLIST pidl = ::SHBrowseForFolder(&info); // pidl will be null if they cancel the browse dialog. // pidl will be not null when they select a folder. if (pidl) { // Try to convert the pidl to a display string. // Return is true if success. if (::SHGetPathFromIDList(pidl, _pLink)) { // Set edit control to the directory path. ::SetWindowText(::GetDlgItem(_hSelf, IDC_EDIT_LINK), _pLink); } pShellMalloc->Free(pidl); } pShellMalloc->Release(); delete [] info.pszDisplayName; } } else { LPTSTR pszLink = NULL; FileDlg dlg(_hInst, _hParent); dlg.setDefFileName(_pLink); if (_tcsstr(_pDesc, _T("Session")) != NULL) dlg.setExtFilter(_T("Session file"), _T(".session"), NULL); dlg.setExtFilter(_T("All types"), _T(".*"), NULL); if (_fileMustExist == TRUE) { pszLink = dlg.doSaveDlg(); } else { pszLink = dlg.doOpenSingleFileDlg(); } if (pszLink != NULL) { // Set edit control to the directory path. _tcscpy(_pLink, pszLink); ::SetWindowText(::GetDlgItem(_hSelf, IDC_EDIT_LINK), _pLink); } } break; } case IDCANCEL: { ::EndDialog(_hSelf, FALSE); return TRUE; } case IDOK: { UINT lengthName = ::SendDlgItemMessage(_hSelf, IDC_EDIT_NAME, WM_GETTEXTLENGTH, 0, 0) + 1; UINT lengthLink = ::SendDlgItemMessage(_hSelf, IDC_EDIT_LINK, WM_GETTEXTLENGTH, 0, 0) + 1; SendDlgItemMessage(_hSelf, IDC_EDIT_NAME, WM_GETTEXT, lengthName, (LPARAM)_pName); SendDlgItemMessage(_hSelf, IDC_EDIT_LINK, WM_GETTEXT, lengthLink, (LPARAM)_pLink); if ((_tcslen(_pName) != 0) && (_tcslen(_pLink) != 0)) { TCHAR pszGroupName[MAX_PATH]; GetFolderPathName(TreeView_GetSelection(_hTreeCtrl), pszGroupName); _strGroupName = pszGroupName; ::EndDialog(_hSelf, TRUE); return TRUE; } else { if (NLMessageBox(_hInst, _hParent, _T("MsgBox AllFields"), MB_OK) == FALSE) ::MessageBox(_hParent, _T("Fill out all fields!"), _T("Error"), MB_OK); } break; } default: break; } break; } case WM_SIZE: { RECT rc = {0}; RECT rcMain = {0}; /* get main window size */ ::GetWindowRect(_hSelf, &rcMain); /* resize static box */ ::GetWindowRect(::GetDlgItem(_hSelf, IDC_STATIC_FAVES_DESC), &rc); rc.bottom = rcMain.bottom - 46; ScreenToClient(_hSelf, &rc); ::SetWindowPos(::GetDlgItem(_hSelf, IDC_STATIC_FAVES_DESC), NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); /* set position of OK button */ ::GetWindowRect(::GetDlgItem(_hSelf, IDOK), &rc); rc.top = rcMain.bottom - 36; rc.bottom = rcMain.bottom - 12; ScreenToClient(_hSelf, &rc); ::SetWindowPos(::GetDlgItem(_hSelf, IDOK), NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); /* set position of CANCEL button */ ::GetWindowRect(::GetDlgItem(_hSelf, IDCANCEL), &rc); rc.top = rcMain.bottom - 36; rc.bottom = rcMain.bottom - 12; ScreenToClient(_hSelf, &rc); ::SetWindowPos(::GetDlgItem(_hSelf, IDCANCEL), NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); /* set position of DETAILS button */ ::GetWindowRect(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), &rc); rc.top = rcMain.bottom - 36; rc.bottom = rcMain.bottom - 12; ScreenToClient(_hSelf, &rc); ::SetWindowPos(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); break; } case WM_NOTIFY: { LPNMHDR nmhdr = (LPNMHDR)lParam; if (nmhdr->hwndFrom == _hTreeCtrl) { switch (nmhdr->code) { case TVN_ITEMEXPANDING: { DWORD dwpos = ::GetMessagePos(); TVHITTESTINFO ht; HTREEITEM hItem; ht.pt.x = GET_X_LPARAM(dwpos); ht.pt.y = GET_Y_LPARAM(dwpos); ::ScreenToClient(_hTreeCtrl, &ht.pt); hItem = TreeView_HitTest(_hTreeCtrl, &ht); if (hItem != NULL) { if (!TreeView_GetChild(_hTreeCtrl, hItem)) { DrawChildrenOfItem(hItem); } } break; } case TVN_SELCHANGED: { /* only when link params are also viewed */ if (_bWithLink == TRUE) { HTREEITEM hItem = TreeView_GetSelection(_hTreeCtrl); if (hItem != NULL) { PELEM pElem = (PELEM)GetParam(hItem); if (pElem != NULL) { if (pElem->uParam & FAVES_PARAM_LINK) { ::SetDlgItemText(_hSelf, IDC_EDIT_NAME, pElem->pszName); ::SetDlgItemText(_hSelf, IDC_EDIT_LINK, pElem->pszLink); } else { ::SetDlgItemText(_hSelf, IDC_EDIT_NAME, _T("")); ::SetDlgItemText(_hSelf, IDC_EDIT_LINK, _T("")); } } } } break; } default: break; } } break; } case WM_DESTROY : { /* deregister this dialog */ ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (LPARAM)_hSelf); break; } default: break; } return FALSE; }