lstool.c

来自「CC386 is a general-purpose 32-bit C comp」· C语言 代码 · 共 577 行 · 第 1/2 页

C
577
字号
    FormatToolBar(vert, ptr->u.tb.vWnd);
    return ptr->id;
}

//-------------------------------------------------------------------------

void SetToolBarData(HWND hwnd, char *horiz, char *vert)
{
    TBBUTTON buttons[60];
    CCW_params *ptr = (CCW_params*)GetWindowLong(hwnd, 0);
    RECT c;
    int i;
    GetClientRect(ptr->self, &c);
    MoveWindow(ptr->self, 0, 0, 1000, 1000, 0);

    i = ParseToolBar(horiz, ptr->u.tb.hWnd, ptr, buttons);
    ChangeButtons(i, ptr->u.tb.hWnd, buttons, ptr);
    i = ParseToolBar(vert, ptr->u.tb.vWnd, ptr, buttons);
    ChangeButtons(i, ptr->u.tb.vWnd, buttons, ptr);
    if (ptr->vertical)
        c.left += INDENT;
    else
        c.top += INDENT;
    MoveWindow(ptr->self, c.left, c.top, c.right - c.left, c.bottom - c.top, 1);
}

//-------------------------------------------------------------------------

static void ResizeContainer(CCW_params *ptr)
{
    CalculateLayout( - 1, 0);
}

//-------------------------------------------------------------------------

static LRESULT CALLBACK _export ControlWindWndProc(HWND hwnd, UINT iMessage,
    WPARAM wParam, LPARAM lParam)
{
    TBBUTTON buttons[60];
    TBNOTIFY *tb;
    RECT r,  *pr, r1;
    PAINTSTRUCT ps;
    HDC dc;
    CCW_params *ptr;
    static int skip;
    static int dragging, oncursor, sizing;
    static HCURSOR oldCursor;
    POINT temppt;
    int temp;
    int i;
    HBRUSH brush;
    LPTOOLTIPTEXT lpt;
    LPMINMAXINFO minmax;
    SIZE size;
    char name[64], buf[512],  *p;
    switch (iMessage)
    {
        case WM_NOTIFY:
            ptr = (CCW_params*)GetWindowLong(hwnd, 0);
            switch (((LPNMHDR)lParam)->code)
            {
            case TBN_BEGINADJUST:
                break;
            case TBN_QUERYINSERT:
                return TRUE;
            case TBN_QUERYDELETE:
                return TRUE;
            case TBN_GETBUTTONINFO:
                ptr = (CCW_params*)GetWindowLong(hwnd, 0);
                tb = (TBNOTIFY*)lParam;
                if (tb->iItem >= ptr->u.tb.btncount)
                    return FALSE;
                tb->tbButton = ptr->u.tb.buttons[tb->iItem];
                p = GetTipText(ptr, tb->tbButton.idCommand);
                tb->cchText = strlen(p);
                strcpy(tb->pszText, p);
                //                  tb->cchText = 0 ;
                return TRUE;
            case TBN_RESET:
                ptr = (CCW_params*)GetWindowLong(hwnd, 0);
                ChangeButtons(ptr->u.tb.btncount, ptr->u.tb.hWnd, ptr
                    ->u.tb.buttons, ptr);
                ChangeButtons(ptr->u.tb.btncount, ptr->u.tb.vWnd, ptr
                    ->u.tb.buttons, ptr);
                ResizeContainer(ptr);
                return TRUE;
            case TBN_CUSTHELP:
                ptr = (CCW_params*)GetWindowLong(hwnd, 0);
                if (ptr->u.tb.helpitem)
                    ContextHelp(ptr->u.tb.helpitem);
                break;
            case TBN_ENDADJUST:
                ptr = (CCW_params*)GetWindowLong(hwnd, 0);
                CopyButtons(ptr);
                ResizeContainer(ptr);
                PostMessage(hwndFrame, WM_REDRAWTOOLBAR, 0, 0);
                break;
            case TBN_TOOLBARCHANGE:
                SetRectSize(ptr->u.tb.hWnd, ptr);
                SetRectSize(ptr->u.tb.vWnd, ptr);
                ResizeContainer(ptr);
                break;
            case TTN_NEEDTEXT:
                ptr = (CCW_params*)GetWindowLong(hwnd, 0);
                lpt = (LPTOOLTIPTEXT)lParam;
                p = GetTipText(ptr, lpt->hdr.idFrom);
                if (p)
                    lpt->lpszText = p;
                break;
            default:
                return SendMessage(ptr->u.tb.notifyparent, iMessage, wParam,
                    lParam);
            }
            break;
        case WM_PAINT:
            dc = BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
            break;
        case WM_COMMAND:
            ptr = (CCW_params*)GetWindowLong(hwnd, 0);
            return SendMessage(ptr->u.tb.notifyparent, iMessage, wParam, lParam)
                ;
        case WM_CREATE:
            ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof
                (CCW_params));
            SetWindowLong(hwnd, 0, (DWORD)ptr);
            *ptr = *(CCW_params*)(((LPCREATESTRUCT)lParam)->lpCreateParams);
            ptr->self = hwnd;
            ptr->type = LSTOOLBAR;
            //         return 0 ;
            ptr->u.tb.btncount = 0;
            while (ptr->u.tb.buttons[ptr->u.tb.btncount].fsStyle || ptr
                ->u.tb.buttons[ptr->u.tb.btncount].idCommand)
                ptr->u.tb.btncount++;
            ptr->u.tb.hWnd = CreateToolbarEx(hwnd, WS_CHILD | (ptr->u.tb.hints 
                ? TBSTYLE_TOOLTIPS : 0) | CCS_NODIVIDER | CCS_ADJUSTABLE |
                TBSTYLE_WRAPABLE, ptr->u.tb.bmpid, ptr->u.tb.bmpcount, 
                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), ptr->u.tb.bmpid,
                ptr->u.tb.buttons, ptr->u.tb.btncount, ptr->u.tb.width, ptr
                ->u.tb.height, ptr->u.tb.width, ptr->u.tb.height, sizeof
                (TBBUTTON));
            SendMessage(ptr->u.tb.hWnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON),
                0);
            SendMessage(ptr->u.tb.hWnd, TB_GETITEMRECT, i - 1, (LPARAM) &r);
            ptr->u.tb.hsize.cx = r.right + GetSystemMetrics(SM_CXFRAME) *2;
            ptr->u.tb.hsize.cy = r.bottom + GetSystemMetrics(SM_CYFRAME) *2;
            MoveWindow(hwnd, 0, INDENT, ptr->u.tb.hsize.cy, ptr->u.tb.hsize.cx,
                1);
            sprintf(name, "TBH%d", ptr->id);
            p = ProfileToString(name, "");
            i = ParseToolBar(p, ptr->u.tb.hWnd, ptr, buttons);
            if (i)
                ChangeButtons(i, ptr->u.tb.hWnd, buttons, ptr);
            else
                ChangeButtons(ptr->u.tb.btncount, ptr->u.tb.hWnd, ptr
                    ->u.tb.buttons, ptr);
            ptr->u.tb.vWnd = CreateToolbarEx(hwnd, WS_CHILD | (ptr->u.tb.hints 
                ? TBSTYLE_TOOLTIPS : 0) | CCS_NODIVIDER | CCS_ADJUSTABLE |
                TBSTYLE_WRAPABLE, ptr->u.tb.bmpid, ptr->u.tb.bmpcount, 
                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), ptr->u.tb.bmpid,
                ptr->u.tb.buttons, ptr->u.tb.btncount, ptr->u.tb.width, ptr
                ->u.tb.height, ptr->u.tb.width, ptr->u.tb.height, sizeof
                (TBBUTTON));

            SendMessage(ptr->u.tb.vWnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON),
                0);
            SendMessage(ptr->u.tb.vWnd, TB_SETROWS, MAKEWPARAM(i, FALSE), 
                (LPARAM) &r);
            SendMessage(hwnd, TB_GETITEMRECT, i - 1, (LPARAM) &r);
            ptr->u.tb.vsize.cx = r.right + GetSystemMetrics(SM_CXFRAME) *2;
            ptr->u.tb.vsize.cy = r.bottom + GetSystemMetrics(SM_CYFRAME) *2;
            MoveWindow(hwnd, INDENT, 0, ptr->u.tb.hsize.cx, ptr->u.tb.hsize.cy,
                1);
            sprintf(name, "TBV%d", ptr->id);
            p = ProfileToString(name, "");
            i = ParseToolBar(p, ptr->u.tb.vWnd, ptr, buttons);
            if (i)
                ChangeButtons(i, ptr->u.tb.vWnd, buttons, ptr);
            else
                ChangeButtons(ptr->u.tb.btncount, ptr->u.tb.vWnd, ptr
                    ->u.tb.buttons, ptr);
            SendMessage(hwnd, LCF_SETVERTICAL, 0, ptr->vertical);
            dmgrAddClient(ptr);
            return 0;
        case WM_DESTROY:
            ptr = (CCW_params*)GetWindowLong(hwnd, 0);
            FormatToolBar(buf, ptr->u.tb.hWnd);
            sprintf(name, "TBH%d", ptr->id);
            StringToProfile(name, buf);
            FormatToolBar(buf, ptr->u.tb.vWnd);
            sprintf(name, "TBV%d", ptr->id);
            StringToProfile(name, buf);
            dmgrRemoveClient(ptr);
            HeapFree(GetProcessHeap(), 0, ptr);
            break;
        case LCF_SETVERTICAL:
            ptr = (CCW_params*)GetWindowLong(hwnd, 0);
            ptr->vertical = (int)lParam;
            if (ptr->vertical)
            {
                ShowWindow(ptr->u.tb.hWnd, SW_HIDE);
                ShowWindow(ptr->u.tb.vWnd, SW_SHOW);
                MoveWindow(hwnd, INDENT, (int)wParam, ptr->u.tb.vsize.cx, ptr
                    ->u.tb.vsize.cy, 1);
            }
            else
            {
                ShowWindow(ptr->u.tb.vWnd, SW_HIDE);
                ShowWindow(ptr->u.tb.hWnd, SW_SHOW);
                MoveWindow(hwnd, (int)wParam, INDENT, ptr->u.tb.hsize.cx, ptr
                    ->u.tb.hsize.cy, 1);
            }
            return 0;
        case WM_CLOSE:
            ptr = (CCW_params*)GetWindowLong(hwnd, 0);
            dmgrHideWindow(ptr->id, TRUE);
            return 0;
        case WM_SIZE:
            ptr = (CCW_params*)GetWindowLong(hwnd, 0);
            if (ptr->vertical)
            {
                MoveWindow(ptr->u.tb.vWnd, INDENT, 0, LOWORD(lParam), HIWORD
                    (lParam), TRUE);
            }
            else
            {
                MoveWindow(ptr->u.tb.hWnd, 0, INDENT, LOWORD(lParam), HIWORD
                    (lParam), TRUE);
            }
            return 0;
        default:
            if (iMessage >= WM_USER && iMessage <= WM_USER + 100)
            {
                ptr = (CCW_params*)GetWindowLong(hwnd, 0);
                return SendMessage(ptr->u.tb.hWnd, iMessage, wParam, lParam);
            }
    }
    return DefWindowProc(hwnd, iMessage, wParam, lParam);
}

//-------------------------------------------------------------------------

void RegisterToolBarWindow(HINSTANCE hInstance)
{
    WNDCLASS wc;
    memset(&wc, 0, sizeof(wc));
    wc.style = 0;
    wc.lpfnWndProc = &ControlWindWndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = sizeof(LPVOID);
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(0, IDI_APPLICATION);
    wc.hCursor = LoadCursor(0, IDC_ARROW);
    wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_INACTIVEBORDER));
    wc.lpszMenuName = 0;
    wc.lpszClassName = szToolBarWindClassName;
    RegisterClass(&wc);

}

//-------------------------------------------------------------------------

HWND CreateToolBarWindow(int id, HWND notify, HWND parent, int width, int
    height, int bmp, int bmpcount, TBBUTTON *buttons, char **hints, int
    vertical, char *title, int helpitem)
{
    CCW_params p;
    HWND hwnd;
    RECT r1, r2;
    memset(&p, 0, sizeof(p));
    p.vertical = vertical;
    p.u.tb.width = width;
    p.u.tb.height = height;
    p.u.tb.buttons = buttons;
    p.u.tb.hints = hints;
    p.u.tb.bmpid = bmp;
    p.u.tb.bmpcount = bmpcount;
    p.u.tb.notifyparent = notify;
    p.u.tb.helpitem = helpitem;
    p.title = title;
    p.id = id;
    hwnd = CreateWindow(szToolBarWindClassName, "", WS_CLIPSIBLINGS | WS_CHILD 
        | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 1000, 30, parent, (HMENU)0,
        (HINSTANCE)GetWindowLong(parent, GWL_HINSTANCE), &p);

    return hwnd;
}

⌨️ 快捷键说明

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