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

📄 newtoolbar.c

📁 MINI GUI1.6X源码
💻 C
字号:
/*** $Id: newtoolbar.c,v 1.8 2005/06/14 08:04:46 limei Exp $**** newtoolbar.c: The NewToolBar control demo program.**** Copyright (C) 2003 Feynman Software.**** Create date: 2003/5/15*//***  This source is free software; you can redistribute it and/or**  modify it under the terms of the GNU General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This software is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU**  General Public License for more details.****  You should have received a copy of the GNU General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/stat.h>#include <sys/types.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#define LEN_TEXT    50#define LEN_TIP     50#define IDC_CTRL_BUTTON       100#define IDC_CTRL_NEWTOOLBAR_1 110#define IDC_CTRL_NEWTOOLBAR_2 120#define IDC_CTRL_NEWTOOLBAR_3 130#define IDC_CTRL_NEWTOOLBAR_4 140#define IDC_NTB_ONE           140#define IDC_NTB_TWO           150#define IDC_NTB_THREE         160#define IDC_NTB_FOUR          170static HWND hMainWnd = HWND_INVALID;static void my_hotspot_proc (HWND hwnd, int id, const RECT* cell, int x, int y){        HDC hdc;        char buff [254];        Ping ();        hdc = GetClientDC (GetParent (hwnd));        sprintf (buff, "Hotpot of button %d of NewToolBar %d clicked.", id, GetDlgCtrlID (hwnd));        TextOut (hdc, 0, 330, buff);        ReleaseDC (hdc);}BITMAP bitmap1, bitmap2, bitmap3, bitmap4;static void create_newtoolbars (HWND hWnd){    HWND ntb1, ntb2, ntb3, ntb4;    NTBINFO ntb_info;    NTBITEMINFO ntbii;    gal_pixel pixel;    RECT hotspot = {16, 16, 32, 32};    ntb_info.nr_cells = 4;    ntb_info.w_cell  = 0;    ntb_info.h_cell  = 0;    ntb_info.nr_cols = 0;    ntb_info.image = &bitmap1;    ntb1 = CreateWindow (CTRL_NEWTOOLBAR,                    "",                    WS_CHILD | WS_VISIBLE,                     IDC_CTRL_NEWTOOLBAR_1,                    0, 10, 1024, 0,                    hWnd,                    (DWORD) &ntb_info);    pixel = GetPixelInBitmap (&bitmap1, 0, 0);    SetWindowBkColor (ntb1, pixel);    InvalidateRect (ntb1, NULL, TRUE);    ntb_info.nr_cells = 4;    ntb_info.w_cell  = 0;    ntb_info.h_cell  = 0;    ntb_info.nr_cols = 0;    ntb_info.image = &bitmap2;    ntb2 = CreateWindow (CTRL_NEWTOOLBAR,                    "",                    WS_CHILD | WS_VISIBLE | NTBS_WITHTEXT,                    IDC_CTRL_NEWTOOLBAR_2,                    0, 90, 1024, 0,                    hWnd,(DWORD) &ntb_info);    pixel = GetPixelInBitmap (&bitmap2, 0, 0);    SetWindowBkColor (ntb2, pixel);    InvalidateRect (ntb2, NULL, TRUE);    ntb_info.nr_cells = 4;    ntb_info.w_cell  = 0;    ntb_info.h_cell  = 0;    ntb_info.nr_cols = 0;    ntb_info.image = &bitmap3;    ntb3 = CreateWindow (CTRL_NEWTOOLBAR, "",                    WS_CHILD | WS_VISIBLE                    | NTBS_WITHTEXT | NTBS_TEXTRIGHT | NTBS_DRAWSEPARATOR,                    IDC_CTRL_NEWTOOLBAR_3,                    0, 170, 1024, 0,                    hWnd,(DWORD) &ntb_info);    pixel = GetPixelInBitmap (&bitmap3, 0, 0);    SetWindowBkColor (ntb3, pixel);    InvalidateRect (ntb3, NULL, TRUE);    ntb_info.nr_cells = 4;    ntb_info.w_cell  = 0;    ntb_info.h_cell  = 0;    ntb_info.nr_cols = 0;    ntb_info.image = &bitmap4;    ntb4 = CreateWindow (CTRL_NEWTOOLBAR, "",                    WS_CHILD | WS_VISIBLE | NTBS_WITHTEXT | NTBS_TEXTRIGHT | NTBS_DRAWSTATES,                    IDC_CTRL_NEWTOOLBAR_4,                    0, 250, 1024, 0,                    hWnd,(DWORD) &ntb_info);    pixel = GetPixelInBitmap (&bitmap4, 0, 0);    SetWindowBkColor (ntb4, pixel);    InvalidateRect (ntb4, NULL, TRUE);    memset (&ntbii, 0, sizeof (ntbii));    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NTB_ONE;    ntbii.bmp_cell = 0;    SendMessage (ntb1, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NTB_TWO;    ntbii.bmp_cell = 1;    SendMessage(ntb1, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON | NTBIF_DISABLED;    ntbii.id = IDC_NTB_THREE;    ntbii.bmp_cell = 2;    SendMessage (ntb1, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_SEPARATOR;    ntbii.id = 0;    ntbii.bmp_cell = 0;    ntbii.text = NULL;    SendMessage (ntb1, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_HOTSPOTBUTTON;    ntbii.id = IDC_NTB_FOUR;    ntbii.bmp_cell = 3;    ntbii.rc_hotspot = hotspot;    ntbii.hotspot_proc = my_hotspot_proc;    SendMessage (ntb1, TBM_ADDITEM, 0, (LPARAM)&ntbii);    memset (&ntbii, 0, sizeof (ntbii));    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NTB_ONE;    ntbii.bmp_cell = 0;    ntbii.text = "Up";    SendMessage (ntb2, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NTB_TWO;    ntbii.bmp_cell = 1;    ntbii.text = "Prev";    SendMessage (ntb2, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON | NTBIF_DISABLED;    ntbii.id = IDC_NTB_THREE;    ntbii.bmp_cell = 2;    ntbii.text = "Next";    SendMessage (ntb2, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_SEPARATOR;    ntbii.id = 0;    ntbii.bmp_cell = 0;    ntbii.text = NULL;    SendMessage (ntb2, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_HOTSPOTBUTTON;    ntbii.id = IDC_NTB_FOUR;    ntbii.bmp_cell = 3;    ntbii.rc_hotspot = hotspot;    ntbii.hotspot_proc = my_hotspot_proc;    ntbii.text = "Menu";    SendMessage (ntb2, TBM_ADDITEM, 0, (LPARAM)&ntbii);    memset (&ntbii, 0, sizeof (ntbii));    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NTB_ONE;    ntbii.bmp_cell = 0;    ntbii.text = "Up";    SendMessage (ntb3, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NTB_TWO;    ntbii.bmp_cell = 1;    ntbii.text = "Previous";    SendMessage (ntb3, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NTB_THREE;    ntbii.bmp_cell = 2;    ntbii.text = "Next";    SendMessage (ntb3, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_SEPARATOR;    ntbii.id = 0;    ntbii.bmp_cell = 0;    ntbii.text = NULL;    SendMessage (ntb3, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_HOTSPOTBUTTON | NTBIF_DISABLED;    ntbii.id = IDC_NTB_FOUR;    ntbii.bmp_cell = 3;    ntbii.rc_hotspot = hotspot;    ntbii.hotspot_proc = my_hotspot_proc;    ntbii.text = "Menu";    SendMessage (ntb3, TBM_ADDITEM, 0, (LPARAM)&ntbii);    memset (&ntbii, 0, sizeof (ntbii));    ntbii.flags = NTBIF_PUSHBUTTON | NTBIF_DISABLED;    ntbii.id = IDC_NTB_ONE;    ntbii.bmp_cell = 0;    ntbii.text = "Up";    SendMessage (ntb4, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NTB_TWO;    ntbii.bmp_cell = 1;    ntbii.text = "Prev";    SendMessage (ntb4, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NTB_THREE;    ntbii.bmp_cell = 2;    ntbii.text = "Next";    SendMessage (ntb4, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_SEPARATOR;    ntbii.id = 0;    ntbii.bmp_cell = 0;    ntbii.text = NULL;    SendMessage (ntb4, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_HOTSPOTBUTTON;    ntbii.id = IDC_NTB_FOUR;    ntbii.bmp_cell = 3;    ntbii.rc_hotspot = hotspot;    ntbii.hotspot_proc = my_hotspot_proc;    ntbii.text = "Menu";    SendMessage (ntb4, TBM_ADDITEM, 0, (LPARAM)&ntbii);}static int ControlTestWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    switch (message) {    case MSG_CREATE:        if (LoadBitmap (HDC_SCREEN, &bitmap1, "res/new1.jpg"))            return -1;        if (LoadBitmap (HDC_SCREEN, &bitmap2, "res/new4.jpg"))            return -1;        if (LoadBitmap (HDC_SCREEN, &bitmap3, "res/new3.jpg"))            return -1;        if (LoadBitmap (HDC_SCREEN, &bitmap4, "res/new2.jpg"))            return -1;        CreateWindow (CTRL_BUTTON, "Close",                        WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, IDC_CTRL_BUTTON,                         400, 320, 60, 25, hWnd,0);        create_newtoolbars (hWnd);        break;    case MSG_COMMAND:    {        int id = LOWORD(wParam);        int code = HIWORD(wParam);        HDC hdc;        char buff [254];        if (wParam == IDC_CTRL_BUTTON) {            PostMessage (hWnd, MSG_CLOSE, 0, 0);            break;        }        hdc = GetClientDC (hWnd);        sprintf (buff, "Button %d of NewToolBar %d clicked.", code, id);        TextOut (hdc, 0, 330, buff);        ReleaseDC (hdc);        break;    }    case MSG_DESTROY:        UnloadBitmap (&bitmap1);        UnloadBitmap (&bitmap2);        UnloadBitmap (&bitmap3);        UnloadBitmap (&bitmap4);        DestroyAllControls (hWnd);        hMainWnd = HWND_INVALID;	return 0;    case MSG_CLOSE:        DestroyMainWindow (hWnd);        MainWindowCleanup (hWnd);        return 0;    }    return DefaultMainWinProc (hWnd, message, wParam, lParam);}static void InitCreateInfo (PMAINWINCREATE pCreateInfo){    pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE;    pCreateInfo->dwExStyle = WS_EX_NONE;    pCreateInfo->spCaption = "NewToolBar controls";    pCreateInfo->hMenu = 0;    pCreateInfo->hCursor = GetSystemCursor(1);    pCreateInfo->hIcon = 0;    pCreateInfo->MainWindowProc = ControlTestWinProc;    pCreateInfo->lx = 0;    pCreateInfo->ty = 0;    pCreateInfo->rx = 480;    pCreateInfo->by = 380;    pCreateInfo->iBkColor = PIXEL_lightgray;    pCreateInfo->dwAddData = 0;    pCreateInfo->hHosting = HWND_DESKTOP;}void newtoolbar_demo (HWND hwnd){    MAINWINCREATE CreateInfo;    if (hMainWnd != HWND_INVALID) {        ShowWindow (hMainWnd, SW_SHOWNORMAL);        return;    }    InitCreateInfo (&CreateInfo);    CreateInfo.hHosting = hwnd;    hMainWnd = CreateMainWindow (&CreateInfo);}

⌨️ 快捷键说明

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