void YSongListItemUI::DoPaint(HDC hDC, const RECT& rcPaint) { if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return; ASSERT(GetOwner()); // spSongInfoT spSong = thePlayCenter->GetCurrentPlayingSong(); // int nCurPlayListLocalId = thePlayCenter->GetListIndex(); spSongInfoT spSong = thePlayListMgr->GetCurSong(); spPlayListInfoT spList = thePlayListMgr->GetCurList(); if (spSong&&*spSong==*_spSongInfo&&spList&&spList->GetLocalId()==((CListUI*)GetOwner())->GetTag()) { if (SongItemExpHeight != GetFixedHeight()) { SetFixedHeight(SongItemExpHeight); _pNormalLayout->SetVisible(false); _pPushLayout->SetVisible(true); if (_spSongInfo) { _pPushDownLoad->SetVisible(!_spSongInfo->IsLocal()); _pPushShare->SetVisible(!_spSongInfo->IsLocal()); } } TListInfoUI* pInfo = m_pOwner->GetListInfo(); if(pInfo) { DWORD dwSelBkColor = ((CListUI*)GetOwner())->GetSelectedItemBkColor(); SetBkColor(dwSelBkColor); } ChangeIcon(thePlayer->GetStatus()); } else { if (IsSelected() && ((CListUI*)GetOwner())->GetSelCount() == 1) { _pPushLayout->SetVisible(false); _pNormalLayout->SetVisible(true); // _pNorButtonMenu->SetVisible(true); }else { _pPushLayout->SetVisible(false); _pNormalLayout->SetVisible(true); // _pNorButtonMenu->SetVisible(false); } if(SongItemHeight != GetFixedHeight()) SetFixedHeight(SongItemHeight); ChangeIcon(em_stop); } int nIndex = ((CListUI*)GetOwner())->GetItemIndex(this); _pNorLabelIndex->SetText(mci::ToString(nIndex+1)); _pPushLabelIndex->SetText(mci::ToString(nIndex+1)); __super::DoPaint(hDC,rcPaint); }
void YPlayListItemUI::DoPaint(HDC hDC, const RECT& rcPaint) { if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return; ASSERT(GetOwner()); if (_spList) { // int nCurPlayListLocalId = thePlayCenter->GetListIndex(); // if (_spList->GetLocalId()==nCurPlayListLocalId) spPlayListInfoT spList = thePlayListMgr->GetCurList(); if(spList&&spList->GetLocalId()==_spList->GetLocalId()) { CDuiString sText = _spList->GetName(); TCHAR szBuf[MAX_PATH] = {0}; #if defined(UNDER_WINCE) _stprintf(szBuf, _T("<f 1><c #F27D30>%s</c></f>"), sText.GetData()); #else _stprintf_s(szBuf, MAX_PATH - 1, _T("<f 1><c #F27D30>%s</c></f>"), sText.GetData()); #endif _spListName->SetText(szBuf); static CDuiString sPlayImg = _spPlayIco->GetBkImage(); static CDuiString sPauseImg = _spPlayIco->GetUserData(); int nStatus = thePlayer->GetStatus(); ChangeIcon(nStatus); // RECT rt = {15,0,0,0}; // #define BK_IMG_PLAYING _T("file='YTing/Menu/play.png' source='13,0,26,13' dest='2,8,15,21' mask='0xFF000000'") // _spListName->SetFont(1); // _spListName->SetTextPadding(rt); // _spListName->SetText(sText); // _spListName->SetBkImage(BK_IMG_PLAYING); // _spListName->ApplyAttributeList(_T("font=\"3\" bkimage=\"file='YTing/Menu/play.png' source='13,0,26,13' dest='2,8,15,21' mask='0xFF000000'\" textpadding=\"15,0,0,0\"")); } else { CDuiString sText = _spList->GetName(); TCHAR szBuf[MAX_PATH] = {0}; #if defined(UNDER_WINCE) _stprintf(szBuf, _T("<f 0>%s</f>"), sText.GetData()); #else _stprintf_s(szBuf, MAX_PATH - 1, _T("<f 0>%s</f>"), sText.GetData()); #endif _spListName->SetText(szBuf); ChangeIcon(em_stop); // RECT rt = {0,0,0,0}; // #define BK_IMG_NORMAL _T("") // _spListName->SetFont(1); // _spListName->SetTextPadding(rt); // _spListName->SetText(sText); // _spListName->SetBkImage(BK_IMG_NORMAL); } } __super::DoPaint(hDC,rcPaint); }
void BlinkIcon ( int thread_num, int duration) /* -2 = change icon (called from timer) */ /* -1 = blinking off, 0 = indefinite */ { static int state = -1; /* Current duration state */ static int icon = WORKING_ICON; /* Current icon */ /* If this is the first blinking call, start the timer */ if (state == -1) { if (duration < 0) return; AfxGetApp()->m_pMainWnd->SetTimer (363, 1000, &TimerCallback); } /* Remember how long we are to blink */ if (duration >= 0) state = duration; /* If this is the last blinking call, kill the timer */ else if (duration == -1 || (state && --state == 0)) { AfxGetApp()->m_pMainWnd->KillTimer (363); state = -1; icon = IDLE_ICON; } /* Toggle the icon */ icon = (icon == IDLE_ICON) ? WORKING_ICON : IDLE_ICON; ChangeIcon (MAIN_THREAD_NUM, icon); }
QAction* Menu::exec(const QPoint& point) { QAction* action = QMenu::exec(point); if (action == nullptr) { return nullptr; } QIcon icon = action->icon(); action->setIcon(ChangeIcon(action, icon)); return action; }
void CTrayIcon::OnTimer( UINT_PTR nIDEvent ) { if ( nIDEvent == _defFlashIconTimerID ) { if ( m_IsShowIcon ) { FlashIconData Data = DecideFlashIconData(); CIcon icon; icon.LoadIcon(Data.nIconNormal); ChangeIcon(icon); ChangeToolTip(Data.strTooltip); m_IsShowIcon = false; } else { FlashIconData Data = DecideFlashIconData(); CIcon icon; icon.LoadIcon(Data.nIconFlash); ChangeIcon(icon); ChangeToolTip(Data.strTooltip); m_IsShowIcon = true; } } else if ( nIDEvent == _defIconLeaveTimerID ) { POINT pt = {0}; RECT rc; GetCursorPos(&pt); if ( GetTrayIconRect(FindTrayWnd(), m_hNotifyWnd, &rc) == S_FALSE) { GetTrayIconRect(FindNotifyIconOverflowWindow(), m_hNotifyWnd, &rc); } if ( !PtInRect(&rc,pt) ) { BOOL b; OnTrayIconNotify(WM_TRAYICONNOTIFY, 0, WM_MOUSELEAVE, b); } } }
LRESULT CMainDlg::OnTimer(UINT message, WPARAM wparam, LPARAM /*lParam*/, BOOL& bHandled)\ { HICON icon; nIcon=++nIcon%2; if(StateIconMap.find(state)!=StateIconMap.end()) { std::vector<HICON> icons = StateIconMap[state]; if(icons[0]!=icons[1]) { ChangeIcon(icons[nIcon]); } } return 0; }
int _tmain(int argc, _TCHAR* argv[]) { bool printUsage = true; if (argc == 3) { wprintf(L"Icon File Name: %s\n", argv[1]); wprintf(L"Executable File Name: %s\n", argv[2]); if (ChangeIcon(argv[1], argv[2]) == true) printUsage = false; else printf("failed\n"); } if (printUsage == true) { printf("Usage: iconswap.exe [Icon File Name] [Executable File Name]\n"); } return 0; }
BOOL CPrime95App::InitInstance() { int orig_cmdShow; int named_ini_files = -1; int torture_test = 0; char *p; // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. //SetRegistryKey(_T("GIMPS")); //LoadStdProfileSettings(0); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_MDITYPE, RUNTIME_CLASS(CPrime95Doc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CPrime95View)); if (!pDocTemplate) return FALSE; AddDocTemplate(pDocTemplate); // Init our view mutexes gwmutex_init (&VIEW_MUTEX); gwmutex_init (&VIEW_LINES_MUTEX); // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME)) { delete pMainFrame; return FALSE; } m_pMainWnd = pMainFrame; // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line orig_cmdShow = m_nCmdShow; if (!ProcessShellCommand(cmdInfo)) return FALSE; /* Change the working directory to the same directory that */ /* the executable is located. This is especially important */ /* for running prime95 as a Windows 95 service */ { char buf[256]; GetModuleFileName (NULL, buf, sizeof (buf)); strrchr (buf, '\\')[1] = 0; _chdir (buf); } /* Initialize gwnum call back routines. Using callback routines lets the */ /* gwnum library have a nice clean interface for users that do not need */ /* additional functionality that only prime95 uses. */ StopCheckRoutine = stopCheck; OutputBothRoutine = OutputBoth; /* NT services are not passed command line arguments. In this case we */ /* encode the -An information in the NT service name. */ if (NTSERVICENAME[0] && NTSERVICENAME[15] == '-') named_ini_files = atoi (&NTSERVICENAME[16]); // Process command line switches for (p = m_lpCmdLine; *p == '//' || *p == '-'; ) { p++; switch (*p++) { // Accept a -A switch indicating an alternate set of INI files // are to be used. case 'A': case 'a': named_ini_files = 0; while (isspace (*p)) p++; while (isdigit (*p)) { named_ini_files = named_ini_files * 10 + (*p - '0'); p++; } break; // Accept a -T switch to run the torture test. case 'T': case 't': torture_test = 1; break; // Accept a -W switch indicating an alternate working directory. case 'W': case 'w': { char buf[256]; char *bufp = buf; while (isspace (*p)) p++; while (*p && !isspace (*p)) *bufp++ = *p++; *bufp = 0; _chdir (buf); } break; } // Skip whitespace between switches while (isspace (*p)) p++; } // Make sure only one copy of prime95 is running at a time. // This code is courtesy of Jeroen C. van Gelderen // I enhanced it to allow multiple copies if they are running // from different directories or use different -A switches. { char buf[256]; char *p; DWORD mutex_error_code; PSID pEveryoneSID = NULL, pAdminSID = NULL; PACL pACL = NULL; PSECURITY_DESCRIPTOR pSD = NULL; EXPLICIT_ACCESS ea[1]; SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY; SECURITY_ATTRIBUTES sa; // Turn directory name into a (likely) unique integer // Add in the -A value. Use this integer to create a mutex name. _getcwd (buf, 255); for (p = buf; *p; p++) g_MutexNum = g_MutexNum * 17 + *p; g_MutexNum += named_ini_files; sprintf (buf, "Global\\GIMPS%ld", g_MutexNum); /* Create a world access security descriptor to share the Mutex we */ /* are about to create. If we run into any troubles, assume this is */ /* a Windows 95/98/Me system and create a simple Mutex. */ // Create a well-known SID for the Everyone group. if (! AllocateAndInitializeSid ( &SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pEveryoneSID)) goto simple_mutex; // Initialize an EXPLICIT_ACCESS structure for an ACE. // The ACE will allow the Administrators group full access to the key. ZeroMemory (&ea, sizeof (EXPLICIT_ACCESS)); ea[0].grfAccessPermissions = EVENT_ALL_ACCESS; ea[0].grfAccessMode = SET_ACCESS; ea[0].grfInheritance= NO_INHERITANCE; ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID; ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP; ea[0].Trustee.ptstrName = (LPTSTR) pEveryoneSID; // Create a new ACL that contains the new ACEs. if (SetEntriesInAcl (1, ea, NULL, &pACL) != ERROR_SUCCESS) goto simple_mutex; // Initialize a security descriptor. pSD = (PSECURITY_DESCRIPTOR) LocalAlloc (LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); if (pSD == NULL) goto simple_mutex; if (! InitializeSecurityDescriptor (pSD, SECURITY_DESCRIPTOR_REVISION)) goto simple_mutex; // Add the ACL to the security descriptor. if (! SetSecurityDescriptorDacl (pSD, TRUE, pACL, FALSE)) goto simple_mutex; // Initialize a security attributes structure. sa.nLength = sizeof (SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = pSD; sa.bInheritHandle = FALSE; // Create our mutex. Windows XP uses terminal services to support user // switching. The "Global\" prefix is required so that this mutex is // is created in the global kernel objects namespace. Unfortunately, // the "\" character raises an error on Windows 95/98/Me systems. g_hMutexInst = CreateMutex ( &sa, // World access FALSE, // Not owned !! buf); // Unique name if (g_hMutexInst == NULL) simple_mutex: g_hMutexInst = CreateMutex ( NULL, // No security stuff FALSE, // Not owned !! buf+7); // Unique name mutex_error_code = GetLastError (); // Cleanup all the security structures we initialized if (pEveryoneSID) FreeSid (pEveryoneSID); if (pACL) LocalFree (pACL); if (pSD) LocalFree (pSD); // Test for failure if (g_hMutexInst == NULL) return 0; // If mutex already exists then another instance is already running if (mutex_error_code == ERROR_ALREADY_EXISTS) { HWND hwndPrevInst = 0; // Give other instance a little time to display it's main window Sleep (750); // Find the window handle EnumWindows (&MyEnumProc, (LPARAM) &hwndPrevInst); // Unhide the other instance's window if (hwndPrevInst) { ShowWindow (hwndPrevInst, SW_HIDE); ShowWindow (hwndPrevInst, SW_SHOWMINIMIZED); ShowWindow (hwndPrevInst, SW_SHOWNORMAL); } CloseHandle (g_hMutexInst); g_hMutexInst = NULL; return 0; } // Set the window user data so we can be identified by // another instance of this program. SetWindowLongPtr (m_pMainWnd->m_hWnd, GWLP_USERDATA, (LONG_PTR) g_MutexNum); } /* Cache icon handles to work around Windows deadlocking bug */ ICON_IDLE = LoadIcon (IDI_YELLOW_ICON); ICON_WORKING = LoadIcon (IDR_MAINFRAME); /* Name and read the INI files. Perform some other startup initializations. */ nameAndReadIniFiles (named_ini_files); initCommCode (); /* Before processing the INI file, hide and/or position the */ /* main window so that we can display error messages */ m_pMainWnd->SetWindowText ("Prime95"); WINDOWPLACEMENT wp; m_pMainWnd->GetWindowPlacement (&wp); int left = IniGetInt (INI_FILE, "Left", 0); int top = IniGetInt (INI_FILE, "Top", 0); int right = IniGetInt (INI_FILE, "Right", 0); int bottom = IniGetInt (INI_FILE, "Bottom", 0); if (right + left + top + bottom != 0) { wp.rcNormalPosition.left = left; wp.rcNormalPosition.top = top; wp.rcNormalPosition.right = right; wp.rcNormalPosition.bottom = bottom; } wp.showCmd = HIDE_ICON ? SW_HIDE : SW_SHOWMINIMIZED; m_pMainWnd->SetWindowPlacement (&wp); /* Now show the main window and post initial messages */ // Put prime95 in the system tray if (TRAY_ICON) TrayMessage (NIM_ADD, "Prime95", 0); // See if we are running as a Windows95 service WINDOWS95_SERVICE = IniGetInt (INI_FILE, "Windows95Service", 0); WINDOWS95_A_SWITCH = named_ini_files; Service95 (); // Run the torture test if asked to by a command line argument if (torture_test) { m_pMainWnd->ShowWindow (orig_cmdShow); m_pMainWnd->PostMessage (WM_COMMAND, USR_TORTURE, 0); } // On first run, see if this is a stress tester. If not, step // user throught the primenet dialog boxes. else if (STRESS_TESTER == 99) { m_pMainWnd->ShowWindow (orig_cmdShow); m_pMainWnd->PostMessage (WM_COMMAND, USR_WELCOME, 0); } // Take stress testers straight to the torture dialog box else if (STRESS_TESTER) { m_pMainWnd->ShowWindow (orig_cmdShow); m_pMainWnd->PostMessage (WM_COMMAND, IDM_TORTURE, 0); } // Auto-continue if there is any work to do. else if (USE_PRIMENET || WELL_BEHAVED_WORK || WORKTODO_COUNT) { m_pMainWnd->PostMessage (WM_COMMAND, IDM_CONTINUE, 0); } // Otherwise, show the window else if (!HIDE_ICON) { m_pMainWnd->ShowWindow (orig_cmdShow); ChangeIcon (MAIN_THREAD_NUM, IDLE_ICON); } // Initialization complete return TRUE; }
BOOL CTrayIcon::ChangeStandardIcon(LPCTSTR lpszIconName) { HICON hIcon = AfxGetApp()->LoadStandardIcon(lpszIconName); return ChangeIcon(hIcon); }
BOOL CTrayIcon::ChangeIcon(UINT nID) { HICON hIcon = AfxGetApp()->LoadIcon(nID); return ChangeIcon(hIcon); }