📄 newtoolbar.c
字号:
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 = 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;
InvalidateRect (hwnd, &item->rc_item, TRUE);
}
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 = 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 NTBM_SETBITMAP:
{
NTBINFO *ntb_newdata = NULL;
ntb_newdata = (NTBINFO *) lParam;
if (!ntb_newdata)
return NTB_ERR;
ntb_data->image = ntb_newdata->image;
ntb_data->nr_cells =ntb_newdata->nr_cells;
ntb_data->nr_cols = ntb_newdata->nr_cols;
if (ntb_newdata->nr_cols == 0)
ntb_data->nr_cols = 4;
ntb_data->w_cell = ntb_newdata->w_cell;
if (ntb_data->w_cell == 0)
ntb_data->w_cell = ntb_newdata->image->bmWidth / ntb_data->nr_cols;
ntb_data->h_cell = ntb_newdata->h_cell;
if (ntb_newdata->h_cell == 0)
ntb_data->h_cell = ntb_newdata->image->bmHeight / ntb_data->nr_cells;
InvalidateRect(hwnd, NULL, FALSE);
return NTB_OKAY;
}
case MSG_PAINT:
{
HDC hdc = BeginPaint (hwnd);
if ( ! (ntb_data->style & NTBS_VERTICAL))
{
draw_tool_bar_horz (hwnd, hdc, ntb_data);
}
else
{
draw_tool_bar_vert (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_LBUTTONDBLCLK:
{
int sx, sy, x, y;
PNTBITEM item;
sx = x = LOSWORD(lParam);
sy = y = HISWORD(lParam);
if ( (item = get_item_by_pos (ntb_data, x, y)) ) {
NotifyParent (hwnd, myself->id, item->id | 0x4000 );
}
}
break;
case MSG_LBUTTONDOWN:
{
int posx, posy;
NTBITEM* item;
posx = LOSWORD (lParam);
posy = HISWORD (lParam);
if ((item = get_item_by_pos (ntb_data, posx, posy)) == NULL)
break;
if (GetCapture () == hwnd)
break;
SetCapture (hwnd);
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;
}
}
if ( ( item->flags&NTBIF_TYPEMASK ) == NTBIF_CHECKBUTTON ) {
if ( item->flags & NTBIF_CHECKED )
item->flags &= ~NTBIF_CHECKED;
else
item->flags |= NTBIF_CHECKED;
}
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;
}
case MSG_RBUTTONDOWN:
{
int posx, posy;
NTBITEM* item;
posx = LOSWORD (lParam);
posy = HISWORD (lParam);
if ((item = get_item_by_pos (ntb_data, posx, posy)) == NULL)
break;
if (GetCapture () == hwnd)
break;
SetCapture (hwnd);
ntb_data->sel_item = item;
ntb_data->btn_down = TRUE;
InvalidateRect (hwnd, &item->rc_item, TRUE);
}
break;
case MSG_RBUTTONUP:
{
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 | 0x8000);
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 + -