⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtelnet.c

📁 dtelent是开源的开发项目
💻 C
📖 第 1 页 / 共 3 页
字号:
 *
 * Args:
 * winPos - size that window is about to be given by Windows
 *
 * This code is the result of sweating litres of blood trying to tie
 * down all of the different ways that Win3.1 and Win95 resize a
 * window.
 */
static void telnetWindowPosChanging(WINDOWPOS* winPos)
{
    RECT window;		/* current window position */
    RECT client;		/* current client window */
    RECT status;		/* current status window */
    SIZE pad;			/* padding around terminal window */

    SIZE proposed;		/* proposed terminal size */
    SIZE preferred;		/* preferred terminal size */

		/* We are only interested in window resizing
     */
    if (winPos->flags & (SWP_NOSIZE|SWP_HIDEWINDOW
			 |SWP_SHOWWINDOW|SWP_DRAWFRAME))
	return;

    /* Determine the current dimensions of the various windows
     */
    GetWindowRect(telnetWnd, &window);
    GetClientRect(telnetWnd, &client);
    GetWindowRect(statusGetWnd(), &status);

    /* Calculate the padding around the terminal window
     */
    pad.cx = window.right - window.left - client.right;
    pad.cy = window.bottom - window.top - client.bottom
	+ status.bottom - status.top;

		/* Work out the proposed terminal window size
     */
    proposed.cx = winPos->cx - pad.cx;
    proposed.cy = winPos->cy - pad.cy;

    /* Get the terminal child window to adjust the proposed window
     * size adjusted to the preferred size.
     */
    preferred = proposed;
    termWindowPosChanging(&preferred);

		/* Apply the preferred size as a delta to the proposed
     */
    proposed.cx -= preferred.cx;
    proposed.cy -= preferred.cy;

		/* Compare the proposed terminal size with the preferred size and
     * make adjustments to the window resize accordingly.
     */
    if (proposed.cx != 0) {
	/* Horizontal size adjusted
	 */
	if (winPos->x != window.left) {
	    /* Resizing from left - adjust winPos->x for preferred size
	     */
	    winPos->x += proposed.cx;
	    winPos->cx = preferred.cx + pad.cx;
	} else
	    /* Resizing from right - adjust winPos->cx for preferred size
	     */
	    winPos->cx -= proposed.cx;
    }

    if (proposed.cy != 0) {
	/* Vertical size was adjusted
	 */
	if (winPos->y != window.top) {
	    /* Resizing from top - adjust winPos->y for preferred size
	     */
	    winPos->y += proposed.cy;
	    winPos->cy = preferred.cy + pad.cy;
	} else
	    /* Resizing from bottom - adjust winPos->cy for preferred size
			 */
	    winPos->cy -= proposed.cy;
    }
}

/* The window has just been resized - enforce the new size on the
 * child windows.
 *
 * Args:
 * type - the type of resize that just occurred
 * cx -   the new width of the application window
 * cy -   the new height of the application window
 */
static void telnetSetWindowSize(UINT type, int cx, int cy)
{
    RECT status;		/* size / location of status bar */
    int statusHeight;		/* height of status bar */

    if (type == SIZE_MINIMIZED)
	return;

    /* Move the status bar to keep it at the bottom of the window, and
     * at full width.
     */
    GetWindowRect(statusGetWnd(), &status);
		statusHeight = status.bottom - status.top;
    if (type == SIZE_RESTORED || type == SIZE_MAXIMIZED)
	termSetWindowSize(cx, cy - statusHeight);
    MoveWindow(statusGetWnd(), 0, cy - statusHeight, cx, statusHeight, TRUE);
}

/* Window procedure for the application window
 */
long CALLBACK mainWndProc(HWND wnd, UINT message,
			  WPARAM wparam, LPARAM lparam)
{
    char buff [_MAX_PATH];
    HMENU menu;

    switch (message) {
    case WM_COMMAND:
	switch (LOWORD (wparam)) {
	case ID_CONNECT_NEW:
	    /* Create a new instance of dtelnet */
	    GetModuleFileName(instanceHnd, buff, sizeof(buff));
	    WinExec(buff, SW_SHOW);
	    break;
	case ID_CONNECT_REMOTE_SYSTEM:
	    showConnectDialog(instanceHnd, wnd);
	    break;
	case ID_CONNECT_DISCONNECT:
			socketDisconnect();
	    break;
	case ID_CONNECT_PROXY:
	    showProxyDialog(instanceHnd, wnd);
	    break;
	case ID_CONNECT_EXIT_DISCONNECT:
	    connectToggleExitOnDisconnect();
	    break;
	case ID_EXIT:
	    telnetExit();
	    break;

	case ID_EDIT_COPY:
			termSelectCopy();
	    break;
	case ID_EDIT_PASTE:
			termSelectPaste();
			break;
	case ID_EDIT_AUTO_COPY:
			termToggleAutoCopy();
			break;

	case ID_CM_FREE:
	case ID_CM_TEXT:
	    editSetCMMode (LOWORD(wparam));
	    break;

    case ID_MANAGE_FAVORITES:
	fileTypeManage(instanceHnd, wnd);
	break;

    case ID_ADD_TO_FAVORITES:
	fileFavCreate(instanceHnd, wnd);
	break;

	case ID_TERMINAL_FONT:
			showFontDialog(instanceHnd, wnd);
			break;
	case ID_TERMINAL_BOTTOM_ON_OUTPUT:
			termToggleBottomOnOutput();
			break;
	case ID_TERMINAL_CS_BLOCK:
	    termSetCursorStyle(cursorBlock);
	    break;
	case ID_TERMINAL_CS_VERTLINE:
	    termSetCursorStyle(cursorVertLine);
	    break;
	case ID_TERMINAL_CS_UNDERLINE:
	    termSetCursorStyle(cursorUnderLine);
	    break;
	case ID_TERMINAL_BACKSPACE_ALT:
			connectSetBs2Del(!connectGetBs2DelOption());
			break;
	case ID_TERMINAL_START_LOGGING:
			logStart();
			break;
	case ID_TERMINAL_STOP_LOGGING:
			logStop();
			break;
	case ID_TERMINAL_LOG_SESSION:
	    logToggleSession();
	    break;
	case ID_TERMINAL_LOG_PROTOCOL:
			logToggleProtocol();
	    break;
	case ID_TERMINAL_DEFINITION:
			terminalDefShowDialog(instanceHnd, wnd);
	    break;


	case ID_TERMINAL_PRINTPREF:
	    printingPrefDialog();
	    break;
	case ID_TERMINAL_ATTPRINT:
	    termToggleAttachedPrinter();
	    break;
	case ID_TERMINAL_ENABLE_PRINTSCR:
	    termTogglePrintScreen();
	    break;
	case ID_TERMINAL_PRINTSCREEN:
	    if (termPrintScreenEnabled()) printingPrintScreen();
	    break;

	case ID_HELP_CONTENTS:
	    WinHelp(termGetWnd(), helpFileName, HELP_INDEX, 0L);
	    break;
	case ID_HELP_HELP:
	    WinHelp(termGetWnd(), "WINHELP.HLP", HELP_INDEX, 0L);
	    break;
	case ID_HELP_ABOUT:
	    aboutShowDialog(instanceHnd, wnd);
	    break;

	default:
	    /* handle connection history items */
	    if (wparam >= ID_CONNECT_HISTORY
		&& wparam < ID_CONNECT_HISTORY + MAX_HISTORY) {
		connectHistory(wparam - ID_CONNECT_HISTORY);
		break;
	    }
	    /* handle emulation menu items */
	    else if (wparam >= ID_MENU_EMULATE_FIRST
		&& wparam < ID_MENU_EMULATE_FIRST + emuls.num) {
		connectRememberTerm(emuls.names[wparam - ID_MENU_EMULATE_FIRST]);
		emulSetTerm(emuls.names[wparam - ID_MENU_EMULATE_FIRST]);
		statusSetTerm();
	    }
	    /* handle 'Favorites' menu items */
	    else if (wparam >= ID_FAVORITES_FIRST && wparam < ID_FAVORITES_MAX)
	    {
		fileExecFavorites(GetMenu(wnd), wparam);
	    }
	    /* handle 'CharSet' menu items */
	    else if (wparam >= ID_TERMINAL_SERVER_MIN &&
		     wparam <  ID_TERMINAL_SERVER_LIM) {
		char *charset;

		charset = dtcEC_GetName (wparam - ID_TERMINAL_SERVER_MIN + 1);
		if (charset) {
		    emulSetCharset (charset);
		    dtcEC_CheckMenuItem (charset);
		}
	    }
	    else
		return DefWindowProc(wnd, message, wparam, lparam);
	}
	return 0;

    case WM_ERASEBKGND:
	/* No point erasing the window, it is obscured by child windows.
	 */
	return 1;
    case WM_DESTROY:
	PostQuitMessage(0);
	return 0;

    case WM_SETFOCUS:
	termSetFocus();
	return 0;
    case WM_KILLFOCUS:
	termKillFocus();
	return 0;

#ifdef WIN32
    case WM_ENTERSIZEMOVE:
	rawResizeBegin();
	break;
    case WM_EXITSIZEMOVE:
	rawResizeEnd();
	break;
#endif
    case WM_WINDOWPOSCHANGING:
	telnetWindowPosChanging((WINDOWPOS*)lparam);
	return 0;
    case WM_SIZE:
	telnetSetWindowSize(wparam, LOWORD(lparam), HIWORD(lparam));
	return 0;
    case WM_MOVE:
	recalcInitPos();
	break;

    case WM_INITMENU:
	if ((HMENU)wparam == GetMenu(wnd))
	    initMenu(wnd, (HMENU)wparam);
	return 0;

    case WM_CHAR:
	termKeyPress(wparam, lparam);
	break;
    case WM_KEYDOWN:
	termKeyDown(wparam, lparam);
	break;
    case WM_SYSKEYDOWN:
	if (!socketConnected())
	    break;
	termSysKeyDown(wparam, lparam);
	return 0;
    case WM_SYSKEYUP:
    case WM_SYSCHAR:
	if (!socketConnected())
	    break;
	return 0;
    case WM_CREATE:
	menu = GetMenu (wnd);
	menu = GetSubMenu (menu, MENU_TERMINAL_POSITION);
	menu = GetSubMenu (menu, MENU_SERVCHAR_POSITION);
	dtcEC_InitMenu (menu, ID_TERMINAL_SERVER_ANSI);
	break;
    }
    return DefWindowProc(wnd, message, wparam, lparam);
}

/* Set the application window title.
 *
 * When we are online, the session host/port are displayed.
 * When we are logging, the name of the log file is displayed.
 */
void telnetSetTitle()
{
    char title[256];

    if (termHasTitle())
	strcpy(title, termGetTitle());
    else {
	if (socketConnected())
			sprintf(title, "%s/%s", socketGetHost(), socketGetPort());
	else
	    strcpy(title, telnetAppName());
    }

    if (logGetTitle() != NULL)
	sprintf(title + strlen(title), " - %s", logGetTitle());

    SetWindowText(telnetWnd, title);
}

/* Determine the name of the application help file
 */
static void makeHelpFileName(void)
{
    getExePath(instanceHnd, helpFileName);
    if (strlen(helpFileName) + 13 < _MAX_PATH)
	strcat(helpFileName, "dtelnet.hlp");
    else
	strcat(helpFileName, "?");
}

/* Determine the name of the application .INI file
 */
static void makeIniFileName(void)
{
    getExePath(instanceHnd, iniFileName);
    if (strlen(iniFileName) + 13 < _MAX_PATH)
	strcat(iniFileName, "dtelnet.ini");
    else
	strcpy(iniFileName, "dtelnet.ini");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -