📄 mstatwnd.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: Multiple status window class.
*
****************************************************************************/
#include <windows.h>
#include <string.h>
#include "mstatwnd.h"
extern LPVOID MemAlloc( unsigned );
extern void MemFree( LPVOID );
static char *className = "MStatusWnd";
static HPEN penLight;
static HPEN penShade;
static HBRUSH brushButtonFace;
static BOOL hasGDIObjects;
static COLORREF colorButtonFace;
static statushook statusWndHookFunc;
static int classWinExtra;
static statwnd *cheesy_stat;
#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( statwnd *sw, RECT *r, int i )
{
WORD pos;
WORD width;
*r = sw->statusRect;
width = sw->statusRect.right - sw->statusRect.left;
if( i > 0 ) {
if( sw->sectionDesc[i-1].width_is_percent ) {
pos = (WORD) (((DWORD) width * (DWORD) sw->sectionDesc[i].width)/100L);
} else {
pos = sw->sectionDesc[i-1].width;
}
r->left = pos+sw->sectionDesc[i-1].separator_width;
}
if( i == sw->numSections ) {
pos = sw->statusRect.right;
} else if( sw->sectionDesc[i].width_is_percent ) {
pos = (WORD) (((DWORD) (sw->statusRect.right-sw->statusRect.left)
* (DWORD) sw->sectionDesc[i].width)/100L);
} else {
pos = sw->sectionDesc[i].width;
}
r->right = pos;
} /* getRect */
static HFONT oldFont;
static HBRUSH oldBrush;
static COLORREF oldBkColor;
/*
* initHDC - initialize our HDC for drawing text
*/
static char initHDC( statwnd *sw, HDC hdc )
{
#if !defined (__NT__)
if( sw->sectionDataFont == NULL ) {
return( FALSE );
}
#endif
oldFont = SelectObject( hdc, sw->sectionDataFont );
oldBrush = SelectObject( hdc, brushButtonFace );
oldBkColor = GetBkColor( hdc );
SetBkColor( hdc, colorButtonFace );
return( TRUE );
} /* initHDC */
/*
* finiHDC - finished with our HDC
*/
static void finiHDC( HDC hdc )
{
SelectObject( hdc, oldBrush );
SelectObject( hdc, oldFont );
SetBkColor( hdc, oldBkColor );
} /* 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, UINT wparam, LONG lparam )
{
PAINTSTRUCT ps;
RECT r;
int i;
statwnd *sw;
sw = (statwnd *) GetWindowLong( hwnd, classWinExtra );
if( statusWndHookFunc != NULL ) {
if( statusWndHookFunc( hwnd, msg, wparam, lparam ) ) {
return( 0 );
}
}
if ( ( ( msg == WM_SIZE ) || ( msg == WM_PAINT ) ) && !sw ) {
return( DefWindowProc( hwnd, msg, wparam, lparam ) );
}
switch( msg ) {
case WM_CREATE:
SetWindowLong ( hwnd, classWinExtra, (LONG) cheesy_stat );
return( DefWindowProc( hwnd, msg, wparam, lparam ) );
case WM_SIZE:
GetClientRect( hwnd, &sw->statusRect );
InflateRect( &sw->statusRect, - HORZ_BORDER, - VERT_BORDER );
return( DefWindowProc( hwnd, msg, wparam, lparam ) );
case WM_PAINT:
BeginPaint( hwnd, &ps );
StatusWndDraw3DBox( sw, ps.hdc );
if( initHDC( sw, ps.hdc ) ) {
#if defined (__NT__)
if( LOBYTE(LOWORD(GetVersion())) >= 4 ) {
SelectObject( ps.hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT) );
} else {
SelectObject( ps.hdc, (HFONT)GetStockObject(SYSTEM_FONT) );
}
#endif
for( i = 0; i <= sw->numSections; i++ ) {
if( sw->sectionData[i] != NULL ) {
getRect( sw, &r, i );
makeInsideRect( &r );
DrawText( ps.hdc, sw->sectionData[i], -1, &r, sw->sectionDataFlags[i] );
}
}
finiHDC( ps.hdc );
}
EndPaint( hwnd, &ps );
break;
case WM_ERASEBKGND:
#if defined (__NT__)
if( colorButtonFace != GetSysColor( COLOR_BTNFACE ) ) {
DeleteObject( brushButtonFace );
DeleteObject( penLight );
DeleteObject( penShade );
colorButtonFace = GetSysColor( COLOR_BTNFACE );
brushButtonFace = CreateSolidBrush( colorButtonFace );
penLight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) );
penShade = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) );
hasGDIObjects = TRUE;
}
#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 )
{
WNDCLASS wc;
int rc;
if( !hasGDIObjects ) {
colorButtonFace = GetSysColor( COLOR_BTNFACE );
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 ) ) {
classWinExtra = wc.cbWndExtra - sizeof(statwnd *);
} else {
classWinExtra = extra;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (LPVOID) StatusWndCallback;
wc.cbClsExtra = 0;
wc.cbWndExtra = extra + sizeof(statwnd *);
wc.hInstance = hinstance;
wc.hIcon = LoadIcon( (HINSTANCE)NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( (HINSTANCE)NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) 0;
wc.lpszMenuName = NULL;
wc.lpszClassName = className;
rc = RegisterClass( &wc );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -