home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
4418
/
DEMO
/
SOURCE.ZIP
/
STATETOO.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-23
|
6KB
|
199 lines
#include <windows.h>
#include <windowsx.h>
#include <dos.h>
#include <commdlg.h>
#include <shellapi.h>
#include <string.h>
#include "winx31ad.h"
#pragma pack (1)
#include "statetoo.h"
extern HANDLE ghInst;
char szMenuText[128];
static BOOL fIsText = FALSE;
static RECT rectInfo ;
HWND hWndInfo = NULL;
WORD cxChar,cyChar;
void DoSetInfo(HWND hWnd,LPRECT lpRect)
{
TEXTMETRIC tm;
HDC hdc;
hWndInfo = hWnd;
rectInfo = *lpRect;
hdc = GetDC(hWnd);
GetTextMetrics(hdc,&tm);
ReleaseDC(hWnd,hdc);
cxChar = (WORD)tm.tmMaxCharWidth ;
cyChar = (WORD)(tm.tmHeight + tm.tmExternalLeading) ;
}
void DoSetTextInfo(LPSTR lpszTxt)
{
if (hWndInfo == NULL) return;
if (fIsText) InvalidateRect(hWndInfo,&rectInfo,FALSE);
fIsText = FALSE;
if (lpszTxt == NULL) return;
InvalidateRect(hWndInfo,&rectInfo,FALSE);
fIsText = TRUE;
_fstrncpy(szMenuText,lpszTxt,sizeof(szMenuText)-1);
szMenuText[127] = '\0';
}
void DoSetTextResourceInfo(HWND hWnd,UINT idRes)
{
if (hWndInfo == NULL) return;
if (fIsText) InvalidateRect(hWnd,&rectInfo,FALSE);
fIsText = FALSE;
if (idRes == NULL) return;
InvalidateRect(hWnd,&rectInfo,FALSE);
fIsText = TRUE;
LoadString(ghInst,idRes,szMenuText,sizeof(szMenuText)-1);
}
void DoCadre(HDC hdc,UINT left,UINT right,UINT top,UINT bottom,
LPSTR lpTxt,WORD wPct,COLORREF clrref)
{
HBRUSH hBrush;
HPEN hOldPen;
RECT rect;
BOOL fProvDC ;
if (hWndInfo == NULL) return;
fProvDC = (hdc == NULL) ;
if (fProvDC) hdc = GetDC(hWndInfo);
rect.left=left+1; rect.right=right-1; rect.bottom=bottom+1; rect.top=top-1;
if (wPct == 0)
{
hBrush=CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
FillRect(hdc,&rect,hBrush);
DeleteObject(hBrush);
}
else
{
hBrush=CreateSolidBrush(clrref);
rect.right=left+(int)(((right-left)*(DWORD)wPct)/100);
FillRect(hdc,&rect,hBrush);
DeleteObject(hBrush);
}
rect.left--; rect.right++; rect.top--; rect.bottom++;
if (lpTxt!=NULL)
{
HFONT hOldFont ;
LOGFONT logFont;
SetBkColor(hdc,GetSysColor(COLOR_BTNFACE));
_fmemset(&logFont,0,sizeof(LOGFONT));
logFont.lfWeight = FW_NORMAL;
lstrcpy(logFont.lfFaceName,"MS Sans Serif");
logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS ;
logFont.lfHeight = 16;
hOldFont = SelectObject(hdc,CreateFontIndirect(&logFont));
TextOut(hdc,cxChar+left,top,lpTxt,lstrlen(lpTxt));
DeleteObject(SelectObject(hdc,hOldFont));
}
hOldPen=SelectObject(hdc,
CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNSHADOW)));
MoveToEx(hdc,left,bottom,NULL);
LineTo(hdc,left,top);
LineTo(hdc,right,top);
DeleteObject(SelectObject(hdc,hOldPen));
hOldPen=SelectObject(hdc,
CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNHIGHLIGHT)));
MoveToEx(hdc,right,top,NULL);
LineTo(hdc,right,bottom);
LineTo(hdc,left,bottom);
DeleteObject(SelectObject(hdc,hOldPen));
if (fProvDC) ReleaseDC(hWndInfo,hdc);
}
void Jauge(HDC hdc,WORD wPct,COLORREF clrref)
{
BOOL fProvDC ;
if (hWndInfo == NULL) return;
fProvDC = (hdc == NULL) ;
if (fProvDC) hdc = GetDC(hWndInfo);
// DoPeek();
if (cxChar*1<rectInfo.right-cxChar)
DoCadre(hdc,cxChar*1,rectInfo.right-cxChar,
rectInfo.top+3,rectInfo.bottom-3,
NULL,wPct,clrref);
if (fProvDC) ReleaseDC(hWndInfo,hdc);
}
void DoPaintInfo (HDC hdc)
{
HBRUSH hBrush;
char szText[40];
//char szRess[40];
RECT rect;
BOOL fProvDC ;
LPRECT lpRect=&rectInfo;
if (hWndInfo == NULL) return;
fProvDC = (hdc == NULL) ;
if (fProvDC) hdc = GetDC(hWndInfo);
rect = rectInfo;
rect.top +=2;
hBrush=CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
FillRect(hdc,&rectInfo,hBrush);
DeleteObject(hBrush);
SelectObject(hdc,GetStockObject(BLACK_PEN));
MoveToEx(hdc,lpRect->left,lpRect->top+0,NULL);
LineTo(hdc,lpRect->right,lpRect->top+0);
SelectObject(hdc,GetStockObject(WHITE_PEN));
MoveToEx(hdc,lpRect->left,lpRect->top+1,NULL);
LineTo(hdc,lpRect->right,lpRect->top+1);
if (fIsText)
{
HFONT hOldFont ;
LOGFONT logFont;
SetBkColor(hdc,GetSysColor(COLOR_BTNFACE));
_fmemset(&logFont,0,sizeof(LOGFONT));
logFont.lfWeight = FW_NORMAL;
lstrcpy(logFont.lfFaceName,"MS Sans Serif");
logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS ;
logFont.lfHeight = 16;
hOldFont = SelectObject(hdc,CreateFontIndirect(&logFont));
TextOut(hdc,cxChar,lpRect->top+3,szMenuText,lstrlen(szMenuText));
DeleteObject(SelectObject(hdc,hOldFont));
return;
}
szText[0]='\0';
//DoCadre(hdc,cxChar/2,cxChar*6,lpRect->top+3,lpRect->bottom-3,
// szText,0,0);
//if (pCurGdb!=NULL)
// if (pCurGdb->dwGiveSizeByte() != 0)
// wsprintf(szText,"%lu octets",pCurGdb->dwGiveSizeByte());
szText[0]='\0';
//DoCadre(hdc,cxChar*6+(cxChar/2),cxChar*17+(cxChar/2),lpRect->top+3,lpRect->bottom-3,
// szText,0,0);
Jauge(hdc,0,0);
if (fProvDC) ReleaseDC(hWndInfo,hdc);
}