Print button in PrintPreview dialog doesn't work - mfc

After pressing the print button in PrintPreview dialog, nothing comes out.
I think that Print dialog should come out after pressing the print button in PrintPreview dialog, but it doesn't.
It just goes back to the main screen.
P.S.
It's not the functions which were already made when I started the project.
I added this functions manually, because I used another view which is derived from CScrollView, and the original view (CMyView) isn't used.
Here's the code:
void SignalView::OnFilePrintPreview()
{
PRINTDLG printDlg = { 0 };
printDlg.lStructSize = sizeof(PRINTDLG);
if (AfxGetApp()->GetPrinterDeviceDefaults(&printDlg))
{
if (printDlg.hDevMode)
{
DEVMODE *dm = (DEVMODE*)::GlobalLock(printDlg.hDevMode);
if (dm)
{
dm->dmFields |= DM_ORIENTATION;
dm->dmOrientation = DMORIENT_LANDSCAPE;
::GlobalUnlock(printDlg.hDevMode);
}
}
}
CScrollView::OnFilePrintPreview();
}
BOOL SignalView::OnPreparePrinting(CPrintInfo* pInfo)
{
__try {
pInfo->SetMinPage(1);
pInfo->SetMaxPage(1);
// pInfo->m_bPreview = TRUE;
return DoPreparePrinting(pInfo);
}__except (GetExceptionCode()==EXCEPTION_ACCESS_VIOLATION){
AfxMessageBox(_T("Printer Error!"));
return FALSE; // Fail!
}
}
void SignalView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
}
void SignalView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
}
Is there something that I missed?

Related

How to create a CDockablePane in a CFrameWnd with C++ in MFC

At first I called the Create method of the CFrameWnd within another class.
Then I continued with the Create method of CDockablePane with the FrameWnd as the pParentWnd parameter.
The second Create was not successful, an assertion occured in the following code:
void CMFCDragFrameImpl::Init(CWnd* pDraggedWnd)
{
ASSERT_VALID(pDraggedWnd);
m_pDraggedWnd = pDraggedWnd;
CWnd* pDockSite = NULL;
if (m_pDraggedWnd->IsKindOf(RUNTIME_CLASS(CPaneFrameWnd)))
{
CPaneFrameWnd* pMiniFrame = DYNAMIC_DOWNCAST(CPaneFrameWnd, m_pDraggedWnd);
pDockSite = pMiniFrame->GetParent();
}
else if (m_pDraggedWnd->IsKindOf(RUNTIME_CLASS(CPane)))
{
CPane* pBar = DYNAMIC_DOWNCAST(CPane, m_pDraggedWnd);
ASSERT_VALID(pBar);
CPaneFrameWnd* pParentMiniFrame = pBar->GetParentMiniFrame();
if (pParentMiniFrame != NULL)
{
pDockSite = pParentMiniFrame->GetParent();
}
else
{
pDockSite = pBar->GetDockSiteFrameWnd();
}
}
m_pDockManager = afxGlobalUtils.GetDockingManager(pDockSite);
if (afxGlobalUtils.m_bDialogApp)
{
return;
}
ENSURE(m_pDockManager != NULL); <-----------------------
}
Somehow a docking manager seems to be missing. Is it possible that CFrameWnd is not suitable for CDockablePane? Or the docking manager needs to be initialized?
Thanks for your help (code snippets are welcome)!
To add a dockable pane to your project, the first step is to derive a new class from CDockablePane and you must add two message handlers for OnCreate and OnSize, and add a member child window as the main content. Your simple CTreePane class should look like this:
class CTreePane : public CDockablePane
{
DECLARE_MESSAGE_MAP()
DECLARE_DYNAMIC(CTreePane)
protected:
afx_msg int OnCreate(LPCREATESTRUCT lp);
afx_msg void OnSize(UINT nType,int cx,int cy);
private:
CTreeCtrl m_wndTree ;
};
int CTreePane::OnCreate(LPCREATESTRUCT lp)
{
if(CDockablePane::OnCreate(lp)==-1)
return -1;
DWORD style = TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT|
WS_CHILD|WS_VISIBLE|TVS_SHOWSELALWAYS | TVS_FULLROWSELECT;
CRect dump(0,0,0,0) ;
if(!m_wndTree.Create(style,dump,this,IDC_TREECTRL))
return -1;
return 0;
}
In the OnSize handler, you should size your control to fill the entire dockable pane client area.
void CTreePane::OnSize(UINT nType,int cx,int cy)
{
CDockablePane::OnSize(nType,cx,cy);
m_wndTree.SetWindowPos(NULL,0,0,cx,cy, SWP_NOACTIVATE|SWP_NOZORDER);
}
To support a dockable pane in your frame, you must first derive from the Ex family of frames (CFrameWndEx, CMDIFrameWndEx, ..) and in the OnCreate handler, you should initialize the docking manager by setting the allowable docking area, general properties, smart docking mode, …etc.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
CDockingManager::SetDockingMode(DT_SMART);
EnableAutoHidePanes(CBRS_ALIGN_ANY);
...
}void CMainFrame::OnTreePane()
{
if(m_treePane && m_treePane->GetSafeHwnd())
{
m_treePane->ShowPane(TRUE,FALSE,TRUE);
return ;
}
m_treePane = new CTreePane;
UINT style = WS_CHILD | CBRS_RIGHT |CBRS_FLOAT_MULTI;
CString strTitle = _T("Tree Pane");
if (!m_treePane->Create(strTitle, this,
CRect(0, 0, 200, 400),TRUE,IDC_TREE_PANE, style))
{
delete m_treePane;
m_treePane = NULL ;
return ;
}
m_treePane->EnableDocking(CBRS_ALIGN_ANY);
DockPane((CBasePane*)m_treePane,AFX_IDW_DOCKBAR_LEFT);
m_treePane->ShowPane(TRUE,FALSE,TRUE);
RecalcLayout();
}

Exit and Play button don't register well

So been trying my exit and play button work but they do not react the way I want them too for some strange reason. When I change one to else if and if only statement they either both exit or change them again and both start the game. They act like they are the same button and not individuals despite how they are selected and pressed.
Here is my header file:
#pragma once
#include <memory>
#include "State.h"
#include "Game.h"
#include <SFML/Graphics.hpp>
class MainMenu : public Engine::State
{
public:
enum behavior
{
HOVERED, NORMAL
};
private:
std::shared_ptr<Context> context;
sf::Text gameTitle;
sf::Text playButton;
sf::Text exitButton;
void hover(sf::RenderWindow& window, sf::Event event);
//checking certain conditions if it is true or false
bool isPlayButtonSelected;
bool isPlayButtonPressed;
bool isExitButtonSelected;
bool isExitButtonPressed;
public:
MainMenu(std::shared_ptr<Context>& context);
~MainMenu();
void Init() override;
void ProcessInput() override;
void Update(sf::Time deltaTime) override;
void Draw() override;
};
Here is the cpp file:
#include "MainMenu.h"
#include "GamePlay.h"
MainMenu::MainMenu(std::shared_ptr<Context> &context) : context(context),
isPlayButtonSelected(true), isPlayButtonPressed(false), isExitButtonPressed(false),
isExitButtonSelected(false)
{
}
MainMenu::~MainMenu()
{
}
void MainMenu::Init()
{
//our assets being put here that we stored and implement it
context -> assets ->AddFont(MainFont, "Assets/Asdonuts.ttf");
//Titlle screen name of the game code
gameTitle.setFont(context->assets->GetFont(MainFont));
gameTitle.setString("Final Game Project");
gameTitle.setOrigin(gameTitle.getGlobalBounds().width/2,
gameTitle.getGlobalBounds().height/2);
gameTitle.setPosition(context->window->getSize().x/3.5,
context->window->getSize().y/2 - 450.f);
gameTitle.setCharacterSize(150);
//This is the code for the play button
playButton.setFont(context->assets->GetFont(MainFont));
playButton.setString("Start");
playButton.setOrigin(playButton.getGlobalBounds().width/2,
playButton.getGlobalBounds().height/2);
playButton.setPosition(context->window->getSize().x/2,
context->window->getSize().y/2 - 50.f);
playButton.setCharacterSize(70);
//This is the code for the exit button
exitButton.setFont(context->assets->GetFont(MainFont));
exitButton.setString("Exit");
exitButton.setOrigin(exitButton.getGlobalBounds().width/2,
exitButton.getGlobalBounds().height/2);
exitButton.setPosition(context->window->getSize().x/2,
context->window->getSize().y/2 + 50.f);
exitButton.setCharacterSize(70);
}
//this function is when the screen is running and reads user input when pressing
//the buttons and things that happend when they press certain buttons
//while also keeping the window open till they choose to close it on the x button
//on the top right corner
void MainMenu::ProcessInput()
{
sf::Event event;
while(context->window->pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
context->window->close();
}
else if(event.type == sf::Event::KeyPressed)
{
switch(event.key.code)
{
case sf::Keyboard::Up:
{
if(!isPlayButtonSelected)
{
isPlayButtonSelected = true;
isExitButtonSelected = false;
}
break;
}
case sf::Keyboard::W:
{
if(!isPlayButtonSelected)
{
isPlayButtonSelected = true;
isExitButtonSelected = false;
}
break;
}
case sf::Keyboard::Down:
{
if(!isExitButtonSelected)
{
isPlayButtonSelected = false;
isExitButtonSelected = true;
}
break;
}
case sf::Keyboard::S:
{
if(!isExitButtonSelected)
{
isPlayButtonSelected = false;
isExitButtonSelected = true;
}
break;
}
case sf::Keyboard::Enter:
{
isPlayButtonPressed = false;
isExitButtonPressed = false;
if(!isPlayButtonPressed)
{
isPlayButtonPressed = true;
}
else if(!isExitButtonPressed)
{
isExitButtonPressed = true;
}
break;
}
default:
{
break;
}
}
}
}
}
void MainMenu::Update(sf::Time deltaTime)
{
//conditions for the menu fonts and all
//so like we know who is highlighted and not highlighted for the user to understand
//what is going on and what selection they are hovering on
if(isPlayButtonSelected)
{
playButton.setFillColor(sf::Color::Blue);
exitButton.setFillColor(sf::Color::White);
}
else
{
exitButton.setFillColor(sf::Color::Blue);
playButton.setFillColor(sf::Color::White);
}
//important thing for our main menu
//if Play button is pressed the game starts
if(isPlayButtonPressed)
{
context->states->Add(std::make_unique<GamePlay>(context), true);
}
//if the exit button is pressed, the game SHOULD exit
else if(isExitButtonPressed)
{
context->window->close();
}
}
void MainMenu::Draw()
{
//draw everything that needs to be display in the main menu
context->window->clear(sf::Color(53, 189, 164));
context->window->draw(gameTitle);
context->window->draw(playButton);
context->window->draw(exitButton);
context->window->display();
}
So an example what I mean is this one both buttons start the game but if I change it to this:
case sf::Keyboard::Enter:
{
isPlayButtonPressed = false;
isExitButtonPressed = false;
if(!isPlayButtonPressed)
{
isPlayButtonPressed = true;
}
if(!isExitButtonPressed)
{
isExitButtonPressed = true;
}
break;
}
if(isPlayButtonPressed)
{
context->states->Add(std::make_unique<GamePlay>(context), true);
}
//if the exit button is pressed, the game SHOULD exit
if(isExitButtonPressed)
{
context->window->close();
}
They will both exit and not start the game. I have been messing around one if and the other else or both as if statements. Despite the changes and testing none of the buttons act individually and act how they are supposed to act. So curious how to fix this issue?
Unsure if I should provide all my headers and cpp files for more context.
I am not really sure if I understand well your problem, but in your example it seems like isExitButtonPressed is always true at the end.
You're setting it to false at the begining and then setting it to true in the if statement which has always a fulfilled condition giving the fact that you set isExitButtonPressed to false beforehand !

i want prevent double clicked event at tree control in MFC?

i have implemented multi selection when LButtonDown from tree control in MFC
but when i do fast click repeatedly Mouse LButtonDown then a problem arises.
i thinks this problem is occoured by double clicked event when i clicked fast
repeadtly.
i want to acquired click event only except double clickevent.
importance is must be solved this problem in only LBUTTONDOWN event and LButtonClick event.
please help me. ~
my english writing is so badddest. sorry.
below is my source's part.
void CFileTreeCtrl::OnLButtonDown(UINT nFlags , CPoint point)
{
//LRESULT *pResult = 0;
GetCursorPos(&point);
::ScreenToClient(this->m_hWnd, &point);
HTREEITEM hItem = this->HitTest(point, &nFlags);
// if items is exist and event is occured
if (hItem != NULL && (nFlags & TVHT_ONITEMSTATEICON) != 0)
{
// if items is checked
if (this->GetCheck(hItem))
{
UnCheckChildItems(hItem);
}
// items is not checked
else
{
CheckChildItems(hItem);
}
}
CDragDropTreeCtrl::OnLButtonDown(nFlags, point);
}
//=========================================================
// checked all child items
//=========================================================
void CFileTreeCtrl::CheckChildItems(HTREEITEM hItem)
{
HTREEITEM hChildItem = this->GetChildItem(hItem);
while (hChildItem != NULL)
{
this->SetCheck(hChildItem, TRUE);
if (this->ItemHasChildren(hChildItem))
{
CheckChildItems(hChildItem);
}
hChildItem = this->GetNextItem(hChildItem, TVGN_NEXT);
}
}
//=========================================================
// Uncheck all child items.
//=========================================================
void CFileTreeCtrl::UnCheckChildItems(HTREEITEM hItem)
{
HTREEITEM hChildItem = this->GetChildItem(hItem);
while (hChildItem != NULL)
{
this->SetCheck(hChildItem, FALSE);
if (this->ItemHasChildren(hChildItem))
{
UnCheckChildItems(hChildItem);
}
hChildItem = this->GetNextItem(hChildItem, TVGN_NEXT);
}
}

How to display GIF as splash in visual studio c++

I am trying to display a GIF picture as splash as starting of my small program in visual studio. I am really getting crazy. I looked it is possible in Qt IDE but I really need it in visual studio because my other code works only with visual studio. And yes I tried to convert my code for Qt giving me too many errors.
I have seen this post.
I am using GDI+ but still dunno how to simply display it instead of play and stop. It's okay even instead of splash to display a small form that plays the GIF file, can you guys give me a small code snippet in how to do it in c++?
Thanks.
Here is an MFC window class that implements a splash screen using GDI Plus for displaying an (animated) GIF.
I've encapsulated everything inside a header file to simplify using it with your project. Save it as an .h file (maybe "SplashWnd.h"), then include it wherever you want to set up the splash. You app's InitInstance might be a good place to add it - something like this line (before any DoModal calls):
SplashWnd splash(_T("Filname.gif"));
The constructor can also take parameters for controlling the delay before auto-closing, and also specifying a function to call when the splash is closed.
The splash window has no border or caption - it appears only as the loaded image, floating on top of any other windows. Its icon doesn't appear in the taskbar, and will close when its timeout expires, or the user clicks the window or presses a key.
#pragma once
#include <functional>
#include <afxwin.h>
#include <gdiplus.h>
#pragma comment(lib,"gdiplus.lib")
inline void ManageGdiPlusInit(bool release=false) {
static int refcount = 0;
static ULONG_PTR token;
if(release) {
if(--refcount == 0) {
Gdiplus::GdiplusShutdown(token);
}
} else if(++refcount == 1) {
Gdiplus::GdiplusStartupInput startup_input;
Gdiplus::GdiplusStartup(&token, &startup_input, 0);
} }
inline void GdiPlusInit() { ManageGdiPlusInit(false); }
inline void GdiPlusRelease() { ManageGdiPlusInit(true); }
namespace {
class SplashWnd : public CWnd {
protected:
static CString WindowClass() {
static CString name;
if(name.IsEmpty()) {
name = AfxRegisterWndClass(CS_DROPSHADOW, 0, (HBRUSH)GetStockObject(GRAY_BRUSH), 0);
}
return name;
}
Gdiplus::Image *m_pImage;
UINT m_FrameCount;
unsigned char *m_FrameDelayData;
const UINT *m_FrameDelays;
UINT m_CurFrameIndex;
UINT m_AnimationTimerId;
UINT m_ExpireTimerId;
CRect m_WindowRect;
std::function<void()> m_DismissCallback;
DECLARE_MESSAGE_MAP()
afx_msg void OnLButtonDown(UINT nFlags, CPoint point) {
DestroyWindow();
}
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) {
DestroyWindow();
}
afx_msg void OnDestroy() {
if(m_AnimationTimerId != UINT(-1)) {
KillTimer(m_AnimationTimerId);
}
if(m_ExpireTimerId != UINT(-1)) {
KillTimer(m_ExpireTimerId);
}
if(m_DismissCallback) {
m_DismissCallback();
}
CWnd::OnDestroy();
}
afx_msg void OnTimer(UINT nIDEvent) {
if(nIDEvent == m_AnimationTimerId) {
if(++m_CurFrameIndex >= m_FrameCount) {
m_CurFrameIndex = 0;
}
DrawCurFrame();
KillTimer(m_AnimationTimerId);
m_AnimationTimerId = SetTimer(1, m_FrameDelays[m_CurFrameIndex], 0);
return;
}
if(nIDEvent == m_ExpireTimerId) {
DestroyWindow();
return;
} }
void PostNcDestroy() {
if(m_DeleteSelf) {
delete this;
}
}
void DrawCurFrame() {
Gdiplus::Graphics g(m_hWnd);
GUID dim_select_id = Gdiplus::FrameDimensionTime;
m_pImage->SelectActiveFrame(&dim_select_id, m_CurFrameIndex);
g.DrawImage(m_pImage, 0, 0, m_WindowRect.Width(), m_WindowRect.Height());
}
public:
// set m_DeleteSelf to true if a SplashWnd is created with new, and you want it to
// auto-delete itself when the window expires or is dismissed.
bool m_DeleteSelf;
// file_path the gif file path
// ExpireMs the time, in milliseconds until the window automatically closes itself
// WidthFactor the fraction of the width of the primary display to use as the splash screen's width
// HeightFactor the fraction of the height of the primary display to use as the height
// If WidthFactor or HeightFactor are 0, the original image aspect ratio is preserved
// If both are 0, the original image size, in pixels is used
SplashWnd(CString file_path, DWORD ExpireMs=2000, double WidthFactor=0.4, double HeightFactor=0) {
GdiPlusInit();
m_pImage = new Gdiplus::Image(file_path);
// Set up an array of frame times for animated images
UINT dimension_count = m_pImage->GetFrameDimensionsCount();
GUID dimension_id;
m_pImage->GetFrameDimensionsList(&dimension_id, 1);
m_FrameCount = m_pImage->GetFrameCount(&dimension_id);
UINT frame_delay_size = m_pImage->GetPropertyItemSize(PropertyTagFrameDelay);
m_FrameDelayData = new unsigned char[frame_delay_size];
Gdiplus::PropertyItem* frame_delay_item = reinterpret_cast<Gdiplus::PropertyItem*>(m_FrameDelayData);
m_pImage->GetPropertyItem(PropertyTagFrameDelay, frame_delay_size, frame_delay_item);
m_FrameDelays = reinterpret_cast<const UINT*>(frame_delay_item->value);
// Figure out the size and location of the splash window
int primary_width = GetSystemMetrics(SM_CXFULLSCREEN);
int primary_height = GetSystemMetrics(SM_CYFULLSCREEN);
int splash_width = int(primary_width * WidthFactor);
int splash_height = int(primary_height * HeightFactor);
if(splash_width == 0) {
if(splash_height == 0) {
splash_width = m_pImage->GetWidth();
splash_height = m_pImage->GetHeight();
} else {
splash_width = primary_width * splash_height / primary_height;
}
} else if(splash_height == 0) {
splash_height = primary_height * splash_width / primary_width;
}
int l = (primary_width - splash_width) / 2;
int t = (primary_height - splash_height) / 2;
int r = l + splash_width;
int b = t + splash_height;
m_WindowRect.SetRect(
(primary_width - splash_width) / 2,
(primary_height - splash_height) / 2,
(primary_width + splash_width) / 2,
(primary_height + splash_height) / 2);
// WS_EX_TOPMOST makes the window cover up other, regular windows
// WS_EX_TOOLWINDOW prevents an icon for this window in the taskbar
// WS_POPUP prevents caption and border from being drawn
CreateEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW, WindowClass(), _T("Splash"), WS_VISIBLE | WS_POPUP, m_WindowRect, 0, 0);
// Show the first frame
m_CurFrameIndex = 0;
DrawCurFrame();
// Set up the frame-flipping animation timer
m_ExpireTimerId = m_AnimationTimerId = UINT(-1);
if(m_FrameCount > 1) {
m_AnimationTimerId = SetTimer(1, m_FrameDelays[m_CurFrameIndex], 0);
}
// Set up the expiration timer
if(ExpireMs != INFINITE) {
m_ExpireTimerId = SetTimer(2, ExpireMs, 0);
}
m_DeleteSelf = false;
}
// Constructor which takes a callback function which will be called when the splash window closes
template <typename F>
SplashWnd(CString file_path, DWORD ExpireMs, double WidthFactor, double HeightFactor, F DismissCallback)
: SplashWnd(file_path, ExpireMs, WidthFactor, HeightFactor)
{
m_DismissCallback = DismissCallback;
}
~SplashWnd() {
delete [] m_FrameDelayData;
delete m_pImage;
GdiPlusRelease();
}
};
// Message map, usually in an implementation file, but here encapsulated inside the header
// using an anonymous namespace to prevent possible ODR problems.
BEGIN_MESSAGE_MAP(SplashWnd, CWnd)
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_TIMER()
ON_WM_DESTROY()
END_MESSAGE_MAP()
}

How to change the state of button to clicked in cocos2d-x

I am pretty new to cocos2d-x.I have created a button and i wanted to change the state of the button when i tap the button . i am having trouble changing the state from play to pause similar to a music player.Below is the code.
void Gallery::buttonUI(Size visibleSize,Vec2 origin)
{
button = Button::create("play.png");
//button->loadTextures("pause.png","play.png","pause.png");
button->setPosition(Point((visibleSize.width/2)+origin.x,(visibleSize.height/2)+origin.y-80));
button->setContentSize(Size(100.0f, button->getVirtualRendererSize().height));
button->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type){
switch (type)
{
case Widget::TouchEventType::BEGAN:
break;
case Widget::TouchEventType::ENDED:
CCLOG("Characters: %c %c", 'a', 65);
if (!flag)
Gallery::pauseSong();
else
Gallery::resumeSong();
break;
default:
break;
}
});
this->addChild(button);
}
void Gallery::playSong()
{
CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("1.mp3");
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("1.mp3");
flag = false;
}
void Gallery::pauseSong()
{
CocosDenshion::SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
flag = true;
}
void Gallery::resumeSong()
{
CocosDenshion::SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
flag = false;
}
I don’t know of such methods for the ui::Button. But I don’t see the use of specific ui::Button items (capinsets, different methods for different touch events etc.) in your method also.
So, I think the MenuItemImage is better in your case:
bool flag = true;
MenuItemImage *button = MenuItemImage::create("play.png", "play_pressed.png", CC_CALLBACK_0(Gallery::playSong, this));
button->setPosition(Vec2((visibleSize.width/2)+origin.x,(visibleSize.height/2)+origin.y-80)); // better is use Vec2, Point can be ambiguous
Menu* menu = Menu::create(button, NULL); // add created button on Menu
menu ->setPosition(0,0);
this->addChild(menu);
And then set the images in handler pressing:
void Gallery::playSong()
{
if(flag)
{
// preload better move to AppDelegate.cpp
// CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("1.mp3");
flag = false;
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("1.mp3");
button->setNormalImage(Sprite::create(“pause.png”));
button->setSelectedImage(Sprite::create(“pause_pressed.png”)); // if you use selected image
}
else
{
flag = true;
CocosDenshion::SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
button->setNormalImage(Sprite::create(“play.png”));
button->setSelectedImage(Sprite::create(“play_pressed.png”));
}
}
In cocos 3.x use property: setHighlighted(bool)
Example:
When press a key: button->setHighlighted(true);
When release the key:
button->setHighlighted(false);