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

📄 listview.c

📁 MINI GUI1.6X源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*** $Id: listview.c,v 1.28 2005/09/04 06:54:05 qzlong Exp $**** listview.c: The ListView control demo program.**** Copyright (C) 2001 ~ 2002 Wei Yongming.** Copyright (C) 2003 Feynman Software.**** Create date: 2001/11/01*//***  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 <sys/stat.h>#include <sys/types.h>#include <time.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include <minigui/mgext.h>#define IDC_LISTVIEW    10#define IDC_CTRL1       20#define IDC_CTRL2       30#define IDC_CTRL3       40#define IDC_CTRL4       50#define IDC_EDIT        60#define IDC_CTRL6       70#define IDC_CTRL7       80#define IDC_CTRL8       90#define IDC_CTRL9       100#define IDC_CTRL10      110#define IDC_CTRL11      120#define IDC_CTRL12      130#define IDM_FILE        200static HWND hMainWnd = HWND_INVALID;static HWND hChildWnd1;static HMENU hRightMenu;static void create_ctrls (HWND hWnd){        CreateWindow ("button", "Delete the selected item",                                 WS_CHILD                                 | BS_PUSHBUTTON                                 | WS_VISIBLE,                                 IDC_CTRL1, 10, 260, 140, 20, hWnd, 0);        CreateWindow ("button", "Clear all item",                                 WS_CHILD                                 | BS_PUSHBUTTON                                 | WS_VISIBLE,                                 IDC_CTRL2, 160, 260, 100, 20, hWnd, 0);        CreateWindow ("button", "select item",                                 WS_CHILD                                 | BS_PUSHBUTTON                                 | WS_VISIBLE,                                 IDC_CTRL3, 270, 260, 100, 20, hWnd, 0);        CreateWindow ("button", "show item",                                 WS_CHILD                                 | BS_PUSHBUTTON                                 | WS_VISIBLE,                                 IDC_CTRL4, 380, 260, 100, 20, hWnd, 0);        CreateWindow ("edit", "",                                 WS_CHILD                                 | WS_VISIBLE,                                 IDC_EDIT, 30, 230, 120, 20, hWnd, 0);        CreateWindow ("button", "del column",                                 WS_CHILD                                 | WS_VISIBLE,                                 IDC_CTRL6, 10, 290, 100, 20, hWnd, 0);        CreateWindow ("button", "set column head",                                 WS_CHILD                                 | WS_VISIBLE,                                 IDC_CTRL7, 120, 290, 120, 20, hWnd, 0);        CreateWindow ("button", "sorting the items",                                 WS_CHILD                                 | WS_VISIBLE,                                 IDC_CTRL8, 250, 290, 110, 20, hWnd, 0);        CreateWindow ("button", "find item",                                 WS_CHILD                                 | WS_VISIBLE,                                 IDC_CTRL9, 370, 290, 110, 20, hWnd, 0);}static int compare_time (HLVITEM nItem1, HLVITEM nItem2, PLVSORTDATA sortData){        DWORD data1, data2;        struct stat stat1, stat2;        data1 = SendMessage (hChildWnd1, LVM_GETITEMADDDATA, 0, nItem1);        data2 = SendMessage (hChildWnd1, LVM_GETITEMADDDATA, 0, nItem2);//printf ("nitem1 = %x, nitem2 = %x\n", nItem1, nItem2);//printf ("compare time: %s - %s\n", (char *)data1, (char *)data2);        stat ( (char*)data1, &stat1 );        stat ( (char*)data2, &stat2 );        return (stat1.st_mtime - stat2.st_mtime);}static int compare_size (HLVITEM nItem1, HLVITEM nItem2, PLVSORTDATA sortData){        DWORD data1, data2;        struct stat stat1, stat2;        int size1, size2;        data1 = SendMessage (hChildWnd1, LVM_GETITEMADDDATA, 0, nItem1);        data2 = SendMessage (hChildWnd1, LVM_GETITEMADDDATA, 0, nItem2);        stat ( (char*)data1, &stat1 );        stat ( (char*)data2, &stat2 );//printf ("compare size: %s - %s\n", (char *)data1, (char *)data2);        if (S_ISREG(stat1.st_mode))            size1 = stat1.st_size;        else            size1 = 0;        if (S_ISREG(stat2.st_mode))            size2 = stat2.st_size;        else            size2 = 0;        return (size1 - size2);}static HMENU create_rightbutton_menu (void){    int i;    HMENU hMenu;    MENUITEMINFO mii;    char *msg[] = {        "open",        "copy",        "delete",        "rename",        "properties"    };    memset (&mii, 0, sizeof(MENUITEMINFO));    mii.type        = MFT_STRING;    mii.id          = 0;    mii.typedata    = (DWORD)"File";    hMenu = CreatePopupMenu (&mii);    for ( i = 0; i < 5; i ++ ) {        memset ( &mii, 0, sizeof (MENUITEMINFO) );        mii.type = MFT_STRING;        mii.id = IDM_FILE+ i;        mii.state = 0;        mii.typedata= (DWORD) msg[i];         InsertMenuItem ( hMenu, i, TRUE, &mii );    }    return hMenu;    //return StripPopupHead(hMenu);}static voidlv_notify_process (HWND hwnd, int id, int code, DWORD addData){    if (code == LVN_KEYDOWN) {        PLVNM_KEYDOWN down;        int key;                down = (PLVNM_KEYDOWN)addData;        key = LOWORD(down->wParam);        if (key == SCANCODE_REMOVE) {            HLVITEM hlvi;            hlvi = SendMessage (hwnd, LVM_GETSELECTEDITEM, 0, 0);            if (hlvi) {                if( MessageBox (hMainWnd, "are you really want to delete this file?",                             "warning", MB_YESNO) == IDYES) {                    // not really delete yet.                    SendMessage (hwnd, LVM_DELITEM, 0, hlvi);                }            }        }        if (key == SCANCODE_ENTER) {        }    }    if (code == LVN_ITEMRUP) {        PLVNM_ITEMRUP up;        int x, y;                up = (PLVNM_ITEMRUP)addData;        x = LOSWORD(up->lParam);        y = HISWORD(up->lParam);        ClientToScreen (hChildWnd1, &x, &y);        TrackPopupMenu (GetPopupSubMenu (hRightMenu), TPM_LEFTALIGN | TPM_LEFTBUTTON ,             x, y, hMainWnd);    }    if (code == LVN_ITEMDBCLK) {        HLVITEM hlvi = SendMessage (hwnd, LVM_GETSELECTEDITEM, 0, 0);        if (hlvi > 0) {                if( MessageBox (hMainWnd, "Are you really want to open this file?",                             "Question", MB_YESNO) == IDYES) {                    MessageBox (hMainWnd, "Me too.", "Sorry", MB_OK);                }        }    }}extern BITMAP bmp_bkgnd;static intControlTestWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    static BITMAP folder;    switch (message)    {    case MSG_CREATE:    {        int i = 0;        LVSUBITEM subdata;        LVITEM item;        LVCOLUMN s1;        DIR*    dir;        struct  dirent* dir_ent;        struct  stat my_stat;        create_ctrls (hWnd);        hRightMenu = create_rightbutton_menu ();        LoadBitmapFromFile (HDC_SCREEN, &folder, "./res/folder.bmp");        hChildWnd1 = CreateWindowEx (CTRL_LISTVIEW, "List View",

⌨️ 快捷键说明

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