#include "stdafx.h" #include BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { // There are too many windows on the screen, actually. // We are interested in the visible ones only. if (IsWindowVisible(hwnd)) { static const char ReplaceFrom[] = "Oskom Client"; static const char ReplaceTo[] = "Ultima Online"; const int ReplaceFromLen = sizeof(ReplaceFrom) - 1; const int ReplaceToLen = sizeof(ReplaceTo) - 1; // Get the original window's title and its length. int OriginalBufferLen = GetWindowTextLength(hwnd) + 1; char* OriginalTitle = new char[OriginalBufferLen]; int OriginalTitleLen = GetWindowText(hwnd, OriginalTitle, OriginalBufferLen); // First, we check if the window's title contains no less characters // than the string we are looking for (that is ReplaceFrom string). // This check seems to be redundant, since we compare the strings later on, but // we have to check the return value of the function GetWindowText to be non-zero. // Then, we check if the window's title begins with the string ReplaceFrom. if (OriginalTitleLen >= ReplaceFromLen && strncmp(OriginalTitle, ReplaceFrom, ReplaceFromLen) == 0) { // Composing a new title: // it will start with the string ReplaceTo instead of ReplaceFrom. int ChangedTitleLen = OriginalTitleLen - ReplaceFromLen + ReplaceToLen; char* ChangedTitle = new char[ChangedTitleLen + 1]; strncpy(ChangedTitle, ReplaceTo, ReplaceToLen); strcpy(ChangedTitle + ReplaceToLen, OriginalTitle + ReplaceFromLen); // Set the new title. SetWindowText(hwnd, ChangedTitle); delete [] ChangedTitle; } delete [] OriginalTitle; } return TRUE; } int _tmain(int argc, _TCHAR* argv[]) { // Enumerate all top-level windows on the screen. // Function EnumWindowsProc will be called for every window. EnumWindows(&EnumWindowsProc, 0); return 0; }