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

📄 newtoolbar.c

📁 libminigui-1.3.0.tar.gz。 miniGUI的库函数源代码!
💻 C
📖 第 1 页 / 共 2 页
字号:
                item->rc_text.left = item->rc_item.left;                item->rc_text.right = item->rc_item.right;                item->rc_text.top                         = item->rc_item.top + ntb_data->h_cell + GAP_BMP_TEXT_VERT;                item->rc_text.bottom = item->rc_text.top + GetFontHeight (hdc);                item->rc_item.bottom = item->rc_text.bottom + 1;            }        }        else {            item->rc_item.right = item->rc_item.left + ntb_data->w_cell + 1;            item->rc_item.bottom = item->rc_item.top + ntb_data->h_cell + 1;        }        break;                            case NTBIF_SEPARATOR:        default:            if (ntb_data->style & NTBS_DRAWSEPARATOR)                item->rc_item.right = item->rc_item.left + WIDTH_SEPARATOR;            else                item->rc_item.right = item->rc_item.left + WIDTH_SEPARATOR * 2;            item->rc_item.bottom = item->rc_item.top + ntb_data->h_cell;            break;        }        prev = item;        item = item->next;    }    ReleaseDC (hdc);}/*===========================================================================*/static int NewToolbarCtrlProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam){    PCONTROL myself;    PNTBCTRLDATA ntb_data;    myself   = Control (hwnd);    ntb_data = (PNTBCTRLDATA) myself->dwAddData2;    switch (message) {        case MSG_CREATE:        {            NTBINFO* data = (NTBINFO*)myself->dwAddData;            ntb_data = (NTBCTRLDATA*) calloc (1, sizeof (NTBCTRLDATA));            if (ntb_data == NULL)                        return -1;            ntb_data->head = NULL;            ntb_data->style = myself->dwStyle;            ntb_data->image = data->image;            ntb_data->nr_cells = data->nr_cells;            ntb_data->nr_cols = data->nr_cols;            if (data->nr_cols == 0)                ntb_data->nr_cols = 4;            ntb_data->w_cell = data->w_cell;            if (data->w_cell == 0)                ntb_data->w_cell = data->image->bmWidth / ntb_data->nr_cols;            ntb_data->h_cell = data->h_cell;            if (data->h_cell == 0)                ntb_data->h_cell = data->image->bmHeight / ntb_data->nr_cells;            ntb_data->nr_items = 0;            ntb_data->sel_item = NULL;            myself->dwAddData2 = (DWORD)ntb_data;            break;        }        case MSG_DESTROY:        {            NTBITEM *item, *tmp;            item = ntb_data->head;            while (item) {                tmp = item->next;                free (item);                item = tmp;             }            free (ntb_data);            break;        }        case MSG_FONTCHANGED:        {            RECT rc;            recalc_items (hwnd, ntb_data);            GetWindowRect (hwnd, &rc);            MoveWindow (hwnd, rc.left, rc.top, RECTW(rc), RECTH(rc), TRUE);            break;        }        case MSG_NCPAINT:            return 0;        case MSG_SIZECHANGING:        {            const RECT* rcExpect = (const RECT*)wParam;            RECT* rcResult = (RECT*)lParam;            rcResult->left = rcExpect->left;            rcResult->top = rcExpect->top;            rcResult->right = rcExpect->right;            if (ntb_data->style & NTBS_WITHTEXT) {                rcResult->bottom = rcExpect->top + ntb_data->h_cell + MARGIN_VERT * 2;                if (!(ntb_data->style & NTBS_TEXTRIGHT))                    rcResult->bottom += GetWindowFont (hwnd)->size + GAP_BMP_TEXT_VERT;            }            else                rcResult->bottom = rcExpect->top + ntb_data->h_cell + MARGIN_VERT * 2;            return 0;        }        case NTBM_ADDITEM:        {            NTBITEMINFO* item_info = NULL;            NTBITEM* new_item;            item_info = (NTBITEMINFO*) lParam;            if (!(new_item = (NTBITEM*)calloc (1, sizeof (NTBITEM))))                return NTB_ERR;            new_item->flags = item_info->flags;            new_item->id = item_info->id;            new_item->bmp_cell = item_info->bmp_cell;            if (item_info->text)                strncpy (new_item->text, item_info->text, NTB_TEXT_LEN);            else                new_item->text [0] = '\0';            if (item_info->tip)                strncpy (new_item->tip, item_info->tip, NTB_TIP_LEN);            else                new_item->tip [0] = '\0';            new_item->rc_hotspot = item_info->rc_hotspot;            new_item->hotspot_proc = item_info->hotspot_proc;            new_item->add_data = item_info->add_data;            append_new_item (hwnd, ntb_data, new_item);            InvalidateRect (hwnd, &new_item->rc_item, TRUE);            return 0;        }        break;        case NTBM_GETITEM:        {            int id = HIWORD (wParam);            PNTBITEMINFO item_info = (PNTBITEMINFO) lParam;            NTBITEM* item = NULL;            if (!item_info)                return NTB_ERR;            item = ntb_data->head;            while (item) {                if (id == item->id) {                    if (item_info->which & MTB_WHICH_FLAGS)                        item_info->flags = item->flags;                    if (item_info->which & MTB_WHICH_ID)                        item_info->id = item->id;                    if (item_info->which & MTB_WHICH_CELL)                        item_info->bmp_cell = item->bmp_cell;                    if (item_info->which & MTB_WHICH_HOTSPOT) {                        item_info->hotspot_proc = item->hotspot_proc;                        item_info->rc_hotspot = item->rc_hotspot;                    }                    if (item_info->which & MTB_WHICH_ADDDATA)                        item_info->add_data = item->add_data;                    if (item_info->which & MTB_WHICH_TEXT)                        strncpy (item_info->text, item->text, NTB_TEXT_LEN);                    if (item_info->which & MTB_WHICH_TIP)                        strncpy (item_info->tip, item->tip, NTB_TIP_LEN);                    return NTB_OKAY;                }                item = item->next;            }            return NTB_ERR;        }        case NTBM_SETITEM:        {            int id = HIWORD (wParam);            PNTBITEMINFO item_info = (PNTBITEMINFO) lParam;            NTBITEM* item = NULL;            if (!item_info)                return NTB_ERR;            item = ntb_data->head;            while (item) {                if (id == item->id) {                    if (item_info->which & MTB_WHICH_FLAGS)                        item->flags = item_info->flags;                    if (item_info->which & MTB_WHICH_ID)                        item->id = item_info->id;                    if (item_info->which & MTB_WHICH_CELL) {                        item->bmp_cell = item_info->bmp_cell;                        InvalidateRect (hwnd, &item->rc_item, TRUE);                    }                    if (item_info->which & MTB_WHICH_HOTSPOT) {                        item->hotspot_proc = item_info->hotspot_proc;                        item->rc_hotspot = item_info->rc_hotspot;                    }                    if (item_info->which & MTB_WHICH_ADDDATA)                        item->add_data = item_info->add_data;                    if (item_info->which & MTB_WHICH_TEXT) {                        strncpy (item->text, item_info->text, NTB_TEXT_LEN);                        if (ntb_data->style & NTBS_WITHTEXT) {                            if (ntb_data->style & NTBS_TEXTRIGHT) {                                recalc_items (hwnd, ntb_data);                                InvalidateRect (hwnd, NULL, TRUE);                            }                            else {                                InvalidateRect (hwnd, &item->rc_text, TRUE);                            }                        }                    }                    if (item_info->which & MTB_WHICH_TIP)                        strncpy (item->tip, item_info->tip, NTB_TIP_LEN);                    return NTB_OKAY;                }                item = item->next;            }            return NTB_ERR;        }        case NTBM_ENABLEITEM:        {            int id = HIWORD(wParam);            BOOL enable = lParam;            PNTBITEM item = NULL;            item = ntb_data->head;            while (item) {                if (id == item->id) {                    if (enable && (item->flags & NTBIF_DISABLED)) {                        item->flags &= ~NTBIF_DISABLED;                        InvalidateRect (hwnd, &item->rc_item, TRUE);                    }                    else if (!enable && !(item->flags & NTBIF_DISABLED)) {                        item->flags |= NTBIF_DISABLED;                        InvalidateRect (hwnd, &item->rc_item, TRUE);                    }                    return NTB_OKAY;                }                item = item->next;            }            return NTB_ERR;        }        case MSG_PAINT:        {            HDC hdc = BeginPaint (hwnd);            draw_tool_bar (hwnd, hdc, ntb_data);            EndPaint (hwnd, hdc);            return 0;        }        case MSG_MOUSEMOVEIN:        {            if (!wParam && ntb_data->sel_item) {                InvalidateRect (hwnd, &ntb_data->sel_item->rc_item, TRUE);                ntb_data->sel_item = NULL;            }            break;        }        case MSG_MOUSEMOVE:        {            PNTBITEM item;            int x, y;            x = LOSWORD(lParam);            y = HISWORD(lParam);            if (GetCapture () == hwnd)                break;            if ((item = get_item_by_pos (ntb_data, x, y))) {                if (ntb_data->sel_item != item) {                    if (ntb_data->sel_item)                        InvalidateRect (hwnd, &ntb_data->sel_item->rc_item, TRUE);                    ntb_data->sel_item = item;                    InvalidateRect (hwnd, &ntb_data->sel_item->rc_item, TRUE);                }                break;            }            break;        }        case MSG_LBUTTONDOWN:        {            int posx, posy;            NTBITEM* item;            posx = LOSWORD (lParam);            posy = HISWORD (lParam);            if (GetCapture () == hwnd)                break;            SetCapture (hwnd);            if ((item = get_item_by_pos (ntb_data, posx, posy)) == NULL)                break;            ntb_data->sel_item = item;            ntb_data->btn_down = TRUE;            InvalidateRect (hwnd, &item->rc_item, TRUE);        }        break;        case MSG_LBUTTONUP:        {            int sx, sy, x, y;            PNTBITEM item;            sx = x = LOSWORD(lParam);            sy = y = HISWORD(lParam);            ntb_data->btn_down = FALSE;            if (GetCapture() != hwnd)                break;            ReleaseCapture ();            ScreenToClient (hwnd, &x, &y);            if ((item = get_item_by_pos (ntb_data, x, y))                             && item == ntb_data->sel_item) {                if ((item->flags & NTBIF_TYPEMASK) == NTBIF_HOTSPOTBUTTON                                 && item->hotspot_proc) {                    RECT rc_hotspot = item->rc_hotspot;                    OffsetRect (&rc_hotspot, item->rc_item.left, item->rc_item.top);                    if (PtInRect (&rc_hotspot, x, y)) {                        RECT rc_item = item->rc_item;                                                    ClientToScreen (hwnd, &rc_item.left, &rc_item.top);                        ClientToScreen (hwnd, &rc_item.right, &rc_item.bottom);                        item->hotspot_proc (hwnd, item->id, &rc_item, sx, sy);                        InvalidateRect (hwnd, &item->rc_item, TRUE);                        break;                    }                }                NotifyParent (hwnd, myself->id, item->id);                InvalidateRect (hwnd, &item->rc_item, TRUE);            }            else if (ntb_data->sel_item) {                InvalidateRect (hwnd, &ntb_data->sel_item->rc_item, TRUE);                ntb_data->sel_item = NULL;            }            break;        }        default:            break;    }    return DefaultControlProc (hwnd, message, wParam, lParam);}#endif /* _CTRL_NEWTOOLBAR */

⌨️ 快捷键说明

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