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

📄 combobox.c

📁 libminigui-1.3.0.tar.gz。 miniGUI的库函数源代码!
💻 C
📖 第 1 页 / 共 3 页
字号:
/*** $Id: combobox.c,v 1.50 2003/11/23 04:09:08 weiym Exp $**** cobmobox.c: the cobmobox control.**** Copyright (C) 2003 Feynman Software** Copyright (C) 2001 ~ 2002 Wei Yongming**** NOTE: Originally by Wang Jian**** Create date: 2001/08/06*//*** This program 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 program 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 program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//*** TODO: */#include <stdio.h>#include <stdlib.h>#include <string.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "control.h"#include "cliprect.h"#include "internals.h"#include "ctrlclass.h"#ifdef _CTRL_COMBOBOX#include "edit.h"#include "combobox.h"#include "ctrlmisc.h"#define  LEN_SPINVALUE          50#define  IDC_CEDIT              100#define  IDC_CLISTBOX           101    #define  INTER_EDIT_BUTTON      2 #define  INTER_EDIT_LISTBOX     4 #define  DEF_LISTHEIGHT         60static BITMAP bmp_downarrow;static BITMAP bmp_updownarrow;#define ARROWBMP_DOWN       (&bmp_downarrow)#define ARROWBMP_UPDOWN     (&bmp_updownarrow)static int ComboBoxCtrlProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam);BOOL RegisterComboBoxControl (void){    WNDCLASS WndClass;    if (!LoadSystemBitmap (&bmp_downarrow, SYSBMP_DOWNARROW))        return FALSE;    if (!LoadSystemBitmap (&bmp_updownarrow, SYSBMP_UPDOWNARROW))        return FALSE;    WndClass.spClassName = CTRL_COMBOBOX;    WndClass.dwStyle     = WS_NONE;    WndClass.dwExStyle   = WS_EX_NONE;    WndClass.hCursor     = GetSystemCursor (0);    WndClass.iBkColor    = GetWindowElementColor (BKC_CONTROL_DEF);    WndClass.WinProc     = ComboBoxCtrlProc;    return AddNewControlClass (&WndClass) == ERR_OK;}static int AutoSpinEditBoxProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam ){    WNDPROC old_edit_proc;    if (message == MSG_CHAR) {        if (wParam < '0' || wParam > '9')            return 0;    }    old_edit_proc = (WNDPROC) GetWindowAdditionalData (hWnd);    return (*old_edit_proc) (hWnd, message, wParam, lParam);}static int DefCBProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam);inline static void GetButtonRect (HWND hwnd, int *x, int *y, int *w, int *h){    PCOMBOBOXDATA pData;    PCONTROL pCtrl;    pCtrl = Control (hwnd);     pData = (PCOMBOBOXDATA)pCtrl->dwAddData2;    *x = pData->ButtonRect.left;    *y = pData->ButtonRect.top;    *w = pData->ButtonRect.right-*x;    *h = pData->ButtonRect.bottom-*y;}static BOOL ComboBoxDownButton (HWND hwnd, HDC hdc){    int x, y, w, h;    PCOMBOBOXDATA pData;    PCONTROL pCtrl;     pCtrl = Control (hwnd);         pData = (PCOMBOBOXDATA)pCtrl->dwAddData2;     GetButtonRect (hwnd, &x, &y, &w, &h);    if (pData->ButtonBmp)        FillBoxWithBitmap (hdc, x, y + WIDTH_EDIT_BORDER, 0, 0, pData->ButtonBmp);    return TRUE;}static int ComboBoxCtrlProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam){    PCONTROL      pCtrl   = Control (hwnd);    PCOMBOBOXDATA pData   = (PCOMBOBOXDATA)pCtrl->dwAddData2;    DWORD         dwStyle = pCtrl->dwStyle;        switch (message) {        case MSG_CREATE:        {            RECT rect;            int  height, width, edit_width, list_height, btn_width;            int  tmpx, tmpy;            const char* edit_text = GetWindowCaption (hwnd);            DWORD list_style, edit_style;            if (!(pData = calloc (1, sizeof (COMBOBOXDATA)))) {                fprintf (stderr, "Create ComboBox control failure!\n");                return -1;            }            pData->wStateFlags = 0;            pData->nListItems = 0;            pCtrl->dwAddData2 = (DWORD)pData;            GetClientRect (hwnd, &rect);            //height = GetMainWinMetrics (MWM_ICONY)             height = GetSysCharHeight ()                    + MARGIN_EDIT_TOP + MARGIN_EDIT_BOTTOM + (WIDTH_EDIT_BORDER<<1);            width = rect.right - rect.left;            btn_width = GetMainWinMetrics (MWM_ICONX);            edit_width = width - btn_width - INTER_EDIT_BUTTON;            list_style = WS_VSCROLL | LBS_NOTIFY | WS_THINFRAME;            if (dwStyle & CBS_SORT) list_style |= LBS_SORT;            edit_style = WS_CHILD | WS_VISIBLE;            if (!(dwStyle & CBS_EDITNOBORDER)) edit_style |= WS_BORDER;            if (dwStyle & CBS_EDITBASELINE) edit_style |= ES_BASELINE;            if (dwStyle & CBS_UPPERCASE) edit_style |= ES_UPPERCASE;            if (dwStyle & CBS_LOWERCASE) edit_style |= ES_LOWERCASE;            if (dwStyle & CBS_READONLY) edit_style |= ES_READONLY;            switch (dwStyle & CBS_TYPEMASK) {            case CBS_SIMPLE:                list_height = (pCtrl->dwAddData > 0) ? pCtrl->dwAddData : DEF_LISTHEIGHT;                list_style |= WS_VISIBLE | WS_BORDER;                edit_width = width;                width -= GetMainWinMetrics (MWM_ICONX);                pData->ButtonBmp = 0;                pData->ListBoxRect.left = rect.left + GetMainWinMetrics (MWM_ICONX);                pData->ListBoxRect.right = rect.right - MARGIN_EDIT_RIGHT;                pData->ListBoxRect.top = rect.top + height + INTER_EDIT_LISTBOX;                pData->ListBoxRect.bottom = pData->ListBoxRect.top + list_height;                break;            case CBS_SPINLIST:                pData->ButtonBmp = ARROWBMP_UPDOWN;                list_height = 0;                pData->spin_pace = 1;                pData->fastspin_pace = 5;                break;            case CBS_AUTOSPIN:                pData->ButtonBmp = ARROWBMP_UPDOWN;                pData->spin_min = 0;                pData->spin_max = 100;                pData->spin_pace = 1;                pData->fastspin_pace = 5;                list_height = -1;                break;            default:                list_height = (pCtrl->dwAddData > 0) ? pCtrl->dwAddData : DEF_LISTHEIGHT;                pData->ButtonBmp = ARROWBMP_DOWN;                pData->ListBoxRect.left = rect.left;                pData->ListBoxRect.right = rect.right;                pData->ListBoxRect.top = rect.top + height;                pData->ListBoxRect.bottom = rect.top + height + list_height;                break;            }            tmpx = pData->ListBoxRect.right;            tmpy = pData->ListBoxRect.bottom;            ClientToScreen (hwnd, &tmpx, &tmpy);            if (tmpy > g_rcScr.bottom) {                pData->ListBoxRect.left = rect.left;                pData->ListBoxRect.right = rect.right;                pData->ListBoxRect.top = rect.top - list_height;                pData->ListBoxRect.bottom = rect.top;            }            pData->EditControl = CreateWindow (CTRL_SLEDIT,                             edit_text,                             edit_style, IDC_CEDIT,                            rect.left, rect.top,                             edit_width,                            height,                            hwnd, 0);            if ((dwStyle & CBS_TYPEMASK) == CBS_AUTOSPIN) {                WNDPROC old_edit_proc = SetWindowCallbackProc (pData->EditControl, AutoSpinEditBoxProc);                SetWindowAdditionalData (pData->EditControl, (DWORD)old_edit_proc);                pData->str_format = strdup ("%d");            }            if (list_height >= 0) {                pData->ListBoxControl = CreateWindowEx (CTRL_LISTBOX,                            "listbox",                             list_style,                             ((dwStyle & CBS_TYPEMASK) != CBS_SIMPLE) ? WS_EX_CTRLASMAINWIN : WS_EX_NONE,                            IDC_CLISTBOX,                            pData->ListBoxRect.left, pData->ListBoxRect.top,                            width, list_height,                             hwnd, 0);            }            else {                pData->ListBoxControl = 0;            }            pData->ButtonRect.left = rect.right - btn_width;            pData->ButtonRect.right = rect.right;            pData->ButtonRect.top = rect.top;            pData->ButtonRect.bottom = rect.top + height;            break;        }        case MSG_DESTROY:            DestroyAllControls (hwnd);            free (pData->str_format);            free (pData);        return 0;        case MSG_SIZECHANGING:        {            const RECT* rcExpect = (const RECT*)wParam;            RECT* rcResult = (RECT*)lParam;            int height = GetMainWinMetrics (MWM_ICONY)                     + MARGIN_EDIT_TOP + MARGIN_EDIT_BOTTOM + (WIDTH_EDIT_BORDER<<1);            rcResult->left = rcExpect->left;            rcResult->top = rcExpect->top;            rcResult->right = rcExpect->right;            rcResult->bottom = rcExpect->top + height;            if ((dwStyle & CBS_TYPEMASK) == CBS_SIMPLE)                rcResult->bottom +=                         (pData->ListBoxRect.bottom - pData->ListBoxRect.top + INTER_EDIT_LISTBOX);            return 0;        }        case MSG_CHILDHIDDEN:         {             int reason = wParam;             int x = LOSWORD(lParam);             int y = HISWORD(lParam); 

⌨️ 快捷键说明

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