/*! 見出しコンボックスを空にする */ VOID AaTitleClear( VOID ) { ComboBox_SetCurSel( ghComboxWnd, -1 ); while( ComboBox_GetCount( ghComboxWnd ) ){ ComboBox_DeleteString( ghComboxWnd, 0 ); } gvcAaTitle.clear( ); return; }
/* * TextInputKey: User pressed a key on text input box. * Return True iff key should NOT be passed on to Windows for default processing. */ Bool TextInputKey(HWND hwnd, UINT key, Bool fDown, int cRepeat, UINT flags) { Bool held_down = (flags & 0x4000) ? True : False; /* Is key being held down? */ char string[MAXSAY + 1]; int action; BOOL bValid; void *action_data; if (key == VK_RETURN && !held_down) { UserDidSomething(); ComboBox_GetText(hwndInput, string, MAXSAY + 1); if (string[0] == 0) return True; SetFocus(hMain); bValid = ParseGotText(string); // Add it to the history. if (*string && bValid) { BOOL bAdd = TRUE; int iCount; char achHead[MAXSAY+1]; iCount = ComboBox_GetCount(hwndInput); if (iCount > 0) { ComboBox_GetLBText(hwndInput, 0, achHead); if (0 == strcmp(achHead, string)) bAdd = FALSE; } if (bAdd) { ComboBox_InsertString(hwndInput, 0, string); if (iCount > EDITBOX_HISTORY) ComboBox_DeleteString(hwndInput, iCount); } } return True; } // Check for special keys action = TranslateKey(key, textin_key_table, &action_data); if (action == A_NOACTION) return False; PerformAction(action, action_data); return True; }
/** * Adds a string and associated item data to a combobox. * * @param pszText - the text to add to the combobox * @param lParam - item data to accociate with the new item * * @return zero-based index to new item or CB_ERR on failure **/ INT_PTR CCombo::AddItem(LPCTSTR pszText, LPARAM lParam) { INT_PTR added = ComboBox_AddString(_hwnd, pszText); if (SUCCEEDED(added)) { if (PtrIsValid(lParam) && FAILED(ComboBox_SetItemData(_hwnd, added, lParam))) { ComboBox_DeleteString(_hwnd, added); added = CB_ERR; } } return added; }
static INT_PTR EnumNamesProc(CTimeZone *pTimeZone, int index, LPARAM lParam) { if (pTimeZone && pTimeZone->ptszDisplay) { int added = ComboBox_AddString((HWND)lParam, pTimeZone->ptszDisplay); if (SUCCEEDED(added)) { if (FAILED(ComboBox_SetItemData((HWND)lParam, added, pTimeZone))) { ComboBox_DeleteString((HWND)lParam, added); } } } return 0; }
//================================================================================================ //-----------------------//-----------------------------+++--> Delete One of the Configured Timers: void OnDel(HWND hDlg) //------------------------------------------------------------------+++--> { HWND timer_cb = GetDlgItem(hDlg, IDC_TIMERNAME); char name[TNY_BUFF]; char subkey[TNY_BUFF]; size_t offset; int idx, idx2, count; offset=wsprintf(subkey, "%s\\Timer", g_szTimersSubKey); ComboBox_GetText(timer_cb, name, sizeof(name)); count = ComboBox_GetCount(timer_cb) -1; for(idx=0; idx<count; ++idx) { timeropt_t* pts = (timeropt_t*)ComboBox_GetItemData(timer_cb, idx); if(!strcmp(name,pts->name)){ break; } } if(idx==count) return; StopTimer(idx); for(idx2=idx+1; idx2<count; ++idx2) { timeropt_t* pts; pts = (timeropt_t*)ComboBox_GetItemData(timer_cb, idx2); wsprintf(subkey+offset, "%d", idx2); // we're 1 behind, as needed api.SetStr(subkey, "Name", pts->name); api.SetInt(subkey, "Seconds", pts->second); api.SetInt(subkey, "Minutes", pts->minute); api.SetInt(subkey, "Hours", pts->hour); api.SetInt(subkey, "Days", pts->day); api.SetStr(subkey, "File", pts->fname); api.SetInt(subkey, "Repeat", pts->bRepeat); api.SetInt(subkey, "Blink", pts->bBlink); api.SetInt(subkey, "Active", pts->bActive); } wsprintf(subkey+offset, "%d", count); api.DelKey(subkey); api.SetInt(g_szTimersSubKey, "NumberOfTimers", --count); free((void*)ComboBox_GetItemData(timer_cb,idx)); ComboBox_DeleteString(timer_cb,idx); ComboBox_SetCurSel(timer_cb, (idx>0)?(idx-1):idx); OnTimerName(hDlg); PostMessage(hDlg, WM_NEXTDLGCTL, 1, FALSE); }
// --------------------------------------------------------------------------- // CWinMenubar::LoadDialogProc() // Dialog Window proc for the Load URL dialog // --------------------------------------------------------------------------- BOOL CALLBACK CWinMenubar::LoadDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { SetWindowLong(hDlg, DWL_USER, lParam); // CEcmtMenubar* HWND hURL = GetDlgItem(hDlg, IDC_URL); #ifdef HAVE_WLIB HKEY key = REG_OpenKey(HKCU, gRegPath, KEY_READ); if (key) { RegMsz* history = REG_QueryMultiSz(key, gRegLoadHistory); if (history) { const char* entry = REGMSZ_First(history); TRACE("ECMTMENUBAR: reading URL history...\n"); while (entry) { TRACE1(" %s\n",entry); // Cannot use ComboBox_AddString because it may call // SendMessageW, while we need SendMessageA SendMessageA(hURL, CB_ADDSTRING, 0, (LPARAM)entry); entry = REGMSZ_Next(history, entry); } int n = ComboBox_GetCount(hURL); if (n > 0) { TRACE1("ECMTMENUBAR: loaded %d history entries\n",n); ComboBox_SetCurSel(hURL, 0); } } REG_CloseKey(key); } #endif // HAVE_WLIB // Disable OK button if the URL field is empty HWND hOK = GetDlgItem(hDlg, IDOK); EnableWindow(hOK, GetWindowTextLength(hURL) > 0); } return TRUE; case WM_COMMAND: switch (wParam) { case MAKELONG(IDC_URL,CBN_SELCHANGE): // Will update the OK button after the edit field gets updated PostMessageA(hDlg, message, MAKELONG(IDC_URL,EN_CHANGE), lParam); return TRUE; case MAKELONG(IDC_URL,CBN_EDITCHANGE): case MAKELONG(IDC_URL,EN_CHANGE): { // Disable OK button if the URL is empty HWND hURL = GetDlgItem(hDlg, IDC_URL); HWND hOK = GetDlgItem(hDlg, IDOK); EnableWindow(hOK, GetWindowTextLength(hURL) > 0); } return TRUE; case IDC_BROWSE: { CWinMenubar* This = (CWinMenubar*)GetWindowLong(hDlg,DWL_USER); HWND hURL = GetDlgItem(hDlg, IDC_URL); TCHAR* fname = This->SelectFile(hURL); if (fname) { // Opening a local file. Add local file cheme to the beginning // of url, so later on a decision can be made: whether open a // web address using browser or local file using the SDK launcher. TCHAR* url=NULL; const char* cheme = LOCAL_FILE_SCHEME; int length = strlen(cheme) + wcslen(fname)+1; url = (TCHAR*)Alloc(length*sizeof(TCHAR)); TCHAR* tempurl = url; if(url) { // Add cheme while(*cheme) { *tempurl = *cheme; cheme++; tempurl++; } // Add pathS wcscat(tempurl,fname); tempurl=NULL; HWND hOK = GetDlgItem(hDlg, IDOK); EnableWindow(hOK, TRUE); SetWindowText(hURL, url); SetFocus(hURL); Free(url); } Free(fname); } } return TRUE; case IDOK: { CWinMenubar* This = (CWinMenubar*)GetWindowLong(hDlg,DWL_USER); HWND hURL = GetDlgItem(hDlg, IDC_URL); int len = GetWindowTextLength(hURL); if (This && len > 0) { TCHAR* url = (TCHAR*)Alloc((len+1)*sizeof(TCHAR)); if (url) { len = GetWindowText(hURL, url, len+1); // Check if url contains "local://" at the beginning. const char* cheme = LOCAL_FILE_SCHEME; // Boolean indicating does url contain local file cheme BOOL match = TRUE; for(int k=0;k<strlen(cheme);k++){ TCHAR c_cheme=cheme[k]; TCHAR c_url=url[k]; if(c_url != c_cheme) { match = FALSE; break; } } // Launch file with the SDK launcher local cheme was found. // otherwice launch url in browser. if(match==TRUE) { TCHAR* fname=url; fname += strlen(cheme); This->iEcmtMenubar->LoadFile( This->iDefaultBrowser, fname); fname=NULL; } else {//Else launch file in browser: This->iEcmtMenubar->LaunchBrowser( This->iDefaultBrowser, url); #ifdef HAVE_WLIB // Update the URL history. First, remove duplicates. TRACE("ECMTMENUBAR: updating URL history...\n"); int i, n = ComboBox_GetCount(hURL); int bufsize = 0; TCHAR* buf = NULL; for (i=n-1; i>=0; i--) { len = ComboBox_GetLBTextLen(hURL,i); if (len >= bufsize) { Free(buf); bufsize = len+1; buf = (TCHAR*)Alloc(bufsize*sizeof(TCHAR)); if (!buf) break; } buf[0] = 0; ComboBox_GetLBText(hURL, i, buf); if (_tcscmp(buf, url) == 0) { TRACE1("ECMTMENUBAR: duplicate at %d\n",i); ComboBox_DeleteString(hURL, i); } } // Insert new item, recalculate number of items ComboBox_InsertString(hURL, 0, url); n = ComboBox_GetCount(hURL); Free(buf); // Delete extra items from the bottom int extra = n - KMaxLoadHistory; for (i=0; i<extra; i++) { ComboBox_DeleteString(hURL, n-i-1); } // Save the history RegMsz * msz = REGMSZ_Create(); if (msz) { TRACE("ECMTMENUBAR: collecting history\n"); char* buf2 = NULL; bufsize = 0; n = ComboBox_GetCount(hURL); for (i=0; i<n; i++) { len = ComboBox_GetLBTextLen(hURL,i); if (len >= bufsize) { Free(buf2); bufsize = len+1; buf2 = (char*)Alloc(bufsize); if (!buf2) break; } buf2[0] = 0; SendMessageA(hURL,CB_GETLBTEXT,i,(LPARAM)buf2); TRACE1(" %s\n",buf2); if (buf2[0]) REGMSZ_Add(msz, buf2); } HKEY key = REG_OpenCreateKey(HKCU, gRegPath); if (key) { TRACE("ECMTMENUBAR: saving history\n"); REG_SetMsz(key, gRegLoadHistory, msz); REG_CloseKey(key); } REGMSZ_Delete(msz); Free(buf2); } #endif // HAVE_WLIB } // And finally free memory Free(url); } } } // Fall through case IDCANCEL: EndDialog(hDlg, wParam); return TRUE; default: return FALSE; } default: return FALSE; } }
INT_PTR CALLBACK GeneralPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { int updatestrings = 0; if (msg == WM_INITDIALOG) { wchar_t txt[20]; GetPrivateProfileString(L"General", L"AutoFocus", L"0", txt, ARRAY_SIZE(txt), inipath); Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOFOCUS), _wtoi(txt)?BST_CHECKED:BST_UNCHECKED); GetPrivateProfileString(L"General", L"Aero", L"2", txt, ARRAY_SIZE(txt), inipath); Button_SetCheck(GetDlgItem(hwnd,IDC_AERO), _wtoi(txt)?BST_CHECKED:BST_UNCHECKED); GetPrivateProfileString(L"General", L"InactiveScroll", L"1", txt, ARRAY_SIZE(txt), inipath); Button_SetCheck(GetDlgItem(hwnd,IDC_INACTIVESCROLL), _wtoi(txt)?BST_CHECKED:BST_UNCHECKED); GetPrivateProfileString(L"General", L"MDI", L"0", txt, ARRAY_SIZE(txt), inipath); Button_SetCheck(GetDlgItem(hwnd,IDC_MDI), _wtoi(txt)?BST_CHECKED:BST_UNCHECKED); HWND control = GetDlgItem(hwnd, IDC_LANGUAGE); ComboBox_ResetContent(control); if (l10n == &l10n_ini) { ComboBox_AddString(control, l10n->lang); ComboBox_SetCurSel(control, 0); ComboBox_Enable(control, FALSE); } else { ComboBox_Enable(control, TRUE); int i; for (i=0; i < ARRAY_SIZE(languages); i++) { ComboBox_AddString(control, languages[i]->lang); if (l10n == languages[i]) { ComboBox_SetCurSel(control, i); } } } Button_Enable(GetDlgItem(hwnd,IDC_ELEVATE), vista && !elevated); } else if (msg == WM_COMMAND) { int id = LOWORD(wParam); int event = HIWORD(wParam); HWND control = GetDlgItem(hwnd, id); int val = Button_GetCheck(control); wchar_t txt[10]; if (id == IDC_AUTOFOCUS) { WritePrivateProfileString(L"General", L"AutoFocus", _itow(val,txt,10), inipath); } else if (id == IDC_AUTOSNAP && event == CBN_SELCHANGE) { val = ComboBox_GetCurSel(control); WritePrivateProfileString(L"General", L"AutoSnap", _itow(val,txt,10), inipath); } else if (id == IDC_AERO) { WritePrivateProfileString(L"General", L"Aero", _itow(val,txt,10), inipath); } else if (id == IDC_INACTIVESCROLL) { WritePrivateProfileString(L"General", L"InactiveScroll", _itow(val,txt,10), inipath); } else if (id == IDC_MDI) { WritePrivateProfileString(L"General", L"MDI", _itow(val,txt,10), inipath); } else if (id == IDC_LANGUAGE && event == CBN_SELCHANGE) { int i = ComboBox_GetCurSel(control); if (i == ARRAY_SIZE(languages)) { OpenUrl(L"https://stefansundin.github.io/altdrag/doc/translate.html"); for (i=0; l10n != languages[i]; i++) {} ComboBox_SetCurSel(control, i); } else { l10n = languages[i]; WritePrivateProfileString(L"General", L"Language", l10n->code, inipath); updatestrings = 1; UpdateStrings(); } } else if (id == IDC_AUTOSTART) { SetAutostart(val, 0, 0); Button_Enable(GetDlgItem(hwnd,IDC_AUTOSTART_HIDE), val); Button_Enable(GetDlgItem(hwnd,IDC_AUTOSTART_ELEVATE), val && vista); if (!val) { Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_HIDE), BST_UNCHECKED); Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_ELEVATE), BST_UNCHECKED); } } else if (id == IDC_AUTOSTART_HIDE) { int elevate = Button_GetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_ELEVATE)); SetAutostart(1, val, elevate); } else if (id == IDC_AUTOSTART_ELEVATE) { int hide = Button_GetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_HIDE)); SetAutostart(1, hide, val); if (val) { // Don't nag if UAC is disabled, only check if elevated DWORD uac_enabled = 1; if (elevated) { DWORD len = sizeof(uac_enabled); HKEY key; RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_QUERY_VALUE, &key); RegQueryValueEx(key, L"EnableLUA", NULL, NULL, (LPBYTE)&uac_enabled, &len); RegCloseKey(key); } if (uac_enabled) { MessageBox(NULL, l10n->general_autostart_elevate_tip, APP_NAME, MB_ICONINFORMATION|MB_OK); } } } else if (id == IDC_ELEVATE && MessageBox(NULL,l10n->general_elevate_tip,APP_NAME,MB_ICONINFORMATION|MB_OK)) { wchar_t path[MAX_PATH]; GetModuleFileName(NULL, path, ARRAY_SIZE(path)); if ((INT_PTR)ShellExecute(NULL,L"runas",path,L"-config -multi",NULL,SW_SHOWNORMAL) > 32) { PostMessage(g_hwnd, WM_CLOSE, 0, 0); } else { MessageBox(NULL, l10n->general_elevation_aborted, APP_NAME, MB_ICONINFORMATION|MB_OK); } return; } UpdateSettings(); } else if (msg == WM_NOTIFY) { LPNMHDR pnmh = (LPNMHDR) lParam; if (pnmh->code == PSN_SETACTIVE) { updatestrings = 1; // Autostart int autostart=0, hidden=0, elevated=0; CheckAutostart(&autostart, &hidden, &elevated); Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOSTART), autostart?BST_CHECKED:BST_UNCHECKED); Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_HIDE), hidden?BST_CHECKED:BST_UNCHECKED); Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOSTART_ELEVATE), elevated?BST_CHECKED:BST_UNCHECKED); Button_Enable(GetDlgItem(hwnd,IDC_AUTOSTART_HIDE), autostart); Button_Enable(GetDlgItem(hwnd,IDC_AUTOSTART_ELEVATE), autostart && vista); } } if (updatestrings) { // Update text SetDlgItemText(hwnd, IDC_GENERAL_BOX, l10n->general_box); SetDlgItemText(hwnd, IDC_AUTOFOCUS, l10n->general_autofocus); SetDlgItemText(hwnd, IDC_AERO, l10n->general_aero); SetDlgItemText(hwnd, IDC_INACTIVESCROLL, l10n->general_inactivescroll); SetDlgItemText(hwnd, IDC_MDI, l10n->general_mdi); SetDlgItemText(hwnd, IDC_AUTOSNAP_HEADER, l10n->general_autosnap); SetDlgItemText(hwnd, IDC_LANGUAGE_HEADER, l10n->general_language); SetDlgItemText(hwnd, IDC_AUTOSTART_BOX, l10n->general_autostart_box); SetDlgItemText(hwnd, IDC_AUTOSTART, l10n->general_autostart); SetDlgItemText(hwnd, IDC_AUTOSTART_HIDE, l10n->general_autostart_hide); SetDlgItemText(hwnd, IDC_AUTOSTART_ELEVATE, l10n->general_autostart_elevate); SetDlgItemText(hwnd, IDC_ELEVATE, (elevated?l10n->general_elevated:l10n->general_elevate)); SetDlgItemText(hwnd, IDC_AUTOSAVE, l10n->general_autosave); // AutoSnap HWND control = GetDlgItem(hwnd, IDC_AUTOSNAP); ComboBox_ResetContent(control); ComboBox_AddString(control, l10n->general_autosnap0); ComboBox_AddString(control, l10n->general_autosnap1); ComboBox_AddString(control, l10n->general_autosnap2); ComboBox_AddString(control, l10n->general_autosnap3); wchar_t txt[10]; GetPrivateProfileString(L"General", L"AutoSnap", L"0", txt, ARRAY_SIZE(txt), inipath); ComboBox_SetCurSel(control, _wtoi(txt)); // Language control = GetDlgItem(hwnd, IDC_LANGUAGE); ComboBox_DeleteString(control, ARRAY_SIZE(languages)); if (l10n == &en_US) { ComboBox_AddString(control, L"How can I help translate?"); } } return FALSE; }
void GroupCommand(HWND hDlg, int ctrl_id, HWND hwndCtl, UINT codeNotify) { int index, i; char group_name[MAX_GROUPNAME + 1], player_name[MAX_CHARNAME + 1], quoted_name[MAX_CHARNAME + 3]; char say_string[MAXSAY + 1]; UserGroup g; HWND hList, hwndFocus, hCombo; Bool legal_index; switch(ctrl_id) { case IDC_GROUPS: if (codeNotify != CBN_SELCHANGE) break; legal_index = GetCurrentGroupName(hDlg, group_name); EnableWindow(GetDlgItem(hDlg, IDC_DELGROUP), legal_index); EnableWindow(GetDlgItem(hDlg, IDC_ADDMEMBER), legal_index); EnableWindow(GetDlgItem(hDlg, IDC_DELMEMBER), legal_index); EnableWindow(GetDlgItem(hDlg, IDC_ADDNAME), legal_index); EnableWindow(GetDlgItem(hDlg, IDC_ADDNAMETEXT), legal_index); if (!legal_index) break; if (GroupLoad(group_name, &g) != GROUP_MATCH) { debug(("GroupCommand unable to load selected group %s\n", group_name)); break; } hList = GetDlgItem(hDlg, IDC_GROUPMEMBERS); ListBox_ResetContent(hList); for (i=0; i < g.num_users; i++) ListBox_AddString(hList, g.names[i]); SetDlgItemText(hDlg, IDC_GROUPSTATUS, ""); break; case IDC_DELGROUP: hCombo = GetDlgItem(hDlg, IDC_GROUPS); index = ComboBox_GetCurSel(hCombo); if (index == CB_ERR) break; ComboBox_GetText(hCombo, group_name, MAX_GROUPNAME); if (GroupDelete(group_name)) { ComboBox_DeleteString(hCombo, index); if (ComboBox_GetCount(hCombo) == 0) { ComboBox_ResetContent(hCombo); ListBox_ResetContent(GetDlgItem(hDlg, IDC_GROUPMEMBERS)); } else ComboBox_SetCurSel(hCombo, min(index, ComboBox_GetCount(hCombo) - 1)); FORWARD_WM_COMMAND(hDlg, IDC_GROUPS, hCombo, CBN_SELCHANGE, GroupDialogProc); if (num_groups < MAX_NUMGROUPS) EnableWindow(GetDlgItem(hDlg, IDC_NEWGROUP), TRUE); SetDlgItemText(hDlg, IDC_GROUPSTATUS, ""); } break; case IDC_ADDMEMBER: if (!GetCurrentGroupName(hDlg, group_name)) break; hList = GetDlgItem(hDlg, IDC_LOGGEDON); index = ListBox_GetCurSel(hList); if (index == LB_ERR) break; ListBox_GetText(hList, index, player_name); // Check for group too full if (ListBox_GetCount(GetDlgItem(hDlg, IDC_GROUPMEMBERS)) >= MAX_GROUPSIZE) { SetDlgItemText(hDlg, IDC_GROUPSTATUS, GetString(hInst, IDS_GROUPFULLDLG)); break; } // Add quotes around player to take care of spaces QuotePlayerName(player_name, quoted_name); if (GroupAdd(group_name, quoted_name) == 0) { SetDlgItemText(hDlg, IDC_GROUPSTATUS, GetString(hInst, IDS_CANTADDNAMEDLG)); break; } hList = GetDlgItem(hDlg, IDC_GROUPMEMBERS); ListBox_AddString(hList, player_name); SetDlgItemText(hDlg, IDC_GROUPSTATUS, ""); break; case IDC_DELMEMBER: if (!GetCurrentGroupName(hDlg, group_name)) break; hList = GetDlgItem(hDlg, IDC_GROUPMEMBERS); index = ListBox_GetCurSel(hList); if (index == LB_ERR) break; ListBox_GetText(hList, index, player_name); QuotePlayerName(player_name, quoted_name); if (GroupDeleteNames(group_name, quoted_name) != 1) { debug(("Deleting name %s from group %s failed\n", player_name, group_name)); break; } ListBox_DeleteString(hList, index); ListBox_SetCurSel(hList, min(index, ListBox_GetCount(hList) - 1)); SetDlgItemText(hDlg, IDC_GROUPSTATUS, ""); break; case IDOK: // Sent when Enter pressed on edit box hwndFocus = GetFocus(); if (hwndFocus == GetDlgItem(hDlg, IDC_ADDNAME)) { if (Edit_GetText(hwndFocus, player_name, MAX_CHARNAME) <= 0) break; Edit_SetSel(hwndFocus, 0, -1); if (!GetCurrentGroupName(hDlg, group_name)) break; // Check for group too full if (ListBox_GetCount(GetDlgItem(hDlg, IDC_GROUPMEMBERS)) >= MAX_GROUPSIZE) { SetDlgItemText(hDlg, IDC_GROUPSTATUS, GetString(hInst, IDS_GROUPFULLDLG)); break; } QuotePlayerName(player_name, quoted_name); if (GroupAdd(group_name, quoted_name) == 0) { SetDlgItemText(hDlg, IDC_GROUPSTATUS, GetString(hInst, IDS_CANTADDNAMEDLG)); break; } hList = GetDlgItem(hDlg, IDC_GROUPMEMBERS); ListBox_AddString(hList, player_name); SetDlgItemText(hDlg, IDC_GROUPSTATUS, ""); } else if (hwndFocus == GetDlgItem(hDlg, IDC_NEWGROUP)) { if (Edit_GetText(hwndFocus, group_name, MAX_GROUPNAME) <= 0) break; Edit_SetSel(hwndFocus, 0, -1); if (!GroupNew(group_name)) { SetDlgItemText(hDlg, IDC_GROUPSTATUS, GetString(hInst, IDS_GROUPFAILEDDLG)); break; } hCombo = GetDlgItem(hDlg, IDC_GROUPS); index = ComboBox_AddString(hCombo, group_name); ComboBox_SetCurSel(hCombo, index); if (num_groups >= MAX_NUMGROUPS) EnableWindow(GetDlgItem(hDlg, IDC_NEWGROUP), FALSE); FORWARD_WM_COMMAND(hDlg, IDC_GROUPS, hCombo, CBN_SELCHANGE, GroupDialogProc); SetDlgItemText(hDlg, IDC_GROUPSTATUS, ""); } else if (hwndFocus == GetDlgItem(hDlg, IDC_GROUPTELL)) { if (Edit_GetText(hwndFocus, say_string, MAXSAY) <= 0) break; if (!GetCurrentGroupName(hDlg, group_name)) break; TellGroup(group_name, say_string); // Prevent auto-repeat from causing lots of messages to be sent Edit_SetText(hwndFocus, ""); } break; case IDC_GROUP_DONE: case IDCANCEL: EndDialog(hDlg, IDOK); break; } }
/* This function handles the WM_COMMAND message. */ void FASTCALL CmdSignatureDlg_OnCommand( HWND hwnd, int id, HWND hwndCtl, UINT codeNotify ) { switch( id ) { case IDD_LIST: if( codeNotify == CBN_SELCHANGE ) { HWND hwndList; HWND hwndEdit; int index; index = (int)GetWindowLong( hwnd, DWL_USER ); hwndEdit = GetDlgItem( hwnd, IDD_EDIT ); if( EditMap_GetModified( hwndEdit ) ) { if( !CmdSignatureDlg_SaveSig( hwnd, index ) ) break; fCancelToClose( hwnd, IDCANCEL ); } hwndList = GetDlgItem( hwnd, IDD_LIST ); index = ComboBox_GetCurSel( hwndList ); CmdSignatureDlg_DisplaySig( hwnd, index ); } break; case IDD_NEW: { char sz[ 9 ]; if( Adm_Dialog( hRscLib, hwnd, MAKEINTRESOURCE( IDDLG_NEWSIG ), NewSig, (LPARAM)(LPSTR)sz ) ) { HWND hwndList; HWND hwndEdit; int index; index = (int)GetWindowLong( hwnd, DWL_USER ); hwndEdit = GetDlgItem( hwnd, IDD_EDIT ); hwndList = GetDlgItem( hwnd, IDD_LIST ); if( EditMap_GetModified( hwndEdit ) && ComboBox_GetCount( hwndList ) > 0 ) if( !CmdSignatureDlg_SaveSig( hwnd, index ) ) break; AnsiUpper( sz ); if( ( index = ComboBox_FindStringExact( hwndList, -1, sz ) ) == LB_ERR ) index = ComboBox_AddString( hwndList, sz ); EnableControl( hwnd, IDOK, TRUE ); EnableControl( hwnd, IDD_DELETE, TRUE ); ComboBox_SetCurSel( hwndList, index ); CmdSignatureDlg_DisplaySig( hwnd, index ); fCancelToClose( hwnd, IDCANCEL ); SetFocus( hwndEdit ); } break; } case IDD_DELETE: { HWND hwndList; int index; hwndList = GetDlgItem( hwnd, IDD_LIST ); if( ( index = ComboBox_GetCurSel( hwndList ) ) != CB_ERR ) { char sz[ _MAX_FNAME ]; PCAT pcat; PCL pcl; PTL ptl; /* Get confirmation first. */ if( IDNO == fMessageBox( hwnd, 0, GS(IDS_STR975), MB_YESNO|MB_ICONINFORMATION ) ) break; /* Get the signature and delete the signature * file itself. */ ComboBox_GetLBText( hwndList, index, sz ); lstrcat( sz, ".sig" ); Ameol2_DeleteFile( sz, DSD_SIG ); /* Remove the signature from the listbox and display the * next one, if there is one. */ if( ComboBox_DeleteString( hwndList, index ) == index ) --index; if( index != CB_ERR ) { ComboBox_SetCurSel( hwndList, index ); CmdSignatureDlg_DisplaySig( hwnd, index ); } else { InvalidateRect( hwndList, NULL, FALSE ); UpdateWindow( hwndList ); EnableControl( hwnd, IDD_DELETE, FALSE ); EnableControl( hwnd, IDOK, FALSE ); Edit_SetText( GetDlgItem( hwnd, IDD_EDIT ), "" ); } /* For every topic which used the signature just deleted, * change it to the global signature. */ ComboBox_GetLBText( hwndList, index, sz ); for( pcat = Amdb_GetFirstCategory(); pcat; pcat = Amdb_GetNextCategory( pcat ) ) for( pcl = Amdb_GetFirstFolder( pcat ); pcl; pcl = Amdb_GetNextFolder( pcl ) ) for( ptl = Amdb_GetFirstTopic( pcl ); ptl; ptl = Amdb_GetNextTopic( ptl ) ) { TOPICINFO topicinfo; Amdb_GetTopicInfo( ptl, &topicinfo ); if( lstrcmp( topicinfo.szSigFile, sz ) == 0 ) Amdb_SetTopicSignature( ptl, szGlobalSig ); } fCancelToClose( hwnd, IDCANCEL ); } break; } case IDOK: { HWND hwndEdit; int index; index = (int)GetWindowLong( hwnd, DWL_USER ); hwndEdit = GetDlgItem( hwnd, IDD_EDIT ); if( EditMap_GetModified( hwndEdit ) ) if( !CmdSignatureDlg_SaveSig( hwnd, index ) ) break; EndDialog( hwnd, TRUE ); break; } case IDCANCEL: { HWND hwndEdit; hwndEdit = GetDlgItem( hwnd, IDD_EDIT ); if( EditMap_GetModified( hwndEdit ) ) { register int r; r = fMessageBox( hwnd, 0, GS(IDS_STR516), MB_YESNOCANCEL|MB_ICONINFORMATION ); if( r == IDCANCEL ) break; if( r == IDYES ) { int index; index = (int)GetWindowLong( hwnd, DWL_USER ); if( !CmdSignatureDlg_SaveSig( hwnd, index ) ) break; } } EndDialog( hwnd, FALSE ); break; } } }
BOOL plResponderProc::DlgProc(TimeValue t, IParamMap2 *pm, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static UINT dragListMsg = 0; if (dragListMsg != 0 && msg == dragListMsg) if (DragListProc(hWnd, (DRAGLISTINFO*)lParam)) return TRUE; switch (msg) { case WM_INITDIALOG: { if (!fhMenu) ICreateMenu(); fhDlg = hWnd; fhList = GetDlgItem(fhDlg, IDC_CMD_LIST); fCurState = 0; fCmdIdx = -1; fPB = pm->GetParamBlock(); fComp = (plResponderComponent*)fPB->GetOwner(); fComp->IFixOldPB(); LoadState(); // Make it so the user can drag commands to different positions dragListMsg = RegisterWindowMessage(DRAGLISTMSGSTRING); MakeDragList(GetDlgItem(hWnd, IDC_CMD_LIST)); // Setup the State Name combo HWND hStateName = GetDlgItem(hWnd, IDC_STATE_COMBO); ComboBox_LimitText(hStateName, 256); // I give up, Windows doesn't want to tell me the real font size #if 0//def CUSTOM_DRAW // TEMP HDC hDC = GetDC(hStateName); HFONT sysFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); HFONT oldFont = SelectFont(hDC, sysFont); TEXTMETRIC tm; GetTextMetrics(hDC, &tm); ComboBox_SetItemHeight(hStateName, 0, tm.tmHeight+2); DeleteFont(SelectFont(hDC, oldFont)); ReleaseDC(hStateName, hDC); #endif // Add the commands int idx = ComboBox_AddString(hStateName, "Add State"); ComboBox_SetItemData(hStateName, idx, kStateAdd); idx = ComboBox_AddString(hStateName, "Remove Current State"); ComboBox_SetItemData(hStateName, idx, kStateRemove); idx = ComboBox_AddString(hStateName, "Set Current as Default"); ComboBox_SetItemData(hStateName, idx, kStateDefault); idx = ComboBox_AddString(hStateName, "Copy Current State"); ComboBox_SetItemData(hStateName, idx, kStateCopy); HWND hSwitchCombo = GetDlgItem(hWnd, IDC_SWITCH_COMBO); int numStates = fPB->Count(kResponderStateName); for (int i = 0; i < numStates; i++) { const char *stateName = fPB->GetStr(kResponderStateName, 0, i); char buf[128]; if (!stateName || *stateName == '\0') { sprintf(buf, "State %d", i+1); stateName = buf; } ComboBox_InsertString(hStateName, i, stateName); ComboBox_AddString(hSwitchCombo, stateName); } ComboBox_SetCurSel(hStateName, fCurState); ComboBox_SetCurSel(hSwitchCombo, fStatePB->GetInt(kStateCmdSwitch)); } return TRUE; #ifdef CUSTOM_DRAW case WM_DRAWITEM: if (wParam == IDC_STATE_COMBO) { IDrawComboItem((DRAWITEMSTRUCT*)lParam); return TRUE; } break; #endif case WM_SETCURSOR: { if (HIWORD(lParam) == WM_RBUTTONDOWN && HWND(wParam) == GetDlgItem(hWnd, IDC_CMD_LIST)) { ICmdRightClick(HWND(wParam)); return TRUE; } } break; case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED) { if (LOWORD(wParam) == IDC_ADD_ACTIVATOR) { // Adding an activator. Set it and refresh the UI to show it in our list. plPick::Activator(fPB, kResponderActivators, false); pm->Invalidate(kResponderActivators); return TRUE; } else if (LOWORD(wParam) == IDC_ADD_CMD) { AddCommand(); return TRUE; } // Remove the currently selected condition else if (LOWORD(wParam) == IDC_REMOVE_CMD) { RemoveCurCommand(); return TRUE; } } else if (HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_CMD_LIST) { ICreateCmdRollups(); return TRUE; } else if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_SWITCH_COMBO) { int sel = ComboBox_GetCurSel((HWND)lParam); if (sel != CB_ERR) fStatePB->SetValue(kStateCmdSwitch, 0, sel); } else if (LOWORD(wParam) == IDC_STATE_COMBO) { HWND hCombo = (HWND)lParam; int code = HIWORD(wParam); // Disable accelerators when the combo has focus, so that new names can be typed in if (code == CBN_SETFOCUS) { plMaxAccelerators::Disable(); return TRUE; } else if (code == CBN_KILLFOCUS) { plMaxAccelerators::Enable(); return TRUE; } // State name changed, save it in the PB else if (code == CBN_EDITCHANGE) { char buf[256]; ComboBox_GetText(hCombo, buf, sizeof(buf)); const char *curName = fPB->GetStr(kResponderStateName, 0, fCurState); if (!curName || strcmp(buf, curName)) { HWND hSwitch = GetDlgItem(hWnd, IDC_SWITCH_COMBO); int sel = ComboBox_GetCurSel(hSwitch); ComboBox_DeleteString(hSwitch, fCurState); ComboBox_InsertString(hSwitch, fCurState, buf); ComboBox_SetCurSel(hSwitch, sel); fPB->SetValue(kResponderStateName, 0, buf, fCurState); ComboBox_DeleteString(hCombo, fCurState); ComboBox_InsertString(hCombo, fCurState, buf); // ComboBox_SetCurSel(hCombo, fCurState); } return TRUE; } else if (code == CBN_SELCHANGE) { int sel = ComboBox_GetCurSel(hCombo); int type = ComboBox_GetItemData(hCombo, sel); if (type == kStateAdd) { IParamBlock2 *pb = CreateParameterBlock2(&gStateBlock, nil); fCurState = AddState(pb); fCmdIdx = -1; } else if (type == kStateRemove) { int count = fPB->Count(kResponderState); // Don't let the user remove the last state if (count == 1) { hsMessageBox("You must have at least one state.", "Error", hsMessageBoxNormal); ComboBox_SetCurSel(hCombo, fCurState); return TRUE; } // Verify that the user really wants to delete the state else { int ret = hsMessageBox("Are you sure you want to remove this state?", "Verify Remove", hsMessageBoxYesNo); if (ret == hsMBoxNo) { ComboBox_SetCurSel(hCombo, fCurState); return TRUE; } } fPB->Delete(kResponderState, fCurState, 1); fPB->Delete(kResponderStateName, fCurState, 1); ComboBox_DeleteString(hCombo, fCurState); ComboBox_SetCurSel(hCombo, 0); HWND hSwitch = GetDlgItem(hWnd, IDC_SWITCH_COMBO); ComboBox_DeleteString(hSwitch, fCurState); // If the deleted state was the default, set the default to the first int defState = fPB->GetInt(kResponderStateDef); if (fCurState == defState) fPB->SetValue(kResponderStateDef, 0, 0); else if (fCurState < defState) fPB->SetValue(kResponderStateDef, 0, defState-1); // Patch up the switch commands for (int i = fCurState; i < fPB->Count(kResponderState); i++) { IParamBlock2 *pb = (IParamBlock2*)fPB->GetReferenceTarget(kResponderState, 0, i); int switchState = pb->GetInt(kStateCmdSwitch); // TODO: might want to warn about this if (switchState == fCurState) pb->SetValue(kStateCmdSwitch, 0, 0); else if (switchState > fCurState) pb->SetValue(kStateCmdSwitch, 0, switchState-1); } fCurState = 0; fCmdIdx = -1; } else if (type == kStateDefault) { // Set the current state as the default fPB->SetValue(kResponderStateDef, 0, fCurState); ComboBox_SetCurSel(hCombo, fCurState); } else if (type == kStateCopy) { // Clone the state PB IParamBlock2 *origPB = (IParamBlock2*)fPB->GetReferenceTarget(kResponderState, 0, fCurState); IParamBlock2 *copyPB = (IParamBlock2*)origPB->Clone(gMyRemapDir); fCurState = AddState(copyPB); fCmdIdx = -1; } else { fCurState = sel; fCmdIdx = -1; } LoadState(); return TRUE; } } } return FALSE; }
int ComboBox::DeleteString(int index) { return ComboBox_DeleteString(m_hWindow, index); }
int CWinCombo::DeleteString(int Index) { if(m_Hwnd) return ComboBox_DeleteString(m_Hwnd, Index); else return CB_ERR; }