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

📄 windiff.c

📁 <Win2k系统编程>源码.次数为国人自编,内容丰富,还是不错的.
💻 C
📖 第 1 页 / 共 5 页
字号:
 * Function: DoResize
 *
 * Purpose:
 *
 * Position child windows on a resize of the main window
 */
void
DoResize(HWND hWnd)
{
        RECT rc;
        int bar_width;

        GetClientRect(hWnd, &rc);
        MoveWindow(hwndStatus, 0, 0, rc.right - rc.left, status_height, TRUE);

        bar_width = (rc.right - rc.left) * BAR_WIN_WIDTH / 100;

        /* bar window is hidden unless in expand mode */
        if ((DisplayMode == MODE_EXPAND) && (picture_mode)) {
                ShowWindow(hwndBar, SW_SHOW);
                MoveWindow(hwndBar, 0, status_height,
                        bar_width, rc.bottom - status_height, TRUE);
                MoveWindow(hwndRCD, bar_width, status_height,
                        (rc.right - rc.left) - bar_width,
                        rc.bottom - status_height, TRUE);
        } else {
                MoveWindow(hwndRCD, 0, status_height, (rc.right - rc.left),
                        rc.bottom - status_height, TRUE);
                ShowWindow(hwndBar, SW_HIDE);
        }

}
/***************************************************************************
 * Function: AboutBox
 *
 * Purpose:
 *
 * Standard processing for About box.
 */
int APIENTRY
AboutBox(HWND hDlg, unsigned message, UINT wParam, LONG lParam)
{
        char ch[256];

        switch (message) {

        case WM_INITDIALOG:
                wsprintf((LPTSTR)ch, "%d.%02d", Version, SubVersion);
                SetDlgItemText(hDlg, IDD_VERSION, ch);
                return(TRUE);

        case WM_COMMAND:
                switch (GET_WM_COMMAND_ID(wParam, lParam)) {
                case IDOK:
                        EndDialog(hDlg, 0);
                        return(TRUE);
                }
                break;
        }
        return(FALSE);
}


/* -- menu commands ---------------------------------------------------*/

/***************************************************************************
 * Function: DoPrint
 *
 * Purpose:
 *
 * Print the current view 
 */
void
DoPrint(void)
{
        Title head, foot;
        PrintContext context;
        TCHAR szPage[50];

        /* print context contains the header and footer. Use the
         * default margins and printer selection
         */

        /* we set the table id to be TABID_PRINTER. When the table calls
         * back to get text and properties, we use this to indicate
         * that the table refered to is the 'current_view', but in print
         * mode, and thus we will use different colours/fonts.
         */
        context.head = &head;
        context.foot = &foot;
        context.margin = NULL;
        context.pd = NULL;
        context.id = TABID_PRINTER;

        /* header is filenames or just WinDiff if no names known*/
        if (strlen(AppTitle) > 0) {
                head.ptext = AppTitle;
        } else {
                head.ptext = "WinDiff";
        }

        /* header is centred, footer is right-aligned and
         * consists of the page number
         */
        head.props.valid = P_ALIGN;
        head.props.alignment = P_CENTRE;
        lstrcpy(szPage,LoadRcString(IDS_PAGE));
        foot.ptext = (LPSTR)szPage;
        foot.props.valid = P_ALIGN;
        foot.props.alignment = P_RIGHT;

        SendMessage(hwndRCD, TM_PRINT, 0, (DWORD) (LPSTR) &context);
}

/***************************************************************************
 * Function: FindNextChange
 *
 * Purpose:
 *
 * Find the next line in the current view that is
 * not STATE_SAME. Start from the current selection, if valid, or
 * from the top of the window if no selection.
 *
 */
BOOL
FindNextChange(void)
{
        long row;

        /* start from the selection or top of the window if no selection */
        if (selection >= 0) {
                row = selection;
        } else {
                row = (int) SendMessage(hwndRCD, TM_TOPROW, FALSE, 0);
        }


        /* find the next 'interesting' line */
        row = view_findchange(current_view, row, TRUE);
        if (row >= 0) {
                SetSelection(row);
                return(TRUE);
        } else {
                windiff_UI(TRUE);
                MessageBox(hwndClient, LoadRcString(IDS_NO_MORE_CHANGES), "Windiff",
                        MB_ICONINFORMATION|MB_OK);
                windiff_UI(FALSE);

                return(FALSE);
        }
}

/***************************************************************************
 * Function: FindPrevChange
 *
 * Purpose:
 *
 * Find the previous line in the current view that is not STATE_SAME
 */
BOOL
FindPrevChange(void)
{
        long row;

        /* start from the selection or top of window if no selection */
        if (selection >= 0) {
                row = selection;
        } else {
                row = (int) SendMessage(hwndRCD, TM_TOPROW, FALSE, 0);
        }

        /* find the previous 'interesting' line */
        row = view_findchange(current_view, row, FALSE);
        if (row >= 0) {
                SetSelection(row);
                return(TRUE);
        } else {
                windiff_UI(TRUE);
                MessageBox(hwndClient, LoadRcString(IDS_NO_PREV_CHANGES), "Windiff",
                        MB_ICONINFORMATION|MB_OK);
                windiff_UI(FALSE);

                return(FALSE);
        }

}
/***************************************************************************
 * Function: WriteProfileInt
 *
 */
 
BOOL WriteProfileInt(LPSTR AppName, LPSTR Key, int Int)
{       char Str[40];

        wsprintf((LPTSTR)Str, "%d", Int);
        return WriteProfileString(AppName, Key, Str);

} /* WriteProfileInt */


/***************************************************************************
 * Function: ToExpand
 *
 * Purpose:
 *
 * Switch to expand view of the selected line 
 */
BOOL
ToExpand(HWND hwnd)
{
        if (selection < 0) {
                return(FALSE);
        }

        if (!view_isexpanded(current_view)) {
                /* save the current outline size and position */
                WINDOWPLACEMENT wp;
                if (GetWindowPlacement(hwndClient,&wp)) {
                        WriteProfileInt(APPNAME, "OutlineShowCmd", wp.showCmd);
                        WriteProfileInt(APPNAME, "OutlineMaxX", wp.ptMaxPosition.x);
                        WriteProfileInt(APPNAME, "OutlineMaxY", wp.ptMaxPosition.y);
                        WriteProfileInt(APPNAME, "OutlineNormLeft", wp.rcNormalPosition.left);
                        WriteProfileInt(APPNAME, "OutlineNormTop", wp.rcNormalPosition.top);
                        WriteProfileInt(APPNAME, "OutlineNormRight", wp.rcNormalPosition.right);
                        WriteProfileInt(APPNAME, "OutlineNormBottom", wp.rcNormalPosition.bottom);
                        WriteProfileInt(APPNAME, "OutlineSaved", 1);
                }

                /* restore the previous expanded size and position, if any */
                if (GetProfileInt(APPNAME, "ExpandedSaved", 0)) {
                        wp.flags                   = 0;
                        wp.showCmd
                                = GetProfileInt( APPNAME, "ExpandShowCmd"
                                               , SW_SHOWMAXIMIZED);
                        wp.ptMaxPosition.x
                                = GetProfileInt( APPNAME, "ExpandMaxX", 0);
                        wp.ptMaxPosition.y
                                = GetProfileInt( APPNAME, "ExpandMaxY", 0);
                        wp.rcNormalPosition.left
                                = GetProfileInt( APPNAME, "ExpandNormLeft"
                                               , wp.rcNormalPosition.left);
                        wp.rcNormalPosition.top
                                = GetProfileInt( APPNAME, "ExpandNormTop"
                                               , wp.rcNormalPosition.top);
                        wp.rcNormalPosition.right
                                = GetProfileInt( APPNAME, "ExpandNormRight"
                                               , wp.rcNormalPosition.right);
                        wp.rcNormalPosition.bottom
                                = GetProfileInt( APPNAME, "ExpandNormBottom"
                                               , wp.rcNormalPosition.bottom);
                        SetWindowPlacement(hwndClient,&wp);
                }
                else ShowWindow(hwndClient, SW_SHOWMAXIMIZED);
        }

        /*change the view mapping to expand mode */
        if (view_expand(current_view, selection)) {

                /* ok - we now have an expanded view - change status
                 * to show this
                 */

                DisplayMode = MODE_EXPAND;

                /* resize to show the graphic bar picture */
                DoResize(hwndClient);


                /* change button,status text-if we are not still busy*/
                if (!fBusy) {
                        TCHAR szBuf[10];
                        lstrcpy(szBuf,LoadRcString(IDS_OUTLINE));
                        /* the status field when we are expanded shows the
                         * tag field (normally the file name) for the
                         * item we are expanding
                         */
                        SetStatus(view_getcurrenttag(current_view) );
                        SetButtonText(szBuf);
                }

                return(TRUE);
        }
        return(FALSE);
} /* ToExpand */

/***************************************************************************
 * Function: ToOutline
 *
 * Purpose:
 *
 * Switch back to outline view - showing just the list of file names.
 */
void
ToOutline(HWND hwnd)
{
        if (view_isexpanded(current_view)) {
                /* save the current expanded size and position */
                WINDOWPLACEMENT wp;
                if (GetWindowPlacement(hwndClient,&wp)) {
                        WriteProfileInt(APPNAME, "ExpandShowCmd", wp.showCmd);
                        WriteProfileInt(APPNAME, "ExpandMaxX", wp.ptMaxPosition.x);
                        WriteProfileInt(APPNAME, "ExpandMaxY", wp.ptMaxPosition.y);
                        WriteProfileInt(APPNAME, "ExpandNormLeft", wp.rcNormalPosition.left);
                        WriteProfileInt(APPNAME, "ExpandNormTop", wp.rcNormalPosition.top);
                        WriteProfileInt(APPNAME, "ExpandNormRight", wp.rcNormalPosition.right);
                        WriteProfileInt(APPNAME, "ExpandNormBottom", wp.rcNormalPosition.bottom);
                        WriteProfileInt(APPNAME, "ExpandedSaved", 1);
                }

                /* restore the previous expanded size and position, if any */
                if (GetProfileInt(APPNAME, "OutlineSaved", 0))  {
                        wp.flags = 0;
                        wp.showCmd
                                = GetProfileInt( APPNAME, "OutlineShowCmd"
                                               , SW_SHOWNORMAL);
                        wp.ptMaxPosition.x
                                = GetProfileInt( APPNAME, "OutlineMaxX", 0);
                        wp.ptMaxPosition.y
                                = GetProfileInt( APPNAME, "OutlineMaxY", 0);
                        wp.rcNormalPosition.left
                                = GetProfileInt( APPNAME, "OutlineNormLeft"
                                               , wp.rcNormalPosition.left);
                        wp.rcNormalPosition.top
                                = GetProfileInt( APPNAME, "OutlineNormTop"
                                               , wp.rcNormalPosition.top);
                        wp.rcNormalPosition.right
                                = GetProfileInt( APPNAME, "OutlineNormRight"
                                               , wp.rcNormalPosition.right);
                        wp.rcNormalPosition.bottom
                                = GetProfileInt( APPNAME, "OutlineNormBottom"
                                               , wp.rcNormalPosition.bottom);
                        SetWindowPlacement(hwndClient,&wp);
                }
                ShowWindow(hwndClient, SW_SHOWNORMAL);
        }

        DisplayMode = MODE_OUTLINE;

        /* switch mapping back to outline view */
        view_outline(current_view);

        /* hide bar window and resize to cover */
        DoResize(hwndClient);


        /* change label on button */
        if (!fBusy) {
                TCHAR szBuf[8];
                lstrcpy(szBuf,LoadRcString(IDS_EXPAND));
                SetButtonText(szBuf);
                SetStatus(NULL);
        }
} /* ToOutline */

/***************************************************************************
 * Function: ToMoved
 *
 * Purpose:
 *
 * If the user clicks on a MOVED line in expand mode, we jump to the
 * other line. We return TRUE if this was possible,  or FALSE otherwise.
 */
BOOL
ToMoved(HWND hwnd)
{
        BOOL bIsLeft;
        int linenr, state;
        long i, total;

        if (DisplayMode != MODE_EXPAND) {
                return(FALSE);
        }
        if (selection < 0) {
                return(FALSE);
        }

        state = view_getstate(current_view, selection);
        if (state == STATE_MOVEDLEFT) {
                bIsLeft = TRUE;
                /* get the linenr of the other copy */
                linenr = abs(view_getlinenr_right(current_view, selection));
        } else if (state == STATE_MOVEDRIGHT) {
                bIsLeft = FALSE;
                /* get the linenr of the other copy */
                linenr = abs(view_getlinenr_left(current_view, selection));
        } else {
                /* not a moved line - so we can't find another copy */
                return(FALSE);
        }

⌨️ 快捷键说明

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