lsctrl.c
来自「CC386 is a general-purpose 32-bit C comp」· C语言 代码 · 共 564 行 · 第 1/2 页
C
564 行
/*
Copyright 2001-2003 Free Software Foundation, Inc.
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.
You may contact the author at:
mailto::camille@bluegrass.net
or by snail mail at:
David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
**********************************************************************
LSCTRL.C is the container window used when windows are docked. It has
two bars at the top or left, followed by a close button and a button
to expand or contract the window when it is put in the same row
or column with similar windows. Other windows are placed inside it to
perform whatever functionality is needed.
**********************************************************************
*/
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "lsctrl.h"
#define TITLEWIDTH 15
#define EDGEWIDTH 1
#define TITLETOP 3
#define BARLEFT 3
#define BARRIGHT (BUTTONCORNER + 2 * BUTTONWIDTH + 4)
#define BARTOP 0
#define BUTTONCORNER 1
#define BUTTONWIDTH 12
static char *szControlWindClassName = "ladSoftControlWindow";
static HCURSOR hcurs, vcurs, lcurs, rcurs, mcurs;
static HBITMAP closebitmap, uparr, downarr, leftarr, rightarr, uparrdis,
leftarrdis;
static void DrawBorder(HDC dc, RECT *r1, int vertical, int active)
{
HBRUSH brush = CreateSolidBrush(GetSysColor(active ? COLOR_ACTIVEBORDER :
COLOR_INACTIVEBORDER));
RECT r2;
r2 = *r1;
if (vertical)
r2.right = r2.left + TITLEWIDTH;
else
r2.right = r2.left + EDGEWIDTH;
FillRect(dc, &r2, brush);
r2 = *r1;
r2.left = r2.right - EDGEWIDTH;
FillRect(dc, &r2, brush);
r2 = *r1;
if (vertical)
r2.bottom = r2.top + EDGEWIDTH;
else
r2.bottom = r2.top + TITLEWIDTH;
FillRect(dc, &r2, brush);
r2 = *r1;
r2.top = r2.bottom - EDGEWIDTH;
FillRect(dc, &r2, brush);
DeleteObject(brush);
}
//-------------------------------------------------------------------------
static void DrawTitle(HDC dc, RECT *r, int vertical)
{
HPEN pen1, pen2, pen3, oldpen;
pen1 = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DLIGHT));
pen2 = CreatePen(PS_SOLID, 2, GetSysColor(COLOR_3DHILIGHT));
pen3 = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
if (!vertical)
{
r->top = TITLETOP;
r->left += EDGEWIDTH;
r->right -= EDGEWIDTH;
oldpen = SelectObject(dc, pen1);
SelectObject(dc, pen1);
MoveToEx(dc, r->left + BARLEFT, r->top + BARTOP, 0);
LineTo(dc, r->right - BARRIGHT + 1, r->top + BARTOP);
SelectObject(dc, pen2);
MoveToEx(dc, r->left + BARLEFT - 1, r->top + BARTOP + 1, 0);
LineTo(dc, r->right - BARRIGHT, r->top + BARTOP + 1);
SelectObject(dc, pen3);
MoveToEx(dc, r->left + BARLEFT, r->top + BARTOP + 3, 0);
LineTo(dc, r->right - BARRIGHT + 1, r->top + BARTOP + 3);
SelectObject(dc, pen2);
MoveToEx(dc, r->left + BARLEFT - 1, r->top + BARTOP + 5, 0);
LineTo(dc, r->right - BARRIGHT, r->top + BARTOP + 5);
SelectObject(dc, pen3);
MoveToEx(dc, r->left + BARLEFT, r->top + BARTOP + 7, 0);
LineTo(dc, r->right - BARRIGHT + 1, r->top + BARTOP + 7);
}
else
{
r->left = TITLETOP;
r->top += EDGEWIDTH;
r->bottom -= EDGEWIDTH;
oldpen = SelectObject(dc, pen1);
MoveToEx(dc, r->left + BARTOP, r->top + BARRIGHT - 1, 0);
LineTo(dc, r->left + BARTOP, r->bottom - BARLEFT);
SelectObject(dc, pen2);
MoveToEx(dc, r->left + BARTOP + 1, r->top + BARRIGHT, 0);
LineTo(dc, r->left + BARTOP + 1, r->bottom - BARLEFT + 1);
SelectObject(dc, pen3);
MoveToEx(dc, r->left + BARTOP + 3, r->top + BARRIGHT - 1, 0);
LineTo(dc, r->left + BARTOP + 3, r->bottom - BARLEFT);
SelectObject(dc, pen2);
MoveToEx(dc, r->left + BARTOP + 5, r->top + BARRIGHT, 0);
LineTo(dc, r->left + BARTOP + 5, r->bottom - BARLEFT + 1);
SelectObject(dc, pen3);
MoveToEx(dc, r->left + BARTOP + 7, r->top + BARRIGHT - 1, 0);
LineTo(dc, r->left + BARTOP + 7, r->bottom - BARLEFT);
}
SelectObject(dc, oldpen);
DeleteObject(pen1);
DeleteObject(pen2);
DeleteObject(pen3);
}
//-------------------------------------------------------------------------
#define RANGE(x,y) ((x) == (y) || (x)+1 == (y)+1)
static void SetFlexBmp(CCW_params *ptr)
{
if (ptr->vertical)
{
if (ptr->u.cw.disabled)
SendMessage(ptr->u.cw.flexbutton, BM_SETIMAGE, IMAGE_BITMAP,
(LPARAM)leftarrdis);
else if (ptr->u.cw.flexed)
SendMessage(ptr->u.cw.flexbutton, BM_SETIMAGE, IMAGE_BITMAP,
(LPARAM)rightarr);
else
SendMessage(ptr->u.cw.flexbutton, BM_SETIMAGE, IMAGE_BITMAP,
(LPARAM)leftarr);
}
else
{
if (ptr->u.cw.disabled)
SendMessage(ptr->u.cw.flexbutton, BM_SETIMAGE, IMAGE_BITMAP,
(LPARAM)uparrdis);
else if (ptr->u.cw.flexed)
SendMessage(ptr->u.cw.flexbutton, BM_SETIMAGE, IMAGE_BITMAP,
(LPARAM)downarr);
else
SendMessage(ptr->u.cw.flexbutton, BM_SETIMAGE, IMAGE_BITMAP,
(LPARAM)uparr);
}
}
//-------------------------------------------------------------------------
static LRESULT CALLBACK _export ControlWindWndProc(HWND hwnd, UINT iMessage,
WPARAM wParam, LPARAM lParam)
{
RECT r, *pr;
PAINTSTRUCT ps;
HDC dc;
CCW_params *ptr;
static int skip;
static int dragging, oncursor, sizing;
static HCURSOR oldCursor;
POINT temppt;
int temp;
HBRUSH brush;
switch (iMessage)
{
case WM_NOTIFY:
ptr = (CCW_params*)GetWindowLong(hwnd, 0);
return SendMessage(ptr->parent, iMessage, wParam, lParam);
case WM_SYSCOMMAND:
if (wParam == SC_CLOSE)
SendMessage(hwnd, WM_CLOSE, 0, 0);
break;
case WM_COMMAND:
ptr = (CCW_params*)GetWindowLong(hwnd, 0);
if (HIWORD(wParam) == BN_CLICKED && (LOWORD(wParam) == 64371 ||
LOWORD(wParam) == 64373))
SendMessage(ptr->parent, WM_SYSCOMMAND, SC_CLOSE, 0);
else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == 64372)
{
SetFlexBmp(ptr);
SetFocus(hwnd);
dmgrFlex(ptr);
}
else
return SendMessage(ptr->parent, iMessage, wParam, lParam);
break;
case WM_ERASEBKGND:
return 0;
case WM_LBUTTONDOWN:
ptr = (CCW_params*)GetWindowLong(hwnd, 0);
if (ptr->container)
break;
temppt.x = (long)(short)LOWORD(lParam);
temppt.y = (long)(short)HIWORD(lParam);
if (oldCursor)
{
dmgrStartSizeClient(ptr, oncursor, lParam);
SetCapture(hwnd);
sizing = TRUE;
}
else if ((ptr->vertical && temppt.x < 17) || (!ptr->vertical &&
temppt.y < 17))
{
dmgrStartMoveClient(ptr, lParam);
oldCursor = SetCursor(mcurs);
SetCapture(hwnd);
dragging = TRUE;
}
break;
case WM_LBUTTONUP:
ptr = (CCW_params*)GetWindowLong(hwnd, 0);
if (ptr->container)
break;
if (dragging)
{
SetCursor(oldCursor);
oldCursor = 0;
}
if (dragging)
ReleaseCapture();
dragging = FALSE;
sizing = FALSE;
dmgrEndMoveSizeClient(ptr);
break;
case WM_MOUSEMOVE:
ptr = (CCW_params*)GetWindowLong(hwnd, 0);
if (ptr->container)
break;
if (dragging)
{
dmgrMoveClient(ptr, lParam, FALSE);
}
else if (sizing)
{
dmgrSizeClient(ptr, lParam);
}
else
{
HCURSOR cursor = 0;
if (dmgrDocked(ptr))
break;
ptr = (CCW_params*)GetWindowLong(hwnd, 0);
temppt.x = (long)(short)LOWORD(lParam);
temppt.y = (long)(short)HIWORD(lParam);
GetClientRect(hwnd, &r);
if (RANGE(temppt.x, r.right - 1))
{
if (RANGE(temppt.y, r.bottom - 1))
{
cursor = SetCursor(lcurs);
oncursor = HTBOTTOMRIGHT;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?