📄 gui.c
字号:
for(index=0;index<MAXCLASSES;index++) SendDlgItemMessage(hDlg,IDC_CLASS,CB_ADDSTRING,0,(LONG)(LPSTR)szClasses[index]); for(index=0;index<MAXROOTS;index++) SendDlgItemMessage(hDlg,IDC_ROOTSERVER,CB_ADDSTRING,0,(LONG)(LPSTR)szRoots[index]); SendDlgItemMessage (hDlg, IDC_QueryType, CB_SETCURSEL, SendDlgItemMessage(hDlg,IDC_QueryType,CB_FINDSTRINGEXACT,(WPARAM)-1,(LPARAM)(LPCTSTR)current_qtype),0); SendDlgItemMessage (hDlg, IDC_CLASS, CB_SETCURSEL, SendDlgItemMessage(hDlg,IDC_CLASS,CB_FINDSTRINGEXACT,(WPARAM)-1,(DWORD)(LPCTSTR)current_class),0); SendDlgItemMessage (hDlg, IDC_ROOTSERVER, CB_SETCURSEL, SendDlgItemMessage(hDlg,IDC_ROOTSERVER,CB_FINDSTRINGEXACT,(WPARAM)-1,(DWORD)(LPCTSTR)rootServerName),0); if (nameserver_set) SetDlgItemText(hDlg, IDC_NAMESERVER, (LPTSTR)current_nameserver); changing_size = FALSE; current_lines = 0; oldlines = 0; SendDlgItemMessage(gDlg, IDC_OUTPUT, LB_SETHORIZONTALEXTENT, (WPARAM)0,0); current_extent = 0; opentempfile(); } return (TRUE); // users messages means return // when we get return check if any commands are pending case WM_DESTROY: break; case WM_COMMAND: { WORD cmd = GET_WM_COMMAND_ID(wParam,lParam); // don't do this if command is the return key if (cmd != IDOK) { if ((editednameserver) && (cmd != IDC_NAMESERVER)) { process_nameserver_changes(hDlg); } if ((editeddomain) && (cmd != IDC_DOMAIN)) { process_domain_changes(hDlg); } } } switch (GET_WM_COMMAND_ID(wParam, lParam)) { case IDOK: // special case means the return button was pressed { HWND hwndTest; hwndTest = GetFocus() ; if ((hwndTest == GetDlgItem(hDlg,IDC_QUERYSTRING)) && editedquery) { i = GetDlgItemText(hDlg, IDC_QUERYSTRING, (LPTSTR)Query, NAME_LEN); if (i != 0) process_query_button(hDlg); else editedquery = FALSE; } else if ((hwndTest == GetDlgItem(hDlg,IDC_NAMESERVER)) && editednameserver) { process_nameserver_changes(hDlg); } else if ((hwndTest == GetDlgItem(hDlg,IDC_DOMAIN)) && editeddomain) { process_domain_changes(hDlg); } else if (editednameserver) // the above hwnd doesnot work any longer with combo boxes so the below // is a kludge to get return working again { process_nameserver_changes(hDlg); } } break; case IDCANCEL: EndDialog(hDlg, TRUE); fclose(outputfile); _unlink("nslookup.tmp"); ExitThread(0); break; case IDC_HIDE: GetWindowRect(hDlg, &savedlargerc); EndDialog(hDlg, TRUE); changing_size = TRUE; enlarging = FALSE; hInstance = GetModuleHandle (NULL); DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG2), NULL, lpDialogFunc); break; case IDC_ENLARGE: GetWindowRect(hDlg, &savedsmallrc); EndDialog(hDlg, TRUE); changing_size = TRUE; enlarging = TRUE; hInstance = GetModuleHandle (NULL); DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, lpDialogFunc); break; case IDC_COPY: // copy to clipboard { // first get the current selection from the dialog and then copy to a string // use filestring int selcount = SendDlgItemMessage (hDlg, IDC_OUTPUT, LB_GETSELCOUNT,0,0); int rv = 0; int i = 0; HGLOBAL hData; LPVOID lpData; SetCursor(hWaitCursor); if (selcount > 5000) { PrintToBox("\n\nCan only copy a maximum of 5000 lines to the Clipboard!\n\n"); } else if (selcount > 0) { // now get the selections rv = SendDlgItemMessage(hDlg,IDC_OUTPUT,LB_GETSELITEMS,(WPARAM)selcount,(LPARAM)(LPINT)&selarray); if (rv != 0) { // now go and get each item filestring[0] = '\0'; for (i=0; i<rv; i++) { SendDlgItemMessage(hDlg,IDC_OUTPUT,LB_GETTEXT, (WPARAM)selarray[i], (LPARAM)(LPCTSTR)text); // now concat to file string strcat(filestring,text); strcat(filestring,"\n\r"); } /* Allocate memory and copy the string to it. */ hData = GlobalAlloc(GMEM_MOVEABLE, strlen(filestring)+1); if (hData == NULL || (lpData = GlobalLock(hData)) == NULL) { PrintToBox("\n\nCopy To Clipboard Failed - Out of Memory\n\n"); } else { lstrcpy(lpData, (LPCTSTR)filestring); GlobalUnlock(hData); /* * Clear the current contents of the clipboard, * and set the data handle to the new string. */ if (OpenClipboard(hDlg)) { EmptyClipboard(); SetClipboardData(CF_TEXT, hData); CloseClipboard(); SendDlgItemMessage(hDlg,IDC_OUTPUT,LB_SETSEL, (WPARAM)(BOOL)FALSE,(LPARAM)(UINT)-1); } } hData = NULL; } } } SetCursor(hStdCursor); break; case IDQUERY: i = GetDlgItemText(hDlg, IDC_QUERYSTRING, (LPTSTR)Query, NAME_LEN); if (i == 0) { editedquery = FALSE; break; } process_query_button(hDlg); break; case IDC_DEBUG: CheckDlgButton(hDlg, IDC_D2, 0); // turn off d2 button SetOption("nod2"); if (IsDlgButtonChecked(hDlg, IDC_DEBUG)) { SetOption("deb"); CheckDlgButton(hDlg, IDC_D2, 0); // turn off d2 button SetOption("nod2"); } else SetOption("nodeb"); break; case IDC_LSERVER: if (IsDlgButtonChecked(hDlg, IDC_LSERVER )) locallserver = TRUE; else locallserver = FALSE; break; case IDC_D2: // debug has to be on for d2 to work if (IsDlgButtonChecked(hDlg, IDC_D2)) { SetOption("deb"); SetOption("d2"); CheckDlgButton(hDlg, IDC_DEBUG, 1);// turn off debug button } else SetOption("nod2"); break; case IDC_CLEAR: SendDlgItemMessage(hDlg, IDC_OUTPUT, LB_RESETCONTENT, 0, 0); current_lines = 0; oldlines = 0; SendDlgItemMessage(gDlg, IDC_OUTPUT, LB_SETHORIZONTALEXTENT, (WPARAM)0,0); current_extent = 0; break; case IDC_IGNORE: if (IsDlgButtonChecked(hDlg, IDC_IGNORE)) SetOption("ig"); else SetOption("noig"); break; case IDC_RECURSE: if (IsDlgButtonChecked(hDlg, IDC_RECURSE)) SetOption("rec"); else SetOption("norec"); break; case IDC_VC: if (IsDlgButtonChecked(hDlg, IDC_VC)) SetOption("v"); else SetOption("nov"); break; case IDC_PORT: i = GetDlgItemInt(hDlg,IDC_PORT,NULL,FALSE); if ((i != 0) && (i << 65536)) { sprintf(Query,"po=%d",i); SetOption(Query); } break; case IDC_RETRY: i = GetDlgItemInt(hDlg, IDC_RETRY, NULL, FALSE); if ((i != 0) && (i << 65536)) { sprintf(Query,"ret=%d",i); SetOption(Query); } break; case IDC_TIMEOUT: i = GetDlgItemInt(hDlg, IDC_TIMEOUT, NULL, FALSE); if ((i != 0) && (i << 65536)) { sprintf(Query,"ti=%d",i); SetOption(Query); } break; case IDC_DOMAIN: i = GetDlgItemText(hDlg, IDC_DOMAIN, (LPTSTR)text, NAME_LEN); if (strcmp(Domain,text) != 0) { editeddomain = TRUE; } break; case IDC_NAMESERVER: /* problem: after hitting return the nameserver gets changed but this flag immediately gets set again so that as soon as we leave the field it gets set a second time .... solution only set this if nameserver has changed by comparing field to current variable */ i = GetDlgItemText(hDlg, IDC_NAMESERVER, (LPTSTR)text, NAME_LEN); if (strncmp(defaultServer,text,strlen(defaultServer)) != 0) { editednameserver = TRUE; } break; case IDC_OUTPUT: break; case IDC_GUIHELP: oldlines = current_lines; PrintHelp(); processtempfile(); bringtoend(oldlines); break; case IDC_ALL: oldlines = current_lines; SetOption("all"); processtempfile(); bringtoend(oldlines); break; case IDC_QueryType: index = SendDlgItemMessage(hDlg, IDC_QueryType, CB_GETCURSEL, 0, 0); len = SendDlgItemMessage(hDlg, IDC_QueryType, CB_GETLBTEXT, index, (DWORD)(LPCSTR)qtype); sprintf(Query,"ty=%s",qtype); SetOption(Query); strcpy(current_qtype,qtype); break; case IDC_ROOTSERVER: index = SendDlgItemMessage(hDlg, IDC_ROOTSERVER, CB_GETCURSEL, 0, 0); len = SendDlgItemMessage(hDlg, IDC_ROOTSERVER, CB_GETLBTEXT, index, (DWORD)(LPCSTR)text); if (index != 0) { sprintf(Query,"ro %s",text); strcpy(rootServerName,text); SetOption(Query); } break; case IDC_QUERYSTRING: editedquery = TRUE; break; case IDC_CLASS: index = SendDlgItemMessage(hDlg, IDC_CLASS, CB_GETCURSEL, 0, 0); len = SendDlgItemMessage(hDlg, IDC_CLASS, CB_GETLBTEXT, index, (DWORD)(LPCSTR)qtype); sprintf(Query,"cl=%s",qtype); SetOption(Query); strcpy(current_class,qtype); break; case IDD_ABOUT: hInstance2 = GetModuleHandle (NULL); DialogBox(hInstance2,MAKEINTRESOURCE(IDD_ABOUTBOX),hDlg, aboutDialogFunc); break; } break; default: return(FALSE); } return(TRUE);}void gui() // starts here{ hStdCursor=LoadCursor((HINSTANCE)NULL,IDC_ARROW); hWaitCursor=LoadCursor((HINSTANCE)NULL,IDC_APPSTARTING); hInstance = GetModuleHandle (NULL); DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, lpDialogFunc); fclose(outputfile); _unlink("nslookup.tmp"); return;}void PrintToBox(char *newtext, int count){ extern HWND gDlg; int ctr = 0; int ctr2; char *cstring_ptr; char letter; BOOLEAN pending = FALSE; int len1 = strlen(newtext); if (count != 0) len1 = count; // printf("in print to box with string = %s \n",newtext); if (current_string == NULL) current_string = malloc(3000); cstring_ptr = current_string; // lgk we need to parse the string and replace tabs with 5 spaces and newlines *cstring_ptr = '\0'; for (ctr=0; ctr <= len1; ctr++) { letter = (char)*newtext; if (letter == '\t') { pending = TRUE; for (ctr2 = 0; ctr2 < 5; ctr2++) *cstring_ptr++ = ' '; } else if (letter == '\n') { *cstring_ptr++ = '\0'; SendDlgItemMessage(gDlg, IDC_OUTPUT, LB_ADDSTRING, 0,(LPARAM)(LPCTSTR) current_string); checkhscroll(current_string); cstring_ptr = current_string; *cstring_ptr = '\0'; pending = FALSE; ++current_lines; } else if (letter == '\0') // ignore { } else if (letter == '\r') // ignore { *cstring_ptr++ = ' '; pending = TRUE; } else // process { *cstring_ptr++ = letter; pending = TRUE; } ++newtext; } if (pending) { *cstring_ptr++ = '\0'; SendDlgItemMessage(gDlg, IDC_OUTPUT, LB_ADDSTRING, 0,(LPARAM)(LPCTSTR) current_string); checkhscroll(current_string); ++current_lines; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -