/*++ Copyright (c) 1992 Microsoft Corporation Module Name: control.c Abstract: This module implements the wndproc and child wndprocs for the control window in the cdplayer app. The control window consists of the LED display, and the control buttons such as play, stop, track skip, etc. It also implements support routines for these controls. Author: Rick Turner (ricktu) 04-Aug-1992 Revision History: --*/ #include #include #include #include "cdplayer.h" #include "cdwindef.h" #include "control.h" #include "toolbar.h" // // local function defs // BOOL FAR PASCAL ControlWndProc( IN HWND, IN DWORD, IN DWORD, IN LONG ); BOOL FAR PASCAL LEDWndProc( IN HWND, IN DWORD, IN DWORD, IN LONG ); // // Module globals // WNDCLASS controlwndclass,LEDwndclass; static CHAR szControlClassName[] = "CdControl"; static CHAR szLEDClassName[] = "CdLED"; HFONT hLEDFont = NULL; HBITMAP hbmCtrlBtns; // // Init routine // BOOL ControlInit( VOID ) { LOGFONT lf; gControlWnd = NULL; gLEDWnd = NULL; // // Register Control Window Proc // controlwndclass.style = CS_HREDRAW | CS_VREDRAW; controlwndclass.lpfnWndProc = (WNDPROC)ControlWndProc; controlwndclass.cbClsExtra = 0; controlwndclass.cbWndExtra = 0; controlwndclass.hInstance = (HINSTANCE)gInstance; controlwndclass.hIcon = NULL; controlwndclass.hCursor = LoadCursor( NULL, IDC_ARROW ); controlwndclass.hbrBackground = CreateSolidBrush( cdLTGRAY ); controlwndclass.lpszMenuName = NULL; controlwndclass.lpszClassName = szControlClassName; RegisterClass( (CONST WNDCLASS *)&controlwndclass ); // // Register LED Window Proc // LEDwndclass.style = CS_HREDRAW | CS_VREDRAW; LEDwndclass.lpfnWndProc = (WNDPROC)LEDWndProc; LEDwndclass.cbClsExtra = 0; LEDwndclass.cbWndExtra = 0; LEDwndclass.hInstance = (HINSTANCE)gInstance; LEDwndclass.hIcon = NULL; LEDwndclass.hCursor = LoadCursor( NULL, IDC_ARROW ); LEDwndclass.hbrBackground = CreateSolidBrush( cdBLACK ); LEDwndclass.lpszMenuName = NULL; LEDwndclass.lpszClassName = szLEDClassName; RegisterClass( (CONST WNDCLASS *)&LEDwndclass ); // // Create font to use in LED box // lf.lfHeight = -14; lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = 1000; lf.lfItalic = FALSE; lf.lfUnderline = FALSE; lf.lfStrikeOut = FALSE; lf.lfCharSet = ANSI_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN; sprintf( (LPTSTR)lf.lfFaceName, "MS Shell Dlg" ); // // Load font // hLEDFont = CreateFontIndirect( (CONST LOGFONT *)&lf ); return( TRUE ); } // // Create Routine // BOOL ControlCreate( IN INT x, IN INT y, IN INT width, IN INT height ) { BOOL result; gControlWnd = CreateWindow( szControlClassName, "CdControlWindow", WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, x, y, width, height, gMainWnd, (HMENU)ID_CHILD_CONTROL, (HINSTANCE)gInstance, NULL ); if (!gControlWnd) return FALSE; // // Create children of Control window // // // Create LED window // gLEDWnd = CreateWindow( szLEDClassName, "[00] 00:00", WS_CHILD | WS_VISIBLE, CONTROL_LED_X, CONTROL_LED_Y, CONTROL_LED_W, CONTROL_LED_H, gControlWnd, (HMENU)0, (HINSTANCE)gInstance, NULL ); if (!gLEDWnd) { DestroyWindow( gControlWnd ); gControlWnd = NULL; return FALSE; } // // Create children of Control window (Play,pause,etc) // result = CreateChildWindows(ID_CHILD_CONTROL,gControlWnd); return result; } // // Destroy routine // BOOL ControlDestroy( VOID ) { INT i; if (!gControlWnd) return TRUE; if (DestroyWindow( gControlWnd )) { gControlWnd = NULL; gLEDWnd = NULL; for (i=0; iTocIndex + FIRSTTRACK(gCurrCdrom); } else { track = 0; } // // Update the LED box? // if (Flags & DISPLAY_UPD_LED) { // // Update LED box // if (gDisplayT) { if (Flags & DISPLAY_UPD_LEADOUT_TIME) { sprintf( lpsz, TRACK_TIME_LEADOUT_FORMAT, track, CDTIME(gCurrCdrom).TrackCurMin, gszTimeSep, CDTIME(gCurrCdrom).TrackCurSec ); } else { sprintf( lpsz, TRACK_TIME_FORMAT, track, CDTIME(gCurrCdrom).TrackCurMin, gszTimeSep, CDTIME(gCurrCdrom).TrackCurSec ); } } if (gDisplayTr) { sprintf( lpsz, TRACK_REM_FORMAT, track, CDTIME(gCurrCdrom).TrackRemMin, gszTimeSep, CDTIME(gCurrCdrom).TrackRemSec ); } if (gDisplayDr) { // // Compute remaining time // mtemp = stemp = m = s =0; if (CURRTRACK(gCurrCdrom) != NULL) { for( tr=CURRTRACK(gCurrCdrom)->nextplay; tr!=NULL; tr=tr->nextplay) { FigureTrackTime( gCurrCdrom, tr->TocIndex, &mtemp, &stemp ); m+=mtemp; s+=stemp; } m+= CDTIME(gCurrCdrom).TrackRemMin; s+= CDTIME(gCurrCdrom).TrackRemSec; } m+= (s/60); s = (s % 60); CDTIME(gCurrCdrom).RemMin = m; CDTIME(gCurrCdrom).RemSec = s; sprintf( lpsz, DISC_REM_FORMAT, CDTIME(gCurrCdrom).RemMin, gszTimeSep, CDTIME(gCurrCdrom).RemSec ); } SetWindowText( gLEDWnd, lpsz ); if (gIconic) { sprintf( lpszIcon, IdStr( STR_CDPLAYER_TIME ), lpsz ); SetWindowText( gMainWnd, lpszIcon ); } } // // Update Title? // if (Flags & DISPLAY_UPD_TITLE_NAME) { ComputeDriveComboBox( ); if (gTitleNameWnd) { SetWindowText( gTitleNameWnd, (LPCSTR)TITLE(gCurrCdrom) ); } } // // Update track name? // if (Flags & DISPLAY_UPD_TRACK_NAME) if (gTrackNameWnd) { if (CURRTRACK(gCurrCdrom)!=NULL) { track = 0; for( tr=PLAYLIST(gCurrCdrom); tr!=CURRTRACK(gCurrCdrom); tr=tr->nextplay, track++ ); SendMessage( gTrackNameWnd, CB_SETCURSEL, (WPARAM)track, (LPARAM)0 ); } else { SendMessage( gTrackNameWnd, CB_SETCURSEL, (WPARAM)0, (LPARAM)0 ); } } // // Update disc time? // if (Flags & DISPLAY_UPD_DISC_TIME) if (gDiscTimeWnd) { sprintf( lpsz, IdStr( STR_TOTAL_PLAY ), //"Total Play: %02d:%02d m:s", CDTIME(gCurrCdrom).TotalMin, gszTimeSep, CDTIME(gCurrCdrom).TotalSec, gszTimeSep ); SetWindowText( gDiscTimeWnd, lpsz ); } // // Update track time? // if (Flags & DISPLAY_UPD_TRACK_TIME) if (gTrackTimeWnd) { sprintf( lpsz, IdStr( STR_TRACK_PLAY ), // "Track: %02d:%02d m:s", CDTIME(gCurrCdrom).TrackTotalMin, gszTimeSep, CDTIME(gCurrCdrom).TrackTotalSec, gszTimeSep ); SetWindowText( gTrackTimeWnd, lpsz ); } } BOOL FAR PASCAL LEDWndProc( IN HWND hwnd, IN DWORD message, IN DWORD wParam, IN LONG lParam ) /*++ Routine Description: This routine handles the WM_PAINT and WM_SETTEXT messages for the "LED" display window. Arguments: hwnd - supplies a handle to the window to draw into message - supplies the window message to the window pointed to be "hwnd" wParam - supplies the word parameter for the message in "message" lParam - supplies the long parameter for the message in "message" Return Value: Whatever our call to DefWindowProc returns for this window. --*/ { HDC hdc; PAINTSTRUCT ps; RECT r,r1; CHAR s[50]; BOOL b; switch( message ) { case WM_PAINT: // // Set up to draw into this window // hdc = BeginPaint( hwnd, &ps ); GetClientRect( hwnd, &r ); // // Draw black background // SelectObject( hdc, (HGDIOBJ)hLEDFont ); SetBkColor( hdc, cdBLACK ); SetTextColor( hdc, RGB(0x80,0x80,0x00) ); ExtTextOut( hdc, 0, 0, ETO_OPAQUE, (CONST RECT *)&r, NULL, 0, NULL ); // // The bottom and right borders are not drawn -- they are // used for alignment, so move our client rectangle in // so that it only encompasses the "drawable" area. // r.bottom--; r.right--; // // Draw Text // InflateRect( &r, -1, -1 ); CopyRect( &r1, (CONST RECT *)&r ); GetWindowText( gLEDWnd, s, 50 ); DrawText( hdc, s, strlen(s), &r1, DT_CALCRECT | DT_SINGLELINE ); OffsetRect( &r1, (((r.right-r.left)-(r1.right-r1.left))/2), (((r.bottom-r.top)-(r1.bottom-r1.top))/2)-2 ); ExtTextOut( hdc, r1.left, r1.top, ETO_OPAQUE, (CONST RECT *)&r1, s, strlen(s), NULL ); // // Draw Borders // // InflateRect( &r, 1, 1 ); SelectObject( hdc, (HGDIOBJ)hpDkGray ); MoveToEx( hdc, r.left, r.bottom, NULL ); LineTo( hdc, r.left, r.top ); LineTo( hdc, r.right, r.top ); SelectObject( hdc, (HGDIOBJ)hpWhite ); LineTo( hdc, r.right, r.bottom ); LineTo( hdc, r.left, r.bottom ); EndPaint( hwnd, (CONST PAINTSTRUCT *)&ps ); return( 0 ); break; case WM_SETTEXT: // // Set up to draw into this window // hdc = GetDC( hwnd ); GetClientRect( hwnd, &r ); // // The bottom and right borders are not drawn -- they are // used for alignment, so move our client rectangle in // so that it only encompasses the "drawable" area. // r.bottom--; r.right--; // // Draw text // InflateRect( &r, -1, -1 ); SetBkColor( hdc, cdBLACK ); SetTextColor( hdc, RGB(0x80,0x80,0x00) ); SelectObject( hdc, (HGDIOBJ)hLEDFont ); CopyRect( &r1, (CONST RECT *)&r ); DrawText( hdc, (LPSTR)lParam, strlen((LPSTR)lParam), &r1, DT_CALCRECT | DT_SINGLELINE); OffsetRect( &r1, (((r.right-r.left)-(r1.right-r1.left))/2), (((r.bottom-r.top)-(r1.bottom-r1.top))/2)-2 ); r1.right+=5; ExtTextOut( hdc, r1.left, r1.top, ETO_OPAQUE, (CONST RECT *)&r1, (LPSTR)lParam, strlen((LPSTR)lParam), NULL ); ReleaseDC( hwnd, hdc ); break; case WM_LBUTTONUP: b = gDisplayDr; gDisplayDr = gDisplayTr; gDisplayTr = gDisplayT; gDisplayT = b; CheckAndSetControls(); UpdateDisplay( DISPLAY_UPD_LED ); break; } return( DefWindowProc( hwnd, message, wParam, lParam ) ); }