📄 drive.c
字号:
return i;
}
/**************************************************************************/
/*** ***/
/*** MeasureItem ***/
/*** ***/
/**************************************************************************/
void MeasureItem( HANDLE hDlg, LPMEASUREITEMSTRUCT mis )
{
HDC hDC = GetDC( hDlg );
TEXTMETRIC tm;
HANDLE hFont;
if ( !dyItem ) {
hFont = (HANDLE)(DWORD)SendMessage(hDlg, WM_GETFONT, 0, 0L);
if (!hFont)
hFont = GetStockObject( SYSTEM_FONT );
hFont = SelectObject( hDC, hFont );
GetTextMetrics( hDC, &tm );
SelectObject( hDC, hFont );
ReleaseDC( hDlg, hDC );
dyText = tm.tmHeight;
dyItem = max( dyDirDrive, dyText );
}
mis->itemHeight = dyItem;
}
/**************************************************************************/
/*** ***/
/*** DrawItem ***/
/*** ***/
/**************************************************************************/
void DrawItem( HWND hDlg, WPARAM wParam, LPDRAWITEMSTRUCT lpdis, BOOL bSave )
{
HDC hdcList;
RECT rectHilite;
char szText[_MAX_PATH+1];
WORD dxAcross;
short nHeight;
LONG rgbBack, rgbText, rgbOldBack, rgbOldText;
short nShift = 1; /* to shift directories right in lst2 */
BOOL bSel;
int BltItem;
*szText = 0;
if ( lpdis->CtlID != IDD_DRIVEID )
return;
hdcList = lpdis->hDC;
SendDlgItemMessage( hDlg, lpdis->CtlID, CB_GETLBTEXT,
(WPARAM)lpdis->itemID, (LPARAM)(LPSTR)szText );
// This piece of code will cause the default optimization to truncate
// the rest of the routine.
//
// if (*szText == 0) {
// /* if empty listing */
// DefWindowProc( hDlg, WM_DRAWITEM, wParam, (LPARAM)lpdis );
// return;
// }
AnsiLower((LPSTR) szText);
nHeight = dyItem;
CopyRect((LPRECT)&rectHilite, (LPRECT) &lpdis->rcItem);
rectHilite.bottom = rectHilite.top + nHeight;
/* Under Win 3.0 in a combobox, if it's in the listbox, it only has to
/* be selected because focus isn't noted properly.
*/
if ((wWinVer < 0x030A) && (lpdis->CtlType == ODT_COMBOBOX) &&
(lpdis->rcItem.left == 0) && (lpdis->itemState & ODS_SELECTED))
lpdis->itemState |= ODS_FOCUS;
/* Careful checking of bSel is needed here. Since the file listbox (lst1)
* can allow multiselect, only ODS_SELECTED needs to be set. But for the
* directory listbox (lst2), ODS_FOCUS also needs to be set.
* 03 September 1991 Clark Cyr
*/
bSel = (lpdis->itemState & (ODS_SELECTED | ODS_FOCUS));
if ((bSel & ODS_SELECTED) || (bSel & ODS_FOCUS)) {
rgbBack = rgbHiliteColor;
rgbText = rgbHiliteText;
} else {
rgbBack = rgbWindowColor;
rgbText = rgbWindowText;
}
rgbOldBack = SetBkColor( hdcList, rgbBack );
rgbOldText = SetTextColor( hdcList, rgbText );
dxAcross = dxDirDrive / BMPHIOFFSET;
BltItem = (int)(WORD)(DWORD)SendDlgItemMessage(hDlg, IDD_DRIVEID,
CB_GETITEMDATA, (WPARAM) lpdis->itemID, 0);
if ( bSel & ODS_SELECTED )
BltItem += BMPHIOFFSET;
/* Draw the name */
ExtTextOut( hdcList, rectHilite.left+dxSpace+dxAcross + dxSpace * nShift,
rectHilite.top + (nHeight - dyText)/2, ETO_OPAQUE | ETO_CLIPPED,
(LPRECT) &rectHilite, (LPSTR) szText, lstrlen((LPSTR) szText),
NULL );
BitBlt(hdcList, rectHilite.left+dxSpace*nShift,
rectHilite.top + (dyItem - dyDirDrive)/2,
dxAcross, dyDirDrive, hdcMemory, BltItem*dxAcross, 0, SRCCOPY);
SetTextColor( hdcList, rgbOldText );
SetBkColor( hdcList, rgbOldBack );
if ( lpdis->itemState & ODS_FOCUS )
DrawFocusRect( hdcList, (LPRECT)&lpdis->rcItem );
return;
}
/**************************************************************************/
/*** ***/
/*** vDeleteDirDriveBitmap ***/
/*** ***/
/**************************************************************************/
void vDeleteDirDriveBitmap()
{
SelectObject( hdcMemory, hbmpOrigMemBmp );
if ( hbmpDirDrive != (HANDLE)NULL ) {
DeleteObject( hbmpDirDrive );
hbmpDirDrive = (HANDLE)NULL;
}
}
/**************************************************************************/
/*** ***/
/*** LoadDirDriveBitmap ***/
/*** ***/
/*** Creates the drive/directory bitmap. If an appropriate bitmap ***/
/*** already exists, it just returns immediately. Otherwise, it ***/
/*** loads the bitmap and creates a larger bitmap with both regular ***/
/*** and highlight colors. ***/
/*** ***/
/**************************************************************************/
BOOL LoadDirDriveBitmap()
{
BITMAP bmp;
HANDLE hbmp, hbmpOrig;
HDC hdcTemp;
BOOL bWorked = FALSE;
if ((hbmpDirDrive != (HANDLE)NULL) &&
(rgbWindowColor == rgbDDWindow) && (rgbHiliteColor == rgbDDHilite))
if ( SelectObject( hdcMemory, hbmpDirDrive ) )
return(TRUE);
vDeleteDirDriveBitmap();
rgbDDWindow = rgbWindowColor;
rgbDDHilite = rgbHiliteColor;
if ( !(hdcTemp = CreateCompatibleDC(hdcMemory)) )
goto LoadExit;
if ( !(hbmp = LoadAlterBitmap(IDS_DRVBMP, rgbSolidBlue, rgbWindowColor)))
goto DeleteTempDC;
GetObject( hbmp, sizeof(BITMAP), (LPSTR) &bmp );
dyDirDrive = bmp.bmHeight;
dxDirDrive = bmp.bmWidth;
hbmpOrig = SelectObject( hdcTemp, hbmp );
hbmpDirDrive = CreateDiscardableBitmap( hdcTemp, dxDirDrive*2, dyDirDrive );
if ( !hbmpDirDrive )
goto DeleteTempBmp;
if ( !SelectObject(hdcMemory, hbmpDirDrive) ) {
vDeleteDirDriveBitmap();
goto DeleteTempBmp;
}
BitBlt( hdcMemory, 0, 0, dxDirDrive, dyDirDrive, hdcTemp, 0, 0, SRCCOPY );
SelectObject( hdcTemp, hbmpOrig );
DeleteObject( hbmp );
if ( !(hbmp = LoadAlterBitmap(IDS_DRVBMP, rgbSolidBlue, rgbHiliteColor)) )
goto DeleteTempDC;
hbmpOrig = SelectObject( hdcTemp, hbmp );
BitBlt( hdcMemory, dxDirDrive, 0, dxDirDrive, dyDirDrive,
hdcTemp, 0, 0, SRCCOPY );
SelectObject( hdcTemp, hbmpOrig );
MySetObjectOwner( hbmpDirDrive );
bWorked = TRUE;
DeleteTempBmp:
DeleteObject( hbmp );
DeleteTempDC:
DeleteDC( hdcTemp );
LoadExit:
return bWorked;
}
/**************************************************************************/
/*** ***/
/*** LoadAlterBitmap ***/
/*** ***/
/*** Loads a bitmap given its name and gives all the pixels that are ***/
/*** a certain color a new color. ***/
/*** ***/
/**************************************************************************/
HBITMAP LoadAlterBitmap(int id, DWORD rgbReplace, DWORD rgbInstead)
{
LPBITMAPINFOHEADER qbihInfo;
HDC hdcScreen;
BOOL fFound;
HANDLE hresLoad;
HANDLE hres;
DWORD FAR * qlng;
LPBYTE qbBits;
HANDLE hbmp;
hresLoad = FindResource( hInst, MAKEINTRESOURCE(id), RT_BITMAP );
if ( hresLoad == (HANDLE)NULL )
return (HANDLE)NULL;
hres = LoadResource( hInst, hresLoad );
if ( hres == (HANDLE)NULL )
return (HANDLE)NULL;
rgbReplace = RgbInvertRgb( rgbReplace );
rgbInstead = RgbInvertRgb( rgbInstead );
qbihInfo = (LPBITMAPINFOHEADER)LockResource( hres );
qlng = (LPLONG)((LPSTR)(qbihInfo) + qbihInfo->biSize);
fFound = FALSE;
while ( !fFound ) {
if (*qlng == rgbReplace) {
fFound = TRUE;
*qlng = (LONG) rgbInstead;
}
qlng++;
}
UnlockResource( hres );
qbihInfo = (LPBITMAPINFOHEADER)LockResource( hres );
/* First skip over the header structure */
qbBits = (LPBYTE)(qbihInfo + 1);
/* Skip the color table entries, if any */
qbBits += (1 << (qbihInfo->biBitCount)) * sizeof(RGBQUAD);
/* Create a color bitmap compatible with the display device */
hdcScreen = GetDC( (HANDLE)NULL );
if ( hdcScreen != (HANDLE)NULL ) {
hbmp = CreateDIBitmap( hdcScreen, qbihInfo, (LONG)CBM_INIT,
qbBits, (LPBITMAPINFO) qbihInfo, DIB_RGB_COLORS );
ReleaseDC( (HANDLE)NULL, hdcScreen );
}
UnlockResource( hres );
FreeResource( hres );
return( hbmp );
}
/**************************************************************************/
/*** ***/
/*** MySetObjectOwner ***/
/*** ***/
/*** Call SetObjectOwner in GDI, eliminating "<Object> not released" ***/
/*** error messages when an app terminates. ***/
/*** ***/
/**************************************************************************/
void MySetObjectOwner( HANDLE hObject )
{
VOID (FAR PASCAL *lpSetObjOwner)(HANDLE, HANDLE);
HMODULE hMod;
if ( wWinVer >= 0x030A ) {
if ( hMod = GetModuleHandle("GDI") )
if ( lpSetObjOwner = GetProcAddress(hMod, MAKEINTRESOURCE(461)) )
(lpSetObjOwner)( hObject, hInst );
}
}
/**************************************************************************/
/*** ***/
/*** RgbInvertRgb ***/
/*** ***/
/*** To reverse the byte order of the RGB value (for file format) ***/
/*** Return new color value (RGB to BGR) ***/
/*** ***/
/**************************************************************************/
LONG RgbInvertRgb( LONG rgbOld )
{
return((LONG) RGB(GetBValue(rgbOld), GetGValue(rgbOld), GetRValue(rgbOld)));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -