📄 statwnd.c
字号:
wc.hInstance = hinstance;
wc.hIcon = LoadIcon( (HINSTANCE)NULL, IDI_APPLICATION );
wc.hCursor = hDefaultCursor;
wc.hbrBackground = (HBRUSH) 0;
wc.lpszMenuName = NULL;
wc.lpszClassName = className;
rc = RegisterClass( &wc );
}
return( rc );
} /* StatusWndInit */
/*
* StatusWndChangeSysColors - fiddle with what StatusWnd believes
* are the system colours
*/
void StatusWndChangeSysColors( COLORREF btnFace, COLORREF btnText,
COLORREF btnHighlight, COLORREF btnShadow )
{
if( hasGDIObjects ) {
DeleteObject( penLight );
DeleteObject( penShade );
DeleteObject( brushButtonFace );
}
colorButtonFace = btnFace;
colorTextFace = btnText;
brushButtonFace = CreateSolidBrush( btnFace );
penLight = CreatePen( PS_SOLID, 1, btnHighlight );
penShade = CreatePen( PS_SOLID, 1, btnShadow );
hasGDIObjects = TRUE;
}
/*
* StatusWndCreate - create the status window
*/
HWND StatusWndCreate( HWND parent, RECT *size, HINSTANCE hinstance,
LPVOID lpvParam )
{
HWND stat;
#if defined (__NT__)
if( LOBYTE(LOWORD(GetVersion())) >= 4 ) {
stat = CreateWindow( className, NULL,
WS_CHILD,
size->left, size->top,
size->right - size->left, size->bottom - size->top,
parent, (HMENU)NULL, hinstance, lpvParam );
} else {
stat = CreateWindow( className, NULL,
WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS,
size->left, size->top,
size->right - size->left, size->bottom - size->top,
parent, (HMENU)NULL, hinstance, lpvParam );
}
#else
stat = CreateWindow( className, NULL,
WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS,
size->left, size->top,
size->right - size->left, size->bottom - size->top,
parent, (HMENU)NULL, hinstance, lpvParam );
#endif
if( stat != NULL ) {
#if defined (__NT__)
if (LOBYTE(LOWORD(GetVersion())) >= 4) {
/* New shell active, Win95 or later */
systemDataFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
} else {
systemDataFont = (HFONT) GetStockObject(SYSTEM_FONT);
}
#endif
ShowWindow( stat, SW_SHOWNORMAL );
UpdateWindow( stat );
}
return( stat );
} /* StatusWndCreate */
/*
* StatusWndDraw3DBox - called by StatusWndDrawLine or externally
* if StatusWndDrawLine is not used.
*/
void StatusWndDraw3DBox( HDC hdc )
{
HPEN old_pen;
int i;
RECT r;
old_pen = SelectObject( hdc, penLight );
for( i=0;i<=numSections;i++ ) {
getRect( &r, i );
outlineRect( hdc, &r );
makeInsideRect( &r );
FillRect( hdc, &r, brushButtonFace );
}
SelectObject( hdc, old_pen );
} /* StatusWndDraw3DBox */
/*
* outputText - output a text string
*/
void outputText( HDC hdc, char *buff, RECT *r, UINT flags, int curr_block )
{
RECT ir;
int len;
int ext;
int width;
if( sectionData[ curr_block ] != NULL ) {
if( !strcmp( buff, sectionData[ curr_block ] ) &&
flags == sectionDataFlags[ curr_block ] ) {
return;
}
}
len = strlen( buff );
if( len == 0 ) {
return;
}
MemFree( sectionData[ curr_block ] );
sectionData[ curr_block ] = MemAlloc( len+1 );
memcpy( sectionData[ curr_block ], buff, len+1 );
sectionDataFlags[ curr_block ] = flags;
#ifndef __NT__
ext = LOWORD( GetTextExtent( hdc, buff, len ) );
#else
{
SIZE sz;
GetTextExtentPoint( hdc, buff, len, &sz );
ext = sz.cx;
}
#endif
ir = *r;
if( flags & DT_CENTER ) {
width = (ir.right - ir.left - ext)/2;
if( width > 0 ) {
ir.right = ir.left+width;
FillRect( hdc, &ir, brushButtonFace );
ir.right = r->right;
ir.left = r->right-width;
FillRect( hdc, &ir, brushButtonFace );
}
} else if( flags & DT_RIGHT ) {
ir.right -= ext;
if( ir.right >= ir.left ) {
FillRect( hdc, &ir, brushButtonFace );
}
} else {
ir.left += ext;
if( ir.left < ir.right ) {
FillRect( hdc, &ir, brushButtonFace );
}
}
DrawText( hdc, buff, -1, r, flags );
} /* outputText */
/*
* StatusWndDrawLine - draws a line in the status bar
*/
void StatusWndDrawLine( HDC hdc, HFONT hfont, char *str, UINT flags )
{
RECT rect;
char buff[256];
char *bptr;
int curr_block;
curr_block = 0;
#if defined (__NT__)
sectionDataFont = systemDataFont;
#else
sectionDataFont = hfont;
#endif
initHDC( hdc );
getRect( &rect, curr_block );
makeInsideRect( &rect );
bptr = str;
if( flags == (UINT) -1 ) {
flags = DT_VCENTER | DT_LEFT;
bptr = buff;
while( *str ) {
if( *str == STATUS_ESC_CHAR ) {
str++;
switch( *str ) {
case STATUS_NEXT_BLOCK:
*bptr = 0;
outputText( hdc, buff, &rect, flags, curr_block );
curr_block++;
getRect( &rect, curr_block );
makeInsideRect( &rect );
flags = DT_VCENTER | DT_LEFT;
bptr = buff;
break;
case STATUS_FORMAT_CENTER:
flags &= ~(DT_RIGHT|DT_LEFT);
flags |= DT_CENTER;
break;
case STATUS_FORMAT_RIGHT:
flags &= ~(DT_CENTER|DT_LEFT);
flags |= DT_RIGHT;
break;
case STATUS_FORMAT_LEFT:
flags &= ~(DT_CENTER|DT_RIGHT);
flags |= DT_LEFT;
break;
}
} else {
*bptr++ = *str;
}
str++;
}
*bptr = 0;
bptr = buff;
}
outputText( hdc, bptr, &rect, flags, curr_block );
finiHDC( hdc );
} /* StatusWndDrawLine */
/*
* StatusWndSetSeparators - set the separator list
*/
void StatusWndSetSeparators( int num_items, status_block_desc *list )
{
int i;
if( num_items > MAX_SECTIONS ) {
num_items = MAX_SECTIONS;
}
for( i=0;i<num_items;i++ ) {
sectionDesc[i] = list[i];
}
numSections = num_items;
} /* StatusWndSetSeparators */
/*
* StatusWndFini - cleans up everything allocated for the status window
*/
void StatusWndFini( void )
{
int i;
if( hasGDIObjects ) {
DeleteObject( penLight );
DeleteObject( penShade );
DeleteObject( brushButtonFace );
hasGDIObjects = FALSE;
}
for( i=0;i<=numSections;i++ ) {
MemFree( sectionData[i] );
sectionData[i] = NULL;
}
numSections = 0;
} /* StatusWndFini */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -