📄 statwnd.c
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Status window for Windows.
*
****************************************************************************/
#include <windows.h>
#include <string.h>
#include "statwnd.h"
extern LPVOID MemAlloc( unsigned );
extern void MemFree( LPVOID );
#ifndef MAX_SECTIONS
#define MAX_SECTIONS 20
#endif
static char *className = "StatusWnd";
static int numSections;
static status_block_desc sectionDesc[MAX_SECTIONS];
static LPSTR sectionData[MAX_SECTIONS+1];
static UINT sectionDataFlags[MAX_SECTIONS+1];
static HFONT sectionDataFont;
#if defined (__NT__)
static HFONT systemDataFont;
#endif
static HPEN penLight;
static HPEN penShade;
static HBRUSH brushButtonFace;
static COLORREF colorButtonFace;
static COLORREF colorTextFace;
static statushook statusWndHookFunc;
static RECT statusRect;
static BOOL hasGDIObjects = FALSE;
#if defined(__WINDOWS_386__)
#define CB FAR PASCAL
#elif defined(__WINDOWS__)
#define CB __export FAR PASCAL
#elif defined(__NT__)
#define CB __export __stdcall
#endif
/*
* getRect - get a rectangle
*/
static void getRect( RECT *r, int i )
{
WORD pos;
WORD width;
*r = statusRect;
width = statusRect.right - statusRect.left;
if( i > 0 ) {
if( sectionDesc[i-1].width_is_percent ) {
pos = (WORD) (((DWORD) width * (DWORD) sectionDesc[i].width)/100L);
} else {
pos = sectionDesc[i-1].width;
}
r->left = pos+sectionDesc[i-1].separator_width;
}
if( i == numSections ) {
pos = statusRect.right;
} else if( sectionDesc[i].width_is_percent ) {
pos = (WORD) (((DWORD) (statusRect.right-statusRect.left)
* (DWORD) sectionDesc[i].width)/100L);
} else {
pos = sectionDesc[i].width;
}
r->right = pos;
} /* getRect */
static HFONT oldFont;
static HBRUSH oldBrush;
static COLORREF oldBkColor;
static COLORREF oldTextColor;
/*
* initHDC - initialize our HDC for drawing text
*/
static char initHDC( HDC hdc )
{
if( sectionDataFont == NULL ) {
return( FALSE );
}
#if defined (__NT__)
oldFont = SelectObject( hdc, systemDataFont );
#else
oldFont = SelectObject( hdc, sectionDataFont );
#endif
oldBrush = SelectObject( hdc, brushButtonFace );
oldBkColor = GetBkColor( hdc );
oldTextColor = GetTextColor( hdc );
SetBkColor( hdc, colorButtonFace );
SetTextColor( hdc, colorTextFace );
return( TRUE );
} /* initHDC */
/*
* finiHDC - finished with our HDC
*/
static void finiHDC( HDC hdc )
{
SelectObject( hdc, oldBrush );
SelectObject( hdc, oldFont );
SetBkColor( hdc, oldBkColor );
SetTextColor( hdc, oldTextColor );
} /* finiHDC */
/*
* makeInsideRect - make a rectangle the inside of a rectangle
*/
static void makeInsideRect( RECT *r )
{
r->left += BORDER_SIZE;
r->right -= BORDER_SIZE;
r->top += BORDER_SIZE;
r->bottom -= BORDER_SIZE;
} /* makeInsideRect */
/*
* outlineRect - draw the outline of a rectangle
*/
static void outlineRect( HDC hdc, RECT *r )
{
MoveToEx( hdc, r->left, r->bottom - 1, NULL );
LineTo( hdc, r->right - 1, r->bottom - 1 );
LineTo( hdc, r->right - 1, r->top );
SelectObject( hdc, penShade );
LineTo( hdc, r->left, r->top );
LineTo( hdc, r->left, r->bottom - 1 );
SelectObject( hdc, penLight );
} /* outlineRect */
/*
* StatusWndCallback - handle messages for
*/
LONG CB StatusWndCallback( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
PAINTSTRUCT ps;
RECT r;
int i;
if( statusWndHookFunc != NULL ) {
if( statusWndHookFunc( hwnd, msg, wparam, lparam ) ) {
return( 0 );
}
}
switch( msg ) {
case WM_SIZE:
GetClientRect( hwnd, &statusRect );
InflateRect( &statusRect, - HORZ_BORDER, - VERT_BORDER );
return( DefWindowProc( hwnd, msg, wparam, lparam ) );
case WM_PAINT:
BeginPaint( hwnd, &ps );
StatusWndDraw3DBox( ps.hdc );
if( initHDC( ps.hdc ) ) {
for( i=0;i<=numSections;i++ ) {
if( sectionData[i] != NULL ) {
getRect( &r, i );
makeInsideRect( &r );
DrawText( ps.hdc, sectionData[i], -1, &r, sectionDataFlags[i] );
}
}
finiHDC( ps.hdc );
}
EndPaint( hwnd, &ps );
break;
#if defined (__NT__)
case WM_SYSCOLORCHANGE:
if( hasGDIObjects ) {
DeleteObject( penLight );
DeleteObject( penShade );
DeleteObject( brushButtonFace );
hasGDIObjects = FALSE;
}
if( !hasGDIObjects ) {
colorButtonFace = GetSysColor( COLOR_BTNFACE );
colorTextFace = GetSysColor( COLOR_BTNTEXT );
brushButtonFace = CreateSolidBrush( colorButtonFace );
penLight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) );
penShade = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) );
hasGDIObjects = TRUE;
}
break;
#endif
case WM_ERASEBKGND:
#if defined (__NT__)
if(colorButtonFace != GetSysColor( COLOR_BTNFACE )) {
/* WM_SYSCOLORCHANGED: not received by this window.
Have to fake it... */
SendMessage( hwnd, WM_SYSCOLORCHANGE, (WPARAM)0, (LPARAM)0 );
}
#endif
GetClientRect( hwnd, &r );
UnrealizeObject( brushButtonFace );
FillRect( (HDC)wparam, &r, brushButtonFace );
break;
default:
return( DefWindowProc( hwnd, msg, wparam, lparam ) );
}
return( 0 );
} /* StatusWndCallback */
/*
* StatusWndInit - initialize for using the status window
*/
int StatusWndInit( HINSTANCE hinstance, statushook hook, int extra,
HCURSOR hDefaultCursor )
{
WNDCLASS wc;
int rc;
if( !hasGDIObjects ) {
colorButtonFace = GetSysColor( COLOR_BTNFACE );
colorTextFace = GetSysColor( COLOR_BTNTEXT );
brushButtonFace = CreateSolidBrush( colorButtonFace );
penLight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) );
penShade = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) );
hasGDIObjects = TRUE;
}
statusWndHookFunc = hook;
rc = TRUE;
if( !GetClassInfo( hinstance, className, &wc ) ) {
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)StatusWndCallback;
wc.cbClsExtra = 0;
wc.cbWndExtra = extra;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -