Задачи:
Я попытался преобразовать свое приложение в формат, совместимый с механизмом отображения состояния простоя. Мой подход заключался в создании программы напрямую двумя разными методами:
- Превращение приложения в приложение Windows Forms
Создание консольного приложения
Однако это процесс не увенчался успехом. Предварительный просмотр состояния простоя не запускается, хотя программа отображается в настройках конфигурации. Кажется, программа работает в фоновом режиме, но не видна на мониторе, когда система становится неактивной.
Вопрос:
Как я могу изменить свою программу на C#, которая эффективно имитирует желаемый визуальный эффект в среде консоли, чтобы она правильно функционировала в качестве визуального дисплея во время простоя компьютера? По сути, как мне устранить разрыв между выводом консоли и ожидаемым форматом и поведением программы, которая визуально активируется во время бездействия системы?
Мой код успешно создает тот визуальный элемент, к которому я стремлюсь. , но я изо всех сил пытаюсь адаптировать его для работы во время простоя компьютера. При переименовании с использованием соответствующего расширения для таких программ он просто запускается, не появляясь на экране.
Настройки программы в режиме ожидания — изображение окна предварительного просмотра, в котором программа не запускается должным образом. . Это происходит после того, как я нажимаю «Предварительный просмотр».
Вот мой код:
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.Threading;
namespace BinaryCodeScreensaver
{
class BinaryCode
{
static void Main(string[] args)
{
int matrixCode = 0;
int screenHeight = Console.WindowHeight;
int screenWidth = Console.WindowWidth / 9;
List screenLines = new List();
List currentLines = new List();
List currentColumns = new List();
List columnDelays = new List();
Random random = new Random();
ConsoleColor currentColor = ConsoleColor.DarkGreen;
Console.CursorVisible = false;
bool pageFilled = false; // Flag to track if the page is filled
string symbols = "ÄÅÆÇÐÉÑÖØÜßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ"; // String of possible symbols
// Initialize screen lines
for (int lineIndex = 0; lineIndex < screenHeight; lineIndex++)
{
screenLines.Add("");
}
currentLines.Add(0);
currentColumns.Add(0);
columnDelays.Add(0);
while (true)
{
// Generate new matrix code and add new columns
if (matrixCode >= 255)
{
matrixCode = 0;
if (currentLines.Count < screenWidth)
{
currentLines.Add(0);
currentColumns.Add(currentLines.Count - 1);
columnDelays.Add(random.Next(50));
}
currentColor = GetRandomGreenShade(random);
}
// Iterate over columns and update characters
for (int columnIndex = 0; columnIndex < currentLines.Count; columnIndex++)
{
if (columnDelays[columnIndex] > 0)
{
columnDelays[columnIndex]--;
continue;
}
int currentLine = currentLines[columnIndex];
int currentColumn = currentColumns[columnIndex];
string binaryString = Convert.ToString(matrixCode, 2).PadLeft(8, '0') + " ";
string previousString = "";
if (screenLines[currentLine].Length > currentColumn * 9)
{
previousString = screenLines[currentLine].Substring(currentColumn * 9, 9);
}
screenLines[currentLine] = screenLines[currentLine].PadRight(currentColumn * 9) + binaryString;
Console.SetCursorPosition(currentColumn * 9, currentLine);
Console.Write(new string(' ', binaryString.Length));
Console.SetCursorPosition(currentColumn * 9, currentLine);
// Output characters with color and effects
for (int characterIndex = 0; characterIndex < binaryString.Length - 1; characterIndex++)
{
if (characterIndex < previousString.Length && binaryString[characterIndex] != previousString[characterIndex])
{
ConsoleColor newGreenShade = currentColor;
while (newGreenShade == currentColor)
{
newGreenShade = GetRandomGreenShade(random);
}
Console.ForegroundColor = newGreenShade;
// Apply random opacity to this character
if (pageFilled && random.Next(100) < 60) // 60% chance of opacity change
{
int opacityLevel = random.Next(1, 4); // Generate random opacity level (1-3)
switch (opacityLevel)
{
case 1:
Console.ForegroundColor = ConsoleColor.Green;
break;
case 2:
Console.ForegroundColor = ConsoleColor.DarkGreen;
break;
case 3:
Console.ForegroundColor = ConsoleColor.Black;
break;
case 4:
default:
break;
}
}
// Replace with a random symbol with a green shade
if (pageFilled && random.Next(100) < 5) // 5% chance of symbol replacement
{
int randomSymbolIndex = random.Next(symbols.Length);
Console.ForegroundColor = GetRandomGreenShade(random);
Console.Write(symbols[randomSymbolIndex]);
Console.ResetColor();
continue;
}
}
else
{
if (previousString.Length > characterIndex && previousString[characterIndex] == '0')
{
Console.ForegroundColor = GetRandomGreenShade(random);
}
else
{
Console.ForegroundColor = ConsoleColor.White;
}
}
Console.Write(binaryString[characterIndex]);
}
Console.ResetColor();
// Update line and column positions
currentLines[columnIndex]++;
if (currentLines[columnIndex] >= screenHeight)
{
currentLines[columnIndex] = 0;
currentColumns[columnIndex]++;
if (currentColumns[columnIndex] >= screenWidth)
{
currentColumns[columnIndex] = 0;
pageFilled = true; // Page is filled when all columns are filled
}
}
}
matrixCode++;
if (!pageFilled)
{
Thread.Sleep(0);
}
else
{
Thread.Sleep(50);
}
}
}
// Generate a random shade of green
static ConsoleColor GetRandomGreenShade(Random random)
{
int greenValue = random.Next(100, 256);
ConsoleColor greenShade = ConsoleColor.DarkGreen;
if (greenValue > 200)
{
greenShade = ConsoleColor.Green;
}
else if (greenValue > 150)
{
greenShade = ConsoleColor.DarkGreen;
}
return greenShade; // Return the generated color
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... creensaver
Мобильная версия