void CColorButtonCtrl::OnMouseMove(UINT nFlags, CPoint point) { static BOOL bHaveDrawnUp = FALSE; static BOOL bHaveDrawnDown = FALSE; CDC* pDC = GetDC(); // get button rect CRect rc; GetClientRect(&rc); // check whether the button is down if (m_bDown) { // check whether mouse pointer is over button if (rc.PtInRect(point)) { bHaveDrawnUp = FALSE; if (!bHaveDrawnDown) { DrawButtonDown(pDC, rc); bHaveDrawnDown = TRUE; } } else { bHaveDrawnDown = FALSE; if (!bHaveDrawnUp) { DrawButtonUp(pDC, rc); bHaveDrawnUp = TRUE; } } } else { bHaveDrawnUp = FALSE; bHaveDrawnDown = FALSE; } ReleaseDC(pDC); }
void CColorButtonCtrl::OnLButtonDown(UINT nFlags, CPoint point) { // call the base class handler COleControl::OnLButtonDown(nFlags, point); CRect rc; CDC* pDC = GetDC(); // set down flag m_bDown = TRUE; // set mouse capture SetCapture(); GetClientRect(&rc); DrawButtonDown(pDC, rc); ReleaseDC(pDC); }
/* * UpdateMenu: * The routine which determines which menu buttons are being pressed and does * other tidbits of crap */ void UpdateMenu(void) { RECT SrcRect, DesRect; // Source and Destination rectangles HRESULT ret; // Set the source and destination rectangles SetRect(&SrcRect, 0, 0, 640, 480); SetRect(&DesRect, 0, 0, 640, 480); // Blit the lpDDSMenu surface (Menu Graphic) to the back buffer lpDDSBack->Blt(&DesRect, lpDDSMenu, &SrcRect, DDBLT_WAIT, NULL); // If the left mouse button is pressed if (MouseLB) { // Determine what was clicked on if (XYInRect(MouseX, MouseY, &StartGameRect)) { // The start game button was pressed // Game Start Code Here DrawButtonDown(0); // draw the button in it's down (highlighted) position DrawCursor(MouseX, MouseY); // Draw the mouse Cursor ret = DDFlip(); // flip to the primary surface if (ret == DDERR_SURFACELOST) { RestoreGraphics(); } DODPlayClickSound(); // play the clicking sound FadeToBlack(); // Fade the screen to black MidiStop(); // Stop the midi KillMenuGFX(); // release the menu graphic surface InitWorld(); // initialize the world LoadGameGFX(); // Load the games needed graphics Game_State = DOD_PLAYING; // set the game state to DOD_PLAYING } else if (XYInRect(MouseX, MouseY, &LoadGameRect)) { // The load game button was pressed // Load Game Code Here DrawButtonDown(1); // draw the button in it's down (highlighted) position DrawCursor(MouseX, MouseY); // Draw the mouse Cursor ret = DDFlip(); // flip to the primary surface if (ret == DDERR_SURFACELOST) { RestoreGraphics(); } DODPlayClickSound(); // play the clicking sound } else if (XYInRect(MouseX, MouseY, &OptionsRect)) { // The options button was pressed // Options Code Here DrawButtonDown(2); // draw the button in it's down (highlighted) position DrawCursor(MouseX, MouseY); // Draw the mouse Cursor ret = DDFlip(); // flip to the primary surface if (ret == DDERR_SURFACELOST) { RestoreGraphics(); } DODPlayClickSound(); // play the clicking sound } else if (XYInRect(MouseX, MouseY, &CreditsRect)) { // The credits button was pressed // Credits Code Here DrawButtonDown(3); // draw the button in it's down (highlighted) position DrawCursor(MouseX, MouseY); // Draw the mouse Cursor ret = DDFlip(); // flip to the primary surface if (ret == DDERR_SURFACELOST) { RestoreGraphics(); } DODPlayClickSound(); // play the clicking sound FadeToBlack(); // fade the menu to black MidiStop(); // stop the midi MidiPlay(".\\Music\\credits.mid", TRUE); // play the credits music Game_State = DOD_CREDITS; // set the Game_State into Credits mode } else if (XYInRect(MouseX, MouseY, &ExitRect)) { // The exit button was pressed // Exit Code Here DrawButtonDown(4); // draw the button in it's down (highlighted) position DrawCursor(MouseX, MouseY); // Draw the mouse Cursor ret = DDFlip(); // flip to the primary surface if (ret == DDERR_SURFACELOST) { RestoreGraphics(); } DODPlayClickSound(); // play the clicking sound FadeToBlack(); // Fade to a black screen DDFillSurface(lpDDSPrimary, 0); // Fill the primary surface with black DDFillSurface(lpDDSBack, 0); // Fill the back surface with black KillMenuGFX(); // release the menu graphic surface PostMessage(main_window_handle, WM_DESTROY, 0, 0); // Post the destroy window message Game_State = DOD_NOTHING; // set the game state to nothing } else { // No buttons were pressed // Just draw the cursor, and flip DrawCursor(MouseX, MouseY); // Draw the mouse Cursor ret = DDFlip(); // flip to the primary surface if (ret == DDERR_SURFACELOST) { RestoreGraphics(); } } } else { // the mouse button wasn't pressed // just draw the cursor and flip DrawCursor(MouseX, MouseY); // Draw the mouse Cursor ret = DDFlip(); // flip to the primary surface if (ret == DDERR_SURFACELOST) { RestoreGraphics(); } } }