int CALLBACK compare_func(LPARAM lparam1, LPARAM lparam2,struct find_helper *fh) { LV_FINDINFO find1,find2; char str1[512]={0},str2[512]={0}; int index1,index2; find1.flags=LVFI_PARAM; find1.lParam=lparam1; find2.flags=LVFI_PARAM; find2.lParam=lparam2; index1=ListView_FindItem(fh->hlistview,-1,&find1); index2=ListView_FindItem(fh->hlistview,-1,&find2); if(index1>=0 && index2>=0){ int result; ListView_GetItemText(fh->hlistview,index1,fh->col,str1,sizeof(str1)); ListView_GetItemText(fh->hlistview,index2,fh->col,str2,sizeof(str2)); result=_stricmp(str1,str2); if(fh->dir) result=-result; return result; } return 0; }
void InterfaceRemoveList(int session_id) { LV_FINDINFO lvf; int index; lvf.flags = LVFI_PARAM; lvf.lParam = session_id; index = ListView_FindItem(hwndLV,-1,&lvf); if (index >= 0) { ListView_DeleteItem(hwndLV,index); } }
void UpdateFileInfoStatus(FILEINFO *pFileinfo, const HWND hwndListView) { pFileinfo->status = InfoToIntValue(pFileinfo); SetFileInfoStrings(pFileinfo, pFileinfo->parentList); if(g_program_options.bHideVerified && pFileinfo->status == STATUS_OK) { LVFINDINFO findInfo; ZeroMemory(&findInfo, sizeof(LVFINDINFO)); findInfo.flags = LVFI_PARAM; findInfo.lParam = (LPARAM)pFileinfo; int pos = ListView_FindItem(hwndListView, -1, &findInfo); if(pos >= 0) ListView_DeleteItem(hwndListView, pos); } }
int DBSettingChanged(WPARAM wParam,LPARAM lParam) { DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam; HANDLE hContact = (HANDLE)wParam; char *setting; SettingListInfo* info; if (hwnd2mainWindow) { HWND hwnd2Settings = GetDlgItem(hwnd2mainWindow, IDC_SETTINGS); if (info = (SettingListInfo*)GetWindowLongPtr(hwnd2Settings, GWLP_USERDATA)) { if ((hContact == info->hContact) && !mir_strcmp(info->module, cws->szModule)) { setting = mir_strdup(cws->szSetting); if (cws->value.type == DBVT_DELETED) { LVFINDINFO lvfi; int index; lvfi.flags = LVFI_STRING; lvfi.psz = setting; lvfi.vkDirection = VK_DOWN; index = ListView_FindItem(hwnd2Settings, -1, &lvfi); if (index > -1) ListView_DeleteItem(hwnd2Settings, index); mir_free(setting); return 0; } settingChanged(hwnd2Settings, hContact, info->module, setting); mir_free(setting); } } } // watch list if (!hwnd2watchedVarsWindow && !usePopups) return 0; for (int i = 0; i < WatchListArray.count; i++) { if (WatchListArray.item[i].module && (hContact == WatchListArray.item[i].hContact)) { if (!mir_strcmp(cws->szModule, WatchListArray.item[i].module)) { if (!WatchListArray.item[i].setting || !mir_strcmp(cws->szSetting, WatchListArray.item[i].setting)) { if (usePopups) popupWatchedVar(hContact, cws->szModule, cws->szSetting); if (hwnd2watchedVarsWindow) PopulateWatchedWindow(GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS)); break; } } } } return 0; }
//===================================================================================== // // * Function : RightCommand() // * Description // 이 함수는 위의 ChildRightProc콜백함수의 WM_COMMAND메시지에 대응하는 메시지 처리 함수 // 이다. // //===================================================================================== LRESULT RightCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { struct tag_ip { TCHAR ip[20]; TCHAR mac[20]; TCHAR vendor[50]; TCHAR time[50]; TCHAR host[50]; } IpAdd[]={ {NULL,NULL,NULL,NULL,NULL}, }; TCHAR szIP[255]; int idx; /*hImgSm = ImageList_LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BIT_VIEW_16), 16,2,RGB(255,255,255)); SendMessage(hList, LVM_SETIMAGELIST,(WPARAM)LVSIL_SMALL, (LPARAM)hImgSm);*/ switch (LOWORD(wParam)) { // 선택한 항목을 방어한다. case IDC_DEF: DialogBox(g_hInst,MAKEINTRESOURCE(IDD_DIALOG_DEFENCE),hWnd,DefenceDlgProc); return TRUE; // IP로 항목을 검색한다. case IDC_FIND: LVFINDINFO fi; GetDlgItemText(hWnd,IDC_IP,szIP,255); fi.flags=LVFI_STRING; fi.psz=szIP; fi.vkDirection=VK_DOWN; idx=ListView_FindItem(hList,-1,&fi); if (idx==-1) { MessageBox(hWnd,TEXT("동일한 ip 없습니다"),TEXT("알림"),MB_OK); } else { ListView_SetItemState(hList,-1,0,LVIS_FOCUSED | LVIS_SELECTED); ListView_SetItemState(hList,idx,LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); ListView_EnsureVisible(hList,idx,FALSE); } return TRUE; } return 0; }
/* * ListView_FindItem() Macro: Searches for a list-view item with the specified * characteristics. Returns the index of the item if successful, or -1 otherwise */ static BOOL CheckListViewFilenameExists(HWND hwndList, LPCTSTR tszFileName) { LVFINDINFO lvfi; int retVal; lvfi.flags = LVFI_STRING; /* Search item by EXACT string */ lvfi.psz = tszFileName; /* String to search */ /* Other items of this structure are not valid, besacuse flags are not set. */ retVal = ListView_FindItem(hwndList, -1, &lvfi); if (retVal != -1) return TRUE; /* item found! */ return FALSE; /* item not found. */ }
//============================================================================= // // DirList_SelectItem() // // Select specified item in the list // BOOL DirList_SelectItem(HWND hwnd,LPCWSTR lpszDisplayName,LPCWSTR lpszFullPath) { #define LVIS_FLAGS LVIS_SELECTED|LVIS_FOCUSED WCHAR szShortPath[MAX_PATH]; SHFILEINFO shfi; LV_FINDINFO lvfi; DLITEM dli; int i = -1; if (!lpszFullPath || !lstrlen(lpszFullPath)) return(FALSE); else GetShortPathName(lpszFullPath,szShortPath,MAX_PATH); if (!lpszDisplayName || !lstrlen(lpszDisplayName)) SHGetFileInfo(lpszFullPath,0,&shfi,sizeof(SHFILEINFO),SHGFI_DISPLAYNAME); else lstrcpyn(shfi.szDisplayName,lpszDisplayName,MAX_PATH); lvfi.flags = LVFI_STRING; lvfi.psz = shfi.szDisplayName; dli.mask = DLI_ALL; while ((i = ListView_FindItem(hwnd,i,&lvfi)) != -1) { DirList_GetItem(hwnd,i,&dli); GetShortPathName(dli.szFileName,dli.szFileName,MAX_PATH); if (!lstrcmpi(dli.szFileName,szShortPath)) { ListView_SetItemState(hwnd,i,LVIS_FLAGS,LVIS_FLAGS); ListView_EnsureVisible(hwnd,i,FALSE); return(TRUE); } } return(FALSE); }
static void MessRefreshPicker(void) { HWND hwndSoftware; int i = 0; LVFINDINFO lvfi; const char *s; windows_options o; hwndSoftware = GetDlgItem(GetMainWindow(), IDC_SWLIST); s_bIgnoreSoftwarePickerNotifies = TRUE; // Now clear everything out; this may call back into us but it should not // be problematic ListView_SetItemState(hwndSoftware, -1, 0, LVIS_SELECTED); for (device_image_interface &dev : image_interface_iterator(s_config->mconfig->root_device())) { const char *opt_name = dev.instance_name(); // get name of device slot load_options(o, OPTIONS_GAME, s_config->driver_index); s = o.value(opt_name); // get name of software in the slot if (s[0]) // if software is loaded { i = SoftwarePicker_LookupIndex(hwndSoftware, s); // see if its in the picker if (i < 0) // not there { // add already loaded software to picker, but not if its already there SoftwarePicker_AddFile(hwndSoftware, s, 1); i = SoftwarePicker_LookupIndex(hwndSoftware, s); // refresh pointer } if (i >= 0) // is there { memset(&lvfi, 0, sizeof(lvfi)); lvfi.flags = LVFI_PARAM; lvfi.lParam = i; i = ListView_FindItem(hwndSoftware, -1, &lvfi); ListView_SetItemState(hwndSoftware, i, LVIS_SELECTED, LVIS_SELECTED); // highlight it } } } s_bIgnoreSoftwarePickerNotifies = FALSE; }
int CShellBrowser::LocateFileItemIndex(const TCHAR *szFileName) const { LV_FINDINFO lvFind; int iItem; int iInternalIndex; iInternalIndex = LocateFileItemInternalIndex(szFileName); if(iInternalIndex != -1) { lvFind.flags = LVFI_PARAM; lvFind.lParam = iInternalIndex; iItem = ListView_FindItem(m_hListView,-1,&lvFind); return iItem; } return -1; }
void CBuddyManager::NotifyBuddyIsOffline(BUDDY_INFO *pBI, SERVER_INFO *pServerInfo) { if(pBI==NULL) return; if(pServerInfo==NULL) return; vecBI::iterator it = FindBuddyInfoByID(pBI->dwID); if(it==BuddyList.end()) return; strcpy_s(it->szServerName,sizeof(pBI->szServerName)," "); it->sIndex = (int) -1; //have to change the Buddy index to a new var that can hold bigger numbers such as DWORD it->pSI = NULL; LV_FINDINFO lvfi; char szText[250]; memset(&lvfi,0,sizeof(LV_FINDINFO)); lvfi.flags = LVFI_PARAM; lvfi.lParam = (LPARAM)pBI->dwID; int index = ListView_FindItem(g_hwndListBuddy , -1, &lvfi); if(index!=-1) { LVITEM item; item.mask = LVIF_TEXT | LVIF_IMAGE ; item.iItem = index; memset(szText,0,sizeof(szText)); item.iImage = -1; item.pszText = it->szServerName; item.cchTextMax = (int)strlen(it->szServerName); item.iSubItem = 1; ListView_SetItem(g_hwndListBuddy,&item); strcpy_s(it->szIPaddress," "); ListView_SetItemText(g_hwndListBuddy,index ,2,szText); } }
/*---------------------------------------------------------------------------------------------- Process notifications for this dialog from some event on a control. This method is called by the framework. @param ctid Id of the control that issued the windows command. @param pnmh Windows command that is being passed. @param lnRet return value to be returned to the windows command. @return true if command is handled. See ${AfStylesDlg#OnNotifyChild} ----------------------------------------------------------------------------------------------*/ bool TeStylesDlg::OnNotifyChild(int ctid, NMHDR * pnmh, long & lnRet) { switch(pnmh->code) { case CBN_SELCHANGE: { // User changes combo box to show filtered list or all styles // First, save the values. This is done easiest by calling UpdateTabCtrl UpdateTabCtrl(-1, -1); // force styles listbox to be refilled UpdateStyleList(); // check if selected style is still shown, otherwise select first visible int iListItem; // Index in the listview. if (SkipStyle(m_istyiSelected)) { // select first item in the styles list iListItem = 0; } else { // re-select old item LVFINDINFO plvfi; plvfi.lParam = m_istyiSelected; plvfi.flags = LVFI_PARAM; iListItem = ListView_FindItem(m_hwndStylesList, -1, &plvfi); } // select an item DWORD dwT = LVIS_SELECTED | LVIS_FOCUSED; ListView_SetItemState(m_hwndStylesList, iListItem, dwT, dwT); // Make sure that it is visible ListView_EnsureVisible(m_hwndStylesList, iListItem, false); lnRet = 0; return true; } default: break; } return SuperClass::OnNotifyChild(ctid, pnmh, lnRet); }
void InterfaceUpdateList(int session_id) { session_node *s; char buf[20]; LV_FINDINFO lvf; int index; EnterServerLock(); s = GetSessionByID(session_id); if (s == NULL) { LeaveServerLock(); return; } lvf.flags = LVFI_PARAM; lvf.lParam = session_id; index = ListView_FindItem(hwndLV,-1,&lvf); if (index >= 0) { if (s->account == NULL) { ListView_SetItemText(hwndLV,index,0," ?"); ListView_SetItemText(hwndLV,index,1,""); } else { sprintf(buf,"%3i",s->account->account_id); ListView_SetItemText(hwndLV,index,0,buf); ListView_SetItemText(hwndLV,index,1,s->account->name); } ListView_SetItemText(hwndLV,index,2,ShortTimeStr(s->connected_time)); ListView_SetItemText(hwndLV,index,3,GetStateName(s)); ListView_SetItemText(hwndLV,index,4,s->conn.name); } LeaveServerLock(); }
VOID SetValueName(HWND hwndLV, LPCWSTR pszValueName) { INT i, c; LVFINDINFOW fi; c = ListView_GetItemCount(hwndLV); for(i = 0; i < c; i++) { ListView_SetItemState(hwndLV, i, 0, LVIS_FOCUSED | LVIS_SELECTED); } if (pszValueName == NULL) i = 0; else { fi.flags = LVFI_STRING; fi.psz = pszValueName; i = ListView_FindItem(hwndLV, -1, &fi); } ListView_SetItemState(hwndLV, i, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); iListViewSelect = i; }
void Picker_Sort(HWND hwndPicker) { LV_FINDINFO lvfi; struct PickerInfo *pPickerInfo; struct CompareProcParams params; int nItem; pPickerInfo = GetPickerInfo(hwndPicker); // populate the CompareProcParams structure Picker_PopulateCompareProcParams(hwndPicker, ¶ms); ListView_SortItems(hwndPicker, Picker_CompareProc, (LPARAM) ¶ms); Picker_ResetHeaderSortIcon(hwndPicker); memset(&lvfi, 0, sizeof(lvfi)); lvfi.flags = LVFI_PARAM; lvfi.lParam = Picker_GetSelectedItem(hwndPicker); nItem = ListView_FindItem(hwndPicker, -1, &lvfi); ListView_EnsureVisible(hwndPicker, nItem, FALSE); }
//================================================================================================ //-------------------------------------+++--> Gather Status Info About the Timers User is Watching: BOOL OnWatchTimer(HWND hDlg) //-----------------------------------------------+++--> { HWND hList=GetDlgItem(hDlg,IDC_LIST); char szStatus[MIN_BUFF]; BOOL bNeeded = FALSE; LVFINDINFO lvFind; LVITEM lvItem; int id; for(id=m_timers; id--; ) { if(m_timer[id].bHomeless) { int iF; GetTimerInfo(szStatus,id); lvFind.flags = LVFI_STRING; lvFind.psz = m_timer[id].name; if((iF = ListView_FindItem(hList, -1, &lvFind)) != -1) { ListView_SetItemText(hList, iF, 1, szStatus); // IF Timer Pre-Exists, bNeeded = TRUE; //------------+++--> Update the Existing Timer Entry. } else { //---------------------+++--> ELSE Add the New Timer Entry to Watch List. lvItem.mask = LVIF_TEXT; lvItem.iSubItem = 0; lvItem.iItem = 0; lvItem.pszText = m_timer[id].name; ListView_InsertItem(hList, &lvItem); lvItem.iSubItem = 1; lvItem.pszText = szStatus; ListView_SetItem(hList, &lvItem); bNeeded = TRUE; } } } return bNeeded; }
/////////////////////////////////////////////////////////////////////////////////////////// // Function: NLSDlgProc // // Description: Message-processing function for text tab // // Comments: // /////////////////////////////////////////////////////////////////////////////////////////// INT_PTR CALLBACK NLSDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { BOOL bProcessedMsg = TRUE; switch(uMsg) { case WM_INITDIALOG: { LVCOLUMN lvcCol = {0}; UINT lcid = 0; LVFINDINFO lvInfo = {0}; int iItem = 0; // load our own icon SendMessage(GetParent(hDlg), WM_SETICON, ICON_BIG, (LPARAM) (LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_MAINICON)))); // Create our list column for the listview control g_hwndList = GetDlgItem(hDlg, IDC_LV_LCID); g_hDlg = hDlg; lvcCol.mask = LVCF_TEXT; LoadString(g_hRes, STR_LANGID, g_tcsTemp, MAX_STR); lvcCol.pszText = g_tcsTemp; ListView_InsertColumn(g_hwndList, COLUMN_LANGID, (LV_COLUMN *)&lvcCol); LoadString(g_hRes, STR_LANG, g_tcsTemp, MAX_STR); lvcCol.pszText = g_tcsTemp; ListView_InsertColumn(g_hwndList, COLUMN_LANGUAGE, (LV_COLUMN *)&lvcCol); LoadString(g_hRes, STR_NLANG, g_tcsTemp, MAX_STR); lvcCol.pszText = g_tcsTemp; ListView_InsertColumn(g_hwndList, COLUMN_NATIVELANG, (LV_COLUMN *)&lvcCol); LoadString(g_hRes, STR_NCOUNTRY, g_tcsTemp, MAX_STR); lvcCol.pszText = g_tcsTemp; ListView_InsertColumn(g_hwndList, COLUMN_NATIVECOUNTRYREGION, (LV_COLUMN *)&lvcCol); LoadString(g_hRes, STR_ACP, g_tcsTemp, MAX_STR); lvcCol.pszText = g_tcsTemp; ListView_InsertColumn(g_hwndList, COLUMN_ACP, (LV_COLUMN *)&lvcCol); LoadString(g_hRes, STR_OEMCP, g_tcsTemp, MAX_STR); lvcCol.pszText = g_tcsTemp; ListView_InsertColumn(g_hwndList, COLUMN_OEMCP, (LV_COLUMN *)&lvcCol); // fill out our listview control with available locales (supported ones). EnumSystemLocales(EnumLocalesProc, LCID_SUPPORTED); // Initialize formatting fields related to the selected locale in the listview InitNLSFields(hDlg, LOCALE_USER_DEFAULT); // Set the column width of the listview control. ListView_SetColumnWidth(g_hwndList, COLUMN_LANGID, LVSCW_AUTOSIZE_USEHEADER); ListView_SetColumnWidth(g_hwndList, COLUMN_LANGUAGE, LVSCW_AUTOSIZE_USEHEADER); ListView_SetColumnWidth(g_hwndList, COLUMN_NATIVELANG, LVSCW_AUTOSIZE_USEHEADER); ListView_SetColumnWidth(g_hwndList, COLUMN_NATIVECOUNTRYREGION, LVSCW_AUTOSIZE_USEHEADER); ListView_SetColumnWidth(g_hwndList, COLUMN_ACP, LVSCW_AUTOSIZE_USEHEADER); ListView_SetColumnWidth(g_hwndList, COLUMN_OEMCP, LVSCW_AUTOSIZE_USEHEADER); // Find user's current locale and select that item in the listview control. lcid = GetUserDefaultLCID(); // Our list has all the LCIDs in 4 digits (0409) whereas GetUserDefaultLCID returs (409). if (lcid < 0x1000) { _sntprintf(g_tcsTemp,MAX_STR,TEXT("0%x"), lcid); } else { _sntprintf(g_tcsTemp,MAX_STR,TEXT("%x"), lcid); } lvInfo.flags = LVFI_STRING; lvInfo.psz = g_tcsTemp; iItem = ListView_FindItem(g_hwndList, 0, &lvInfo); ListView_SetItemState (g_hwndList, iItem, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); ListView_EnsureVisible(g_hwndList, iItem, FALSE); // Set some of the extended styles of our list view (cool reports ;-) ListView_SetExtendedListViewStyle(g_hwndList, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | LVS_EX_GRIDLINES | LVS_EX_TWOCLICKACTIVATE); } break; case WM_NOTIFY: switch (((NMHDR *)lParam)->code) { case LVN_COLUMNCLICK: { NM_LISTVIEW nmv; static int iLastSort = COLUMN_LANGID; LPARAM lSortParam = -1; LVFINDINFO lvInfo; int iItem; // When a column is clicked we need to redo our sorting of preview table. nmv = *(const NM_LISTVIEW *) lParam; // We don't sort for native language and native country name (avoid confusion). if ((nmv.iSubItem == COLUMN_NATIVELANG) || (nmv.iSubItem == COLUMN_NATIVECOUNTRYREGION)) { break; } // If our last sorting was on a different column, we need to do more // than simply reverting our sorting. // Because of listview sorting limitations, we need to redo our list... if (iLastSort != nmv.iSubItem) { // The list view sorting is based on a q-sort, we need to redo our list! ListView_DeleteAllItems(g_hwndList); g_iCounter = 0; EnumSystemLocales(EnumLocalesProc, LCID_SUPPORTED); // Make sure the last selection remains active after sorting... if (g_iCurLocale < 0x1000) { _sntprintf(g_tcsTemp,MAX_STR,TEXT("0%x"), g_iCurLocale); } else { _sntprintf(g_tcsTemp,MAX_STR,TEXT("%x"), g_iCurLocale); } lvInfo.flags = LVFI_STRING; lvInfo.psz = g_tcsTemp; iItem = ListView_FindItem(g_hwndList, 0, &lvInfo); ListView_SetItemState (g_hwndList, iItem, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); // Update our flag for the last column sorted and set the sorting flag iLastSort = nmv.iSubItem; lSortParam = iLastSort; } // Do the actual sorting... ListView_SortItems(g_hwndList, (PFNLVCOMPARE)CompareFunc, lSortParam); // Make sure our selection is visible after the sorting! ListView_EnsureVisible(g_hwndList, ListView_GetSelectionMark(g_hwndList), FALSE); } break; case LVN_ITEMCHANGED: /* fall-through */ case LVN_ITEMACTIVATE: { LPNM_LISTVIEW lpnmlv = (LPNM_LISTVIEW)lParam; static int iItem; LVITEM lvItem = {0}; // Item selection has been changed. // Find the new langId and update our formatting fields... if (iItem != lpnmlv->iItem) { iItem = lpnmlv->iItem; lvItem.mask = LVIF_TEXT; lvItem.iItem = iItem; lvItem.pszText = g_tcsTemp; lvItem.cchTextMax = STR_LEN; ListView_GetItem(g_hwndList, &lvItem); g_iCurLocale = iConvertStrToInt(lvItem.pszText); InitNLSFields(hDlg, g_iCurLocale); } // Show advanced data on the selected locale... if (((NMHDR *)lParam)->code == LVN_ITEMACTIVATE) { bProcessedMsg = (DialogBox(g_hRes, MAKEINTRESOURCE(DLG_LCID), hDlg, LcidDlgProc) != -1); } } break; } break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: /* fall-through*/ case IDOK: break; case IDC_TIMEFORMAT: { if(HIWORD(wParam) == CBN_SELCHANGE) { // Time formating selection has been changed. // Re-edit time HWND hList = NULL; LRESULT index = 0; TCHAR tcTemp[MAX_STR]; hList = GetDlgItem(hDlg, IDC_TIMEFORMAT); if(NULL == hList) { bProcessedMsg = FALSE; break; } index = SendMessage(hList, CB_GETCURSEL, 0, 0); SendMessage(hList, CB_GETLBTEXT, index, (LPARAM) g_tcsTemp); GetTimeFormat(g_iCurLocale, 0, NULL, g_tcsTemp, tcTemp, MAX_STR); SetWindowText(GetDlgItem(hDlg, IDC_TIMESAMPLE), tcTemp); } } break; case IDC_SDATEFORMAT: { if(HIWORD(wParam) == CBN_SELCHANGE) { // short date formating selection has been changed. // Re-edit short date HWND hList = NULL; LRESULT index = 0; TCHAR tcTemp[MAX_STR]; hList = GetDlgItem(hDlg, IDC_SDATEFORMAT); if(NULL == hList) { bProcessedMsg = FALSE; break; } index = SendMessage(hList, CB_GETCURSEL, 0, 0); SendMessage(hList, CB_GETLBTEXT, index, (LPARAM) g_tcsTemp); GetDateFormat(g_iCurLocale, 0, NULL, g_tcsTemp, tcTemp, MAX_STR); SetWindowText(GetDlgItem(hDlg, IDC_SDATESAMPLE), tcTemp); } } break; case IDC_LDATEFORMAT: { if(HIWORD(wParam) == CBN_SELCHANGE) { // long date formating selection has been changed. // Re-edit long date HWND hList = NULL; LRESULT index = 0; TCHAR tcTemp[MAX_STR]; hList = GetDlgItem(hDlg, IDC_LDATEFORMAT); if(NULL == hList) { bProcessedMsg = FALSE; break; } index = SendMessage(hList, CB_GETCURSEL, 0, 0); SendMessage(hList, CB_GETLBTEXT, index, (LPARAM) g_tcsTemp); GetDateFormat(g_iCurLocale, 0, NULL, g_tcsTemp, tcTemp, MAX_STR); SetWindowText(GetDlgItem(hDlg, IDC_LDATESAMPLE), tcTemp); } } break; } break; default: bProcessedMsg = FALSE; } return bProcessedMsg; }
static BOOL CreateNewValue(HKEY hRootKey, LPCTSTR pszKeyPath, DWORD dwType) { TCHAR szNewValueFormat[128]; TCHAR szNewValue[128]; int iIndex = 1; BYTE data[128]; DWORD dwExistingType, cbData; LONG lResult; HKEY hKey; LVFINDINFO lvfi; if (RegOpenKeyEx(hRootKey, pszKeyPath, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey) != ERROR_SUCCESS) return FALSE; LoadString(hInst, IDS_NEW_VALUE, szNewValueFormat, COUNT_OF(szNewValueFormat)); do { wsprintf(szNewValue, szNewValueFormat, iIndex++); cbData = sizeof(data); lResult = RegQueryValueEx(hKey, szNewValue, NULL, &dwExistingType, data, &cbData); } while(lResult == ERROR_SUCCESS); switch(dwType) { case REG_DWORD: cbData = sizeof(DWORD); break; case REG_SZ: case REG_EXPAND_SZ: cbData = sizeof(TCHAR); break; case REG_MULTI_SZ: cbData = sizeof(TCHAR) * 2; break; case REG_QWORD: cbData = sizeof(DWORD) * 2; break; default: cbData = 0; break; } memset(data, 0, cbData); lResult = RegSetValueEx(hKey, szNewValue, 0, dwType, data, cbData); RegCloseKey(hKey); if (lResult != ERROR_SUCCESS) { return FALSE; } RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath); /* locate the newly added value, and get ready to rename it */ memset(&lvfi, 0, sizeof(lvfi)); lvfi.flags = LVFI_STRING; lvfi.psz = szNewValue; iIndex = ListView_FindItem(g_pChildWnd->hListWnd, -1, &lvfi); if (iIndex >= 0) (void)ListView_EditLabel(g_pChildWnd->hListWnd, iIndex); return TRUE; }
static BOOL CreateNewValue(HKEY hRootKey, LPCWSTR pszKeyPath, DWORD dwType) { WCHAR szNewValueFormat[128]; WCHAR szNewValue[128]; int iIndex = 1; BYTE data[128]; DWORD dwExistingType, cbData; LONG lResult; HKEY hKey; LVFINDINFO lvfi; if (RegOpenKeyExW(hRootKey, pszKeyPath, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey) != ERROR_SUCCESS) return FALSE; LoadStringW(hInst, IDS_NEW_VALUE, szNewValueFormat, COUNT_OF(szNewValueFormat)); do { wsprintf(szNewValue, szNewValueFormat, iIndex++); cbData = sizeof(data); lResult = RegQueryValueExW(hKey, szNewValue, NULL, &dwExistingType, data, &cbData); } while(lResult == ERROR_SUCCESS); switch(dwType) { case REG_DWORD: cbData = sizeof(DWORD); break; case REG_SZ: case REG_EXPAND_SZ: cbData = sizeof(WCHAR); break; case REG_MULTI_SZ: /* * WARNING: An empty multi-string has only one null char. * Indeed, multi-strings are built in the following form: * str1\0str2\0...strN\0\0 * where each strI\0 is a null-terminated string, and it * ends with a terminating empty string. * Therefore an empty multi-string contains only the terminating * empty string, that is, one null char. */ cbData = sizeof(WCHAR); break; case REG_QWORD: /* REG_QWORD_LITTLE_ENDIAN */ cbData = sizeof(DWORDLONG); // == sizeof(DWORD) * 2; break; default: cbData = 0; break; } memset(data, 0, cbData); lResult = RegSetValueExW(hKey, szNewValue, 0, dwType, data, cbData); RegCloseKey(hKey); if (lResult != ERROR_SUCCESS) { return FALSE; } RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath); /* locate the newly added value, and get ready to rename it */ memset(&lvfi, 0, sizeof(lvfi)); lvfi.flags = LVFI_STRING; lvfi.psz = szNewValue; iIndex = ListView_FindItem(g_pChildWnd->hListWnd, -1, &lvfi); if (iIndex >= 0) (void)ListView_EditLabel(g_pChildWnd->hListWnd, iIndex); return TRUE; }
/* * VerbAliasDialogProc: Dialog procedure for command verb alias dialog. */ BOOL CALLBACK VerbAliasDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam) { switch (message) { case WM_INITDIALOG: SendDlgItemMessage(hDlg, IDC_VERB, EM_LIMITTEXT, MAX_VERBLEN, 0L); SendDlgItemMessage(hDlg, IDC_EXPANSION, EM_LIMITTEXT, MAX_ALIASLEN, 0L); // Prepare list of aliases currently defined. { LV_COLUMN lvcol; HWND hList; int i; // Prepare list of aliases. hList = GetDlgItem(hDlg, IDC_COMMAND_LIST); SetWindowFont(hList, GetFont(FONT_LIST), FALSE); SetWindowLong(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) | LVS_SHOWSELALWAYS); // Add column headings lvcol.mask = LVCF_TEXT | LVCF_WIDTH; lvcol.pszText = GetString(hInst, IDS_AHEADER0); lvcol.cx = 60; ListView_InsertColumn(hList, 0, &lvcol); lvcol.pszText = GetString(hInst, IDS_AHEADER1); lvcol.cx = 220; ListView_InsertColumn(hList, 1, &lvcol); // Add aliases for (i = 0; i < _nVerbAliases; i++) { if (_apVerbAliases[i].verb[0]) { LV_ITEM lvitem; // Add item for verb. lvitem.mask = LVIF_TEXT; lvitem.iItem = ListView_GetItemCount(hList); lvitem.iSubItem = 0; lvitem.pszText = _apVerbAliases[i].verb; lvitem.iItem = ListView_InsertItem(hList, &lvitem); // Add subitem for command. lvitem.mask = LVIF_TEXT; lvitem.iSubItem = 1; lvitem.pszText = _apVerbAliases[i].text; ListView_SetItem(hList, &lvitem); } } } // Dialog is up. hAliasDialog = hDlg; hAliasDialog2 = hDlg; if (hAliasDialog1) DestroyWindow(GetDlgItem(hDlg, IDC_TUNNEL)); CenterWindow(hDlg, GetParent(hDlg)); return TRUE; case WM_NOTIFY: if (wParam != IDC_COMMAND_LIST) { return TRUE; } else { NM_LISTVIEW* pnm = (NM_LISTVIEW*)lParam; LV_HITTESTINFO lvhit; LV_KEYDOWN* plvkey; HWND hList; int i; if (!pnm) break; // Prepare list of aliases. hList = GetDlgItem(hDlg, IDC_COMMAND_LIST); switch (pnm->hdr.code) { case NM_CLICK: { VerbAlias alias; LV_ITEM lvitem; HWND hList; hList = GetDlgItem(hDlg, IDC_COMMAND_LIST); // If you click anywhere on an item. GetCursorPos(&lvhit.pt); ScreenToClient(hList, &lvhit.pt); lvhit.pt.x = 3; i = ListView_HitTest(hList, &lvhit); if (i < 0) break; // Get our current definition. lvitem.mask = LVIF_TEXT; lvitem.iItem = i; lvitem.iSubItem = 0; lvitem.pszText = alias.verb; lvitem.cchTextMax = sizeof(alias.verb); ListView_GetItem(hList, &lvitem); lvitem.iSubItem = 1; lvitem.pszText = alias.text; lvitem.cchTextMax = sizeof(alias.text); ListView_GetItem(hList, &lvitem); // Put it up for editing. SetDlgItemText(hDlg, IDC_VERB, alias.verb); SetDlgItemText(hDlg, IDC_EXPANSION, alias.text); // Select and focus the item in the list. ListView_SetItemState(hList, i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); } break; case LVN_KEYDOWN: plvkey = (LV_KEYDOWN*)pnm; if (plvkey->wVKey == VK_DELETE) { // for (i = 0; i < nItems; i++) // if (is selected i) // ListView_DeleteItem(hList, i); } break; } } return TRUE; case WM_COMMAND: switch(GET_WM_COMMAND_ID(wParam, lParam)) { case IDOK: // Erase current set and redefine words in the dialog. { int i, nItems; HWND hList; hList = GetDlgItem(hDlg, IDC_COMMAND_LIST); // Simulate a last click of 'Define' in case they forgot. // Does no harm if they left the boxes empty after their // last 'Define'. // ListView_ClearSelection(hList); SendMessage(hDlg, WM_COMMAND, (WPARAM)MAKELONG(IDC_DEFINE, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, IDC_DEFINE)); // Clear our real aliases and rebuild them from our listbox. // FreeVerbAliases(); nItems = ListView_GetItemCount(hList); for (i = 0; i < nItems; i++) { VerbAlias alias; LV_ITEM lvitem; lvitem.mask = LVIF_TEXT; lvitem.iItem = i; lvitem.iSubItem = 0; lvitem.pszText = alias.verb; lvitem.cchTextMax = sizeof(alias.verb); ListView_GetItem(hList, &lvitem); lvitem.iSubItem = 1; lvitem.pszText = alias.text; lvitem.cchTextMax = sizeof(alias.text); ListView_GetItem(hList, &lvitem); AddVerbAlias(alias.verb, alias.text); } } EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; case IDC_DEFINE: { VerbAlias alias; LV_ITEM lvitem; HWND hList; hList = GetDlgItem(hDlg, IDC_COMMAND_LIST); // Get our new definition. GetDlgItemText(hDlg, IDC_VERB, alias.verb, sizeof(alias.verb)); GetDlgItemText(hDlg, IDC_EXPANSION, alias.text, sizeof(alias.text)); if (!alias.verb[0]) { SetFocus(GetDlgItem(hDlg, IDC_VERB)); return TRUE; } if (!alias.text[0]) { SetFocus(GetDlgItem(hDlg, IDC_EXPANSION)); return TRUE; } // Simulate a remove so we don't have to hunt and modify existing entry. ListView_ClearSelection(hList); SendMessage(hDlg, WM_COMMAND, (WPARAM)MAKELONG(IDC_REMOVE, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, IDC_REMOVE)); // Add item for verb. lvitem.mask = LVIF_TEXT; lvitem.iItem = ListView_GetItemCount(hList); lvitem.iSubItem = 0; lvitem.pszText = alias.verb; lvitem.iItem = ListView_InsertItem(hList, &lvitem); // Add subitem for command. lvitem.mask = LVIF_TEXT; lvitem.iSubItem = 1; lvitem.pszText = alias.text; ListView_SetItem(hList, &lvitem); // Clear the fields to try another. SetDlgItemText(hDlg, IDC_VERB, ""); SetDlgItemText(hDlg, IDC_EXPANSION, ""); SetFocus(GetDlgItem(hDlg, IDC_VERB)); } return TRUE; case IDC_REMOVE: { char verb[MAX_VERBLEN+1]; LV_FINDINFO lvfind; HWND hList; int i; hList = GetDlgItem(hDlg, IDC_COMMAND_LIST); // Get our new definition. GetDlgItemText(hDlg, IDC_VERB, verb, sizeof(verb)); if (!verb[0]) { LV_ITEM lvitem; i = ListView_GetSelection(hList); if (i < 0) { SetFocus(GetDlgItem(hDlg, IDC_VERB)); return TRUE; } lvitem.mask = LVIF_TEXT; lvitem.iItem = i; lvitem.iSubItem = 0; lvitem.pszText = verb; lvitem.cchTextMax = sizeof(verb); ListView_GetItem(hList, &lvitem); if (!verb[0]) { SetFocus(GetDlgItem(hDlg, IDC_VERB)); return TRUE; } } // Find item for verb. lvfind.flags = LVFI_STRING | LVFI_WRAP; // not LVFI_PARTIAL lvfind.psz = verb; lvfind.lParam = 0; i = ListView_FindItem(hList, -1, &lvfind); if (i < 0) { SetFocus(GetDlgItem(hDlg, IDC_VERB)); Edit_SetSel(GetDlgItem(hDlg, IDC_VERB), 0, -1); return TRUE; } // Remove item. ListView_DeleteItem(hList, i); // Clear the fields to try another. SetDlgItemText(hDlg, IDC_VERB, ""); SetDlgItemText(hDlg, IDC_EXPANSION, ""); SetFocus(GetDlgItem(hDlg, IDC_VERB)); } return TRUE; case IDC_TUNNEL: if (!hAliasDialog1 && IDOK == DialogBox(hInst, MAKEINTRESOURCE(IDD_ALIAS), hDlg, AliasDialogProc)) { AliasSave(); SetFocus(GetDlgItem(hDlg, IDOK)); } return TRUE; } break; case WM_DESTROY: hAliasDialog = NULL; hAliasDialog2 = NULL; return TRUE; } return FALSE; }
INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { TRecvContactsData* wndData = (TRecvContactsData*)GetWindowLong(hwndDlg, DWLP_USER); switch (msg) { case WM_INITDIALOG: { CLISTEVENT* pcle = (CLISTEVENT*)lParam; /// got it TranslateDialogDefault(hwndDlg); WindowList_Add(ghRecvWindowList, hwndDlg, pcle->hContact); SendMessageT(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_CONTACTS))); EnableDlgItem(hwndDlg, IDOK, FALSE); EnableDlgItem(hwndDlg, IDDETAILS, FALSE); wndData = new TRecvContactsData(pcle->hContact); SetWindowLong(hwndDlg, DWLP_USER, (LONG)wndData); wndData->mhDbEvent = pcle->hDbEvent; /// initialized, pcle not needed anymore wndData->mhListIcon = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),ILC_COLORDDB|ILC_MASK, 0, 1); wndData->mhPopup = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTACTMENU)); CallService(MS_LANGPACK_TRANSLATEMENU, (WPARAM)wndData->mhPopup, 0); wndData->hHook = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_EVENTSENT); char *szProto = GetContactProto(wndData->mhContact); HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS); ListView_SetExtendedListViewStyle(hLV, LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT); // add columns RecvListView_AddColumn(hLV, 120, (char*)SRCCallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDTEXT, 0), FALSE, 0); RecvListView_AddColumn(hLV, 100, "Nick", TRUE, 1); RecvListView_AddColumn(hLV, 100, "First Name", TRUE, 2); RecvListView_AddColumn(hLV, 100, "Last Name", TRUE, 3); // fill in groups SendMessageT(GetDlgItem(hwndDlg, IDC_ENABLEGROUPS), BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0); RebuildGroupCombo(hwndDlg); { // fill listview with received contacts DBEVENTINFO dbe = {0}; dbe.cbSize = sizeof(DBEVENTINFO); dbe.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)wndData->mhDbEvent, 0); if (dbe.cbBlob != -1) // this marks an invalid hDbEvent - all smashed anyway... dbe.pBlob = (PBYTE)_malloca(dbe.cbBlob); CallService(MS_DB_EVENT_GET, (WPARAM)wndData->mhDbEvent, (LPARAM)&dbe); char* pcBlob = (char*)dbe.pBlob; char* pcEnd = (char*)dbe.pBlob + dbe.cbBlob; HICON hiProto = LoadContactProtoIcon(wndData->mhContact); ImageList_AddIcon(wndData->mhListIcon, hiProto); DestroyIcon(hiProto); // imagelist copied the resource ListView_SetImageList(hLV, wndData->mhListIcon, LVSIL_SMALL); LVITEM lvi = {0}; lvi.iImage = 0; lvi.mask = LVIF_TEXT | LVIF_IMAGE; for (int nItem = 0; ; nItem++) { // Nick int strsize = (int)strlennull(pcBlob); TReceivedItem* pItem = wndData->AddReceivedItem(); if (dbe.flags & DBEF_UTF) pItem->mcaNick = utf8_to_tchar((unsigned char*)pcBlob); else pItem->mcaNick = ansi_to_tchar(pcBlob); pcBlob += strsize + 1; // UIN strsize = (int)strlennull(pcBlob); pItem->mcaUIN = null_strdup(pcBlob); pcBlob += strsize + 1; // add to listview lvi.iItem = nItem; lvi.pszText = pItem->mcaUIN; ListView_InsertItem(hLV, &lvi); // with image ListView_SetItemTextT(hLV, nItem, 1, pItem->mcaNick); // check for end of contacts if (pcBlob >= pcEnd) break; } } // new dlg init wndData->hIcons[0] = InitMButton(hwndDlg, IDC_ADD, MAKEINTRESOURCEA(IDI_ADDCONTACT), "Add Contact Permanently to List"); wndData->hIcons[1] = InitMButton(hwndDlg, IDC_DETAILS, MAKEINTRESOURCEA(IDI_USERDETAILS), "View User's Details"); wndData->hIcons[2] = InitMButton(hwndDlg, IDC_HISTORY, MAKEINTRESOURCEA(IDI_HISTORY), "View User's History"); wndData->hIcons[3] = InitMButton(hwndDlg, IDC_USERMENU, MAKEINTRESOURCEA(IDI_DOWNARROW), "User Menu"); SendMessageT(hwndDlg,DM_UPDATETITLE,0,0); // new dialog init done Utils_RestoreWindowPosition(hwndDlg, NULL, MODULENAME, ""); return TRUE; } case WM_NOTIFY: if (((LPNMHDR)lParam)->idFrom == IDC_CONTACTS) { switch (((LPNMHDR)lParam)->code) { case NM_DBLCLK: { HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS); if (ListView_GetSelectedCount(hLV) != 1) break; // if not clicking on item, bye wndData->iPopupItem = ListView_GetNextItem(hLV, -1, LVNI_ALL|LVNI_SELECTED); if (wndData->iPopupItem == -1) break; // if no item selected no user details available return SendMessageT(hwndDlg, WM_COMMAND, ID_POPUP_USERDETAILS, 0); // show user details } case LVN_ITEMCHANGED: { LPNMLISTVIEW pNMLV = (LPNMLISTVIEW)lParam; HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS); // optimisation, for FOR-Cycle bool bExistsCheckedItem = false; // there must be no checked items to disable "Add" button if (ListView_GetCheckState(hLV, pNMLV->iItem)) { // the user has checked this item bExistsCheckedItem = true; // enable "Add" button } else { // loop thru items and check if at least one is checked for (int i = 0; i < ListView_GetItemCount(hLV); i++) if (ListView_GetCheckState(hLV, i)) { // we found checked item, enable add, exit loop bExistsCheckedItem = true; break; } } EnableDlgItem(hwndDlg, IDOK, bExistsCheckedItem); EnableDlgItem(hwndDlg, IDDETAILS, ListView_GetSelectedCount(hLV) > 0); break; } } } break; case WM_COMMAND: { if (!lParam && CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)wndData->mhContact)) break; switch(LOWORD(wParam)) { case IDOK: // "Add Selected" button click { // for each selected item, find its index in the hDbEvent // and after that add this item to the DB permanently char* caUIN; HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS); HWND hGroupsCombo = GetDlgItem(hwndDlg, IDC_GROUPS); HWND hGroupsCheck = GetDlgItem(hwndDlg, IDC_ENABLEGROUPS); int curs = SendMessageT(hGroupsCombo, CB_GETCURSEL, 0, 0); TCHAR* caGroup = NULL; int nGroupId = -1; if (curs != CB_ERR && IsWindowEnabled(hGroupsCheck) && SendMessageT(hGroupsCheck, BM_GETCHECK, 0, 0)) { //got groups, get the one selected in combo TCHAR* caGroup = (TCHAR*)_malloca((SendMessageT(hGroupsCombo, CB_GETLBTEXTLEN, curs, 0) + 1) * sizeof(WCHAR)); SendMessageT(hGroupsCombo, CB_GETLBTEXT, curs, (LPARAM)caGroup); nGroupId = SendMessageT(hGroupsCombo, CB_GETITEMDATA, curs, 0); } for (int i = 0; i < ListView_GetItemCount(hLV); i++) if (ListView_GetCheckState(hLV, i)) { // found checked contact item, add it caUIN = ListView_GetItemTextEx(hLV, i, 0); for (int j = 0; j < wndData->cbReceived; j++) // determine item index in packet if (!strcmpnull(wndData->maReceived[j]->mcaUIN, caUIN)) { char* szProto = GetContactProto(wndData->mhContact); HANDLE hContact = (HANDLE)SRCCallProtoService(szProto, PS_ADDTOLISTBYEVENT, MAKEWPARAM(0, j), (LPARAM)wndData->mhDbEvent); if (hContact && caGroup) { // use newest group API if available if (ServiceExists(MS_CLIST_CONTACTCHANGEGROUP)) CallService(MS_CLIST_CONTACTCHANGEGROUP, (WPARAM)hContact, (LPARAM)nGroupId); else DBWriteContactSettingStringT(hContact, "CList", "Group", caGroup); } break; } SAFE_FREE((void**)&caUIN); } // move to next item break; } case IDDETAILS: { // for each selected item, find its index in the hDbEvent // and after that add this item to the DB // finally, request Details window for this hContact HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS); for (int i = 0; i < ListView_GetItemCount(hLV); i++) if (ListView_GetItemState(hLV, i, LVIS_SELECTED)) { HANDLE hContact = CreateTemporaryContactForItem(hwndDlg, wndData, i); if (hContact) CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0); } break; } case IDCANCEL: { SendMessageT(hwndDlg, WM_CLOSE, 0, 0); break; } case IDC_ENABLEGROUPS: { EnableGroupCombo(hwndDlg); break; } case IDC_GROUPS: { // rebuild group list on popup if (HIWORD(wParam) == CBN_DROPDOWN) RebuildGroupCombo(hwndDlg); break; } case ID_POPUP_ADDUSER: { HANDLE hContact = CreateTemporaryContactForItem(hwndDlg, wndData, wndData->iPopupItem); if (hContact) DialogAddContactExecute(hwndDlg, hContact); break; } case ID_POPUP_USERDETAILS: { HANDLE hContact = CreateTemporaryContactForItem(hwndDlg, wndData, wndData->iPopupItem); if (hContact) CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0 ); break; } case ID_POPUP_SENDMESSAGE: { HANDLE hContact = CreateTemporaryContactForItem(hwndDlg, wndData, wndData->iPopupItem); if (hContact) CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, 0); break; } case IDC_USERMENU: { RECT rc; HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)wndData->mhContact, 0); GetWindowRect(GetDlgItem(hwndDlg,IDC_USERMENU), &rc); TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); DestroyMenu(hMenu); break; } case IDC_HISTORY: CallService(MS_HISTORY_SHOWCONTACTHISTORY,(WPARAM)wndData->mhContact,0); break; case IDC_DETAILS: CallService(MS_USERINFO_SHOWDIALOG,(WPARAM)wndData->mhContact,0); break; case IDC_ADD: DialogAddContactExecute(hwndDlg, wndData->mhContact); break; } break; } case WM_CONTEXTMENU: { HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS); LVHITTESTINFO lvh; RECT rt; wndData->iPopupItem = -1; if ((HWND)wParam != hLV) break; // if not our ListView go away lvh.pt.x = LOWORD(lParam); lvh.pt.y = HIWORD(lParam); if (GetWindowRect(hLV, &rt)==0) return FALSE; // ?? why this, some check ?? ScreenToClient(hLV, &lvh.pt); // convert to ListView local coordinates int ci = ListView_HitTest(hLV, &lvh); if (ci==-1) break; // mouse is not over any item wndData->iPopupItem = ci; TrackPopupMenu(GetSubMenu(wndData->mhPopup, 0), TPM_LEFTALIGN|TPM_TOPALIGN, LOWORD(lParam), HIWORD(lParam), 0, hwndDlg, NULL); break; } case HM_EVENTSENT: { ACKDATA *ack=(ACKDATA*)lParam; if (ack->type!=ACKTYPE_SEARCH) break; // not search ack, go away if (ack->hProcess!=wndData->rhSearch) break; //not our search, go away if (ack->result==ACKRESULT_DATA) { HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS); PROTOSEARCHRESULT* psr = (PROTOSEARCHRESULT*)ack->lParam; LVFINDINFO fi; fi.flags = LVFI_STRING; fi.psz = wndData->haUin; int iLPos = ListView_FindItem(hLV, -1, &fi); if (iLPos==-1) iLPos=0; // ListView_SetItemText(hLV, iLPos, 0, psr->email); // not sent by ICQ, and currently unsupported either if (strcmpnull(psr->nick, "") && psr->nick) ListView_SetItemText(hLV, iLPos, 1, psr->nick); ListView_SetItemText(hLV, iLPos, 2, psr->firstName); ListView_SetItemText(hLV, iLPos, 3, psr->lastName); break; } SAFE_FREE((void**)&wndData->haUin); break; } case WM_CLOSE: // user closed window, so destroy it { WindowList_Remove(ghRecvWindowList, hwndDlg); DestroyWindow(hwndDlg); break; } case WM_DESTROY: // last message received by this dialog, cleanup { CallService(MS_DB_EVENT_MARKREAD, (WPARAM)wndData->mhContact, (LPARAM)wndData->mhDbEvent); Utils_SaveWindowPosition(hwndDlg, NULL, MODULENAME, ""); ImageList_Destroy(wndData->mhListIcon); UnhookEvent(wndData->hHook); DestroyMenu(wndData->mhPopup); for (int i=0; i < SIZEOF(wndData->hIcons); i++) DestroyIcon(wndData->hIcons[i]); delete wndData; // automatically calls destructor break; } case WM_MEASUREITEM: return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); case WM_DRAWITEM: { DrawProtocolIcon(hwndDlg, lParam, wndData->mhContact); return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); } case WM_SIZE: { // make the dlg resizeable UTILRESIZEDIALOG urd = {0}; if (IsIconic(hwndDlg)) break; urd.cbSize = sizeof(urd); urd.hInstance = hInst; urd.hwndDlg = hwndDlg; urd.lParam = 0; // user-defined urd.lpTemplate = MAKEINTRESOURCEA(IDD_RECEIVE); urd.pfnResizer = RecvDlg_Resize; CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM) & urd); break; } case WM_GETMINMAXINFO: { MINMAXINFO* mmi=(MINMAXINFO*)lParam; mmi->ptMinTrackSize.x = 480+2*GetSystemMetrics(SM_CXSIZEFRAME); mmi->ptMinTrackSize.y = 130+2*GetSystemMetrics(SM_CYSIZEFRAME); break; } case DM_UPDATETITLE: { UpdateDialogTitle(hwndDlg, wndData?wndData->mhContact:NULL, "Contacts from"); if (wndData) UpdateDialogAddButton(hwndDlg, wndData->mhContact); break; } } return FALSE; }
int CALLBACK CompareListViewColumn( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort ) { LISTVIEW_SORT * ctx = (LISTVIEW_SORT *) lParamSort; WCHAR text1[ MAX_PATH ]; WCHAR text2[ MAX_PATH ]; int order = CSTR_EQUAL; int idx1, idx2; LVFINDINFO find; double num1, num2; // Get indices of items if ( ctx->UsingEx ) { idx1 = lParam1; idx2 = lParam2; } else { find.flags = LVFI_PARAM; find.lParam = lParam1; idx1 = ListView_FindItem( ctx->hList, -1, &find ); find.lParam = lParam2; idx2 = ListView_FindItem( ctx->hList, -1, &find ); } ListView_GetItemText( ctx->hList, idx1, ctx->Column, text1, MAX_PATH ); ListView_GetItemText( ctx->hList, idx2, ctx->Column, text2, MAX_PATH ); switch ( ctx->ColumnList[ ctx->Column ].Type ) { case DATATYPE_TEXT: order = FilenameCompare( text1, text2 ); break; case DATATYPE_NUMBER: _stscanf( text1, TEXT("%lf"), &num1 ); _stscanf( text2, TEXT("%lf"), &num2 ); if ( num1 > num2 ) order = 1; else if ( num1 < num2 ) order = -1; else order = 0; break; case DATATYPE_HEX: _stscanf( text1, TEXT("%lx"), &num1 ); _stscanf( text2, TEXT("%lx"), &num2 ); if ( num1 > num2 ) order = 1; else if ( num1 < num2 ) order = -1; else order = 0; break; case DATATYPE_DATE: { VarDateFromStr( text1, LANG_USER_DEFAULT, 0, &num1 ); VarDateFromStr( text2, LANG_USER_DEFAULT, 0, &num2 ); if ( num1 < num2 ) order = -1; else if ( num1 > num2 ) order = 1; else order = 0; } break; } if ( ctx->ColumnList[ ctx->Column ].SortDir == SORTDIR_DOWN ) order = -order; return order; }
static LRESULT CALLBACK PluginListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CHAR: if (wParam == '\b') { if (szFilter.GetLength() > 0) szFilter.Truncate(szFilter.GetLength() - 1); } else { szFilter.AppendChar(wParam); for (int i = 0; i < arPluginList.getCount(); i++) { PluginListItemData *p = arPluginList[i]; if (!_tcsnicmp(szFilter, p->fileName, szFilter.GetLength())) { LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; lvfi.lParam = (LPARAM)p; int idx = ListView_FindItem(hwnd, 0, &lvfi); if (idx != -1) { ListView_SetItemState(hwnd, idx, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); ListView_EnsureVisible(hwnd, idx, FALSE); if (timerID != 0) KillTimer(hwnd, timerID); timerID = SetTimer(hwnd, 1, 1500, 0); return TRUE; } } } szFilter.Truncate(szFilter.GetLength() - 1); MessageBeep((UINT)-1); } return TRUE; case WM_TIMER: if (wParam == 1) { KillTimer(hwnd, timerID); timerID = 0; szFilter.Empty(); } break; case WM_LBUTTONDOWN: LVHITTESTINFO hi; hi.pt.x = LOWORD(lParam); hi.pt.y = HIWORD(lParam); ListView_SubItemHitTest(hwnd, &hi); // Dynamically load/unload a plugin if ((hi.iSubItem == 0) && (hi.flags & LVHT_ONITEMICON)) { LVITEM lvi = { 0 }; lvi.mask = LVIF_IMAGE | LVIF_PARAM; lvi.stateMask = -1; lvi.iItem = hi.iItem; lvi.iSubItem = 0; if (ListView_GetItem(hwnd, &lvi)) { lvi.mask = LVIF_IMAGE; PluginListItemData *dat = (PluginListItemData*)lvi.lParam; if (lvi.iImage == 3) { // load plugin if (LoadPluginDynamically(dat)) { lvi.iImage = 2; ListView_SetItem(hwnd, &lvi); } } else if (lvi.iImage == 2) { // unload plugin if (UnloadPluginDynamically(dat)) { lvi.iImage = 3; ListView_SetItem(hwnd, &lvi); } } LoadStdPlugins(); } } } return mir_callNextSubclass(hwnd, PluginListWndProc, msg, wParam, lParam); }
int CALLBACK CompareSharedFilesFunc(LPARAM lParam1, LPARAM lParam2,LPARAM lParamSort) { // lParamSort is the list control pointer and column // lParam1 and lParam2 is the index DWORD_PTR *params=(DWORD_PTR *)lParamSort; CListCtrl *list=(CListCtrl *)params[0]; int sub_item=(int)params[1]; bool found1=false; bool found2=false; CString cstring1,cstring2; HWND hList = list->GetSafeHwnd(); LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; lvfi.lParam = lParam1; int index1 = ListView_FindItem(hList, -1, &lvfi); lvfi.lParam = lParam2; int index2 = ListView_FindItem(hList, -1, &lvfi); cstring1=list->GetItemText(index1,sub_item); cstring2=list->GetItemText(index2,sub_item); // Make then both lowercase cstring1.MakeLower(); cstring2.MakeLower(); switch(sub_item) { case SUB_PATH: case SUB_FILENAME: case SUB_DATE_CREATED: { // Put empty strings at the bottom if(cstring1.IsEmpty()) { return 1; } else if(cstring2.IsEmpty()) { return -1; } else { return strcmp(cstring1,cstring2); } } case SUB_FILE_SIZE: { float val1=0x00FFFFFF; // very big float val2=0x00FFFFFF; // very big sscanf(cstring1,"%f",&val1); sscanf(cstring2,"%f",&val2); if(val1<val2) { return -1; } else if(val1>val2) { return 1; } return 0; } default: { return 0; } } }
void CBuddyManager::NotifyBuddyIsOnline(BUDDY_INFO *pBI, SERVER_INFO *pServerInfo) { if(pBI==NULL) return; if(pServerInfo==NULL) return; vecBI::iterator it = FindBuddyInfoByID(pBI->dwID); if(it==BuddyList.end()) return; if(pServerInfo->szServerName!=NULL) strncpy_s(it->szServerName,sizeof(pBI->szServerName),pServerInfo->szServerName,_TRUNCATE); it->cGAMEINDEX = pServerInfo->cGAMEINDEX; it->sIndex = (int) pServerInfo->dwIndex; //have to change the Buddy index to a new var that can hold bigger numbers such as DWORD HWND hwndLV = g_hwndListBuddy; LV_FINDINFO lvfi; char szText[250]; memset(&lvfi,0,sizeof(LV_FINDINFO)); lvfi.flags = LVFI_PARAM; lvfi.lParam = (LPARAM)pBI->dwID; int index = ListView_FindItem(hwndLV , -1, &lvfi); if(index!=-1) { LVITEM item; item.mask = LVIF_TEXT | LVIF_IMAGE; item.iItem = index; memset(szText,0,sizeof(szText)); if(gm.GamesInfo[it->cGAMEINDEX].colorfilter!=NULL) { gm.GamesInfo[it->cGAMEINDEX].colorfilter(it->szServerName,szText,249); item.pszText = szText; item.cchTextMax = (int)strlen(szText); } else { item.pszText = it->szServerName; item.cchTextMax = (int)strlen(it->szServerName); } item.iSubItem = 1; item.iImage = gm.Get_GameIcon(it->cGAMEINDEX); ListView_SetItem(g_hwndListBuddy,&item); sprintf_s(szText,"%s:%d",pServerInfo->szIPaddress,pServerInfo->usPort); strcpy_s(it->szIPaddress,szText); ListView_SetItemText(g_hwndListBuddy,index ,2,szText); } if(gm.GamesInfo[it->cGAMEINDEX].colorfilter!=NULL) gm.GamesInfo[it->cGAMEINDEX].colorfilter(it->szServerName,szText,249); else strcpy_s(szText,it->szPlayerName); if(g_bRunningQueryServerList && g_bPlayedNotify==false) PlayNotifySound(0 ); if(AppCFG.bBuddyNotify) ShowBalloonTip("A buddy is online!",szText); }
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2,LPARAM lParamSort) { // lParamSort is the list control pointer and column // lParam1 and lParam2 is the index DWORD_PTR *params=(DWORD_PTR *)lParamSort; CListCtrl *list=(CListCtrl *)params[0]; int sub_item=(int)params[1]; bool found1=false; bool found2=false; CString cstring1,cstring2; HWND hList = list->GetSafeHwnd(); LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; lvfi.lParam = lParam1; int index1 = ListView_FindItem(hList, -1, &lvfi); lvfi.lParam = lParam2; int index2 = ListView_FindItem(hList, -1, &lvfi); cstring1=list->GetItemText(index1,sub_item); cstring2=list->GetItemText(index2,sub_item); // Make then both lowercase cstring1.MakeLower(); cstring2.MakeLower(); // Put empty strings at the bottom switch(sub_item) { case SUB_SUPPLY_RETRIEVAL_STARTED: case SUB_SUPPLY_RETRIEVAL_ENDED: case SUB_SUPPLY_RETRIEVAL_PROGRESS: case SUB_NETWORK: case SUB_PING_TIME: { // Put empty strings at the bottom if(cstring1.IsEmpty()) { return 1; } else if(cstring2.IsEmpty()) { return -1; } else { return strcmp(cstring1,cstring2); } } case SUB_COLLECTOR: { unsigned int ip_1=0xFFFFFFFF; // very big unsigned int ip_2=0xFFFFFFFF; // very big unsigned int ip1,ip2,ip3,ip4; sscanf(cstring1,"%u.%u.%u.%u",&ip1,&ip2,&ip3,&ip4); ip_1=(ip1<<24)+(ip2<<16)+(ip3<<8)+(ip4<<0); // big-endian sscanf(cstring2,"%u.%u.%u.%u",&ip1,&ip2,&ip3,&ip4); ip_2=(ip1<<24)+(ip2<<16)+(ip3<<8)+(ip4<<0); // big-endian if(ip_1<ip_2) { return -1; } else if(ip_1>ip_2) { return 1; } return 0; } case SUB_NUM_PROJECTS: { float val1=0x00FFFFFF; // very big float val2=0x00FFFFFF; // very big sscanf(cstring1,"%f",&val1); sscanf(cstring2,"%f",&val2); if(val1<val2) { return -1; } else if(val1>val2) { return 1; } return 0; } default: { return 0; } } }
/* TODO: This code should be coalesced with the code that adds items as well as the code that finds their icons. ALL changes to an items name/internal properties/icon/overlay icon should go through a central function. */ void CFolderView::RenameItem(int iItemInternal,TCHAR *szNewFileName) { IShellFolder *pShellFolder = NULL; LPITEMIDLIST pidlFull = NULL; LPITEMIDLIST pidlRelative = NULL; SHFILEINFO shfi; LVFINDINFO lvfi; TCHAR szDisplayName[MAX_PATH]; LVITEM lvItem; TCHAR szFullFileName[MAX_PATH]; DWORD_PTR res; HRESULT hr; int iItem; if(iItemInternal == -1) return; StringCchCopy(szFullFileName,MAX_PATH,m_CurDir); PathAppend(szFullFileName,szNewFileName); hr = GetIdlFromParsingName(szFullFileName,&pidlFull); if(SUCCEEDED(hr)) { hr = SHBindToParent(pidlFull,IID_IShellFolder,(void **)&pShellFolder,(LPCITEMIDLIST *)&pidlRelative); if(SUCCEEDED(hr)) { hr = GetDisplayName(szFullFileName,szDisplayName,SHGDN_INFOLDER|SHGDN_FORPARSING); if(SUCCEEDED(hr)) { m_pExtraItemInfo[iItemInternal].pridl = ILClone(pidlRelative); StringCchCopy(m_pExtraItemInfo[iItemInternal].szDisplayName, SIZEOF_ARRAY(m_pExtraItemInfo[iItemInternal].szDisplayName), szDisplayName); /* Need to update internal storage for the item, since it's name has now changed. */ StringCchCopy(m_pwfdFiles[iItemInternal].cFileName, SIZEOF_ARRAY(m_pwfdFiles[iItemInternal].cFileName), szNewFileName); /* The files' type may have changed, so retrieve the files' icon again. */ res = SHGetFileInfo((LPTSTR)pidlFull,0,&shfi, sizeof(SHFILEINFO),SHGFI_PIDL|SHGFI_ICON| SHGFI_OVERLAYINDEX); if(res != 0) { /* Locate the item within the listview. */ lvfi.flags = LVFI_PARAM; lvfi.lParam = iItemInternal; iItem = ListView_FindItem(m_hListView,-1,&lvfi); if(iItem != -1) { lvItem.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_STATE; lvItem.iItem = iItem; lvItem.iSubItem = 0; lvItem.iImage = shfi.iIcon; lvItem.pszText = ProcessItemFileName(iItemInternal); lvItem.stateMask = LVIS_OVERLAYMASK; /* As well as resetting the items icon, we'll also set it's overlay again (the overlay could change, for example, if the file is changed to a shortcut). */ lvItem.state = INDEXTOOVERLAYMASK(shfi.iIcon >> 24); /* Update the item in the listview. */ ListView_SetItem(m_hListView,&lvItem); /* TODO: Does the file need to be filtered out? */ if(IsFileFiltered(iItemInternal)) { RemoveFilteredItem(iItem,iItemInternal); } } DestroyIcon(shfi.hIcon); } } pShellFolder->Release(); }
void NListView::ListView_HandleInsertionMark(HWND hListView,int iItemFocus,POINT *ppt) { /* Remove the insertion mark. */ if(ppt == NULL) { LVINSERTMARK lvim; lvim.cbSize = sizeof(LVINSERTMARK); lvim.dwFlags = 0; lvim.iItem = -1; ListView_SetInsertMark(hListView,&lvim); return; } RECT ItemRect; DWORD dwFlags = 0; int iNext; LV_HITTESTINFO item; item.pt = *ppt; int iItem = ListView_HitTest(hListView,&item); if(iItem != -1 && item.flags & LVHT_ONITEM) { ListView_GetItemRect(hListView,item.iItem,&ItemRect,LVIR_BOUNDS); /* If the cursor is on the left side of this item, set the insertion before this item; if it is on the right side of this item, set the insertion mark after this item. */ if((ppt->x - ItemRect.left) > ((ItemRect.right - ItemRect.left)/2)) { iNext = iItem; dwFlags = LVIM_AFTER; } else { iNext = iItem; dwFlags = 0; } } else { dwFlags = 0; /* VK_UP finds whichever item is "above" the cursor. This item may be in the same row as the cursor is in (e.g. an item in the next row won't be found until the cursor passes into that row). Appears to find the item on the right side. */ LVFINDINFO lvfi; lvfi.flags = LVFI_NEARESTXY; lvfi.pt = *ppt; lvfi.vkDirection = VK_UP; iNext = ListView_FindItem(hListView,-1,&lvfi); if(iNext == -1) { lvfi.flags = LVFI_NEARESTXY; lvfi.pt = *ppt; lvfi.vkDirection = VK_LEFT; iNext = ListView_FindItem(hListView,-1,&lvfi); } ListView_GetItemRect(hListView,iNext,&ItemRect,LVIR_BOUNDS); /* This situation only occurs at the end of the row. Prior to this, it is always the item on the right side that is found, with the insertion mark been inserted before that item. Once the end of the row is reached, the item found will be on the left side of the cursor. */ if(ppt->x > ItemRect.left + ((ItemRect.right - ItemRect.left)/2)) { /* At the end of a row, VK_UP appears to find the next item up. Therefore, if we're at the end of a row, and the cursor is completely below the "next" item, find the one under it instead (if there is an item under it), and anchor the insertion mark there. */ if(ppt->y > ItemRect.bottom) { int iBelow; iBelow = ListView_GetNextItem(hListView,iNext,LVNI_BELOW); if(iBelow != -1) iNext = iBelow; } dwFlags = LVIM_AFTER; } int nItems = ListView_GetItemCount(hListView); /* Last item is at position nItems - 1. */ ListView_GetItemRect(hListView,nItems - 1,&ItemRect,LVIR_BOUNDS); /* Special case needed for very last item. If cursor is within 0.5 to 1.5 width of last item, and is greater than it's y coordinate, snap the insertion mark to this item. */ if((ppt->x > ItemRect.left + ((ItemRect.right - ItemRect.left)/2)) && ppt->x < ItemRect.right + ((ItemRect.right - ItemRect.left)/2) + 2 && ppt->y > ItemRect.top) { iNext = nItems - 1; dwFlags = LVIM_AFTER; } } LVINSERTMARK lvim; lvim.cbSize = sizeof(LVINSERTMARK); lvim.dwFlags = dwFlags; lvim.iItem = iNext; ListView_SetInsertMark(hListView,&lvim); }