Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
MATRIX_GDI+ - MATRIX rain code in GDI+

MATRIX_GDI+

Sommario | Admin | Forum | Bugs | Todo | Files

Pagine: [ 1 2 ] Precedente | Prossimo
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2321
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 15:10
Sabato, 27/04/2024
carino, molto simile ma non è proprio quello che avevo fatto.

in pratica il tuo esempio è come un layer su cui vai ad eseguire il paint.
invece intendevo proprio il paint diretto sul desktop.
precisamente sotto le icone, mentre in questo esempio il testo va sopra alle icone e sopra alle applicazioni.

Tramite Window.h ho usato questa api

Codice sorgente - presumibilmente Plain Text

  1. SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (void*)imagePath, SPIF_UPDATEINIFILE)




o meglio

Codice sorgente - presumibilmente C++

  1. bool ImpostaSfondo(const wchar_t* imagePath) {
  2.         if (!SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (void*)imagePath, SPIF_UPDATEINIFILE)) {
  3.             return false;
  4.         }
  5.         return true;
  6.     }



E precisamente quello che volevo fare, disegnare allo stesso livello del desktop.
Il mio è stato un test, non è certo la soluzione migliore, anzi penso sia la peggiore.
E decisamente troppo lento.
Penso che ogni Timeout anche se impostato a 20 o 30 arrivi a scattare circa a 200 se non 300 ms
un bel distacco e decisamente poco fluido. però con background nero sul desktop e testo che scende, e un bell'effetto.
peccato che sia lento.

Se sei cuirioso di provare

Codice sorgente - presumibilmente C#

  1. private const int SPI_SETDESKWALLPAPER = 20;
  2.     private const int SPIF_UPDATEINIFILE = 1;
  3.  
  4. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  5. private static extern int SystemParametersInfo(uint action, uint uParam, string vParam, uint winIni);
  6.  
  7. SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, percorsoFileImmagine, SPIF_UPDATEINIFILE);



Trovi il resto della documentazione direttamente su pinvoke

Ultima modifica effettuata da Thejuster il 27/04/2024 alle 15:17


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Avatar
AldoBaldo (Member)
Guru


Messaggi: 708
Iscritto: 08/01/2015

Segnala al moderatore
Postato alle 21:46
Lunedì, 06/05/2024
Puoi provare a ricavare l'HWND del desktop, ricavare poi l'HDC di quell'HWND e disegnare direttamente su quello con le classiche API di GDI.

=============================

The GetDesktopWindow function returns the handle of the Windows desktop window. The desktop window covers the entire screen. The desktop window is the area on top of which all icons and other windows are painted.

HWND GetDesktopWindow(VOID);

Parameters
This function has no parameters.

Return Values
The return value is the handle of the desktop window.

=============================

The GetDC function retrieves a handle of a display device context (DC) for the client area of the specified window. The display device context can be used in subsequent GDI functions to draw in the client area of the window.
This function retrieves a common, class, or private device context depending on the class style specified for the specified window. For common device contexts, GetDC assigns default attributes to the device context each time it is retrieved. For class and private device contexts, GetDC leaves the previously assigned attributes unchanged.

HDC GetDC(HWND hWnd);

Parameters
hWnd: Identifies the window whose device context is to be retrieved.

Return Values
If the function succeeds, the return value identifies the device context for the given window's client area.
If the function fails, the return value is NULL.

Remarks
After painting with a common device context, the ReleaseDC function must be called to release the device context. Class and private device contexts do not have to be released. The number of device contexts is limited only by available memory.

=============================

The ReleaseDC function releases a device context (DC), freeing it for use by other applications. The effect of the ReleaseDC function depends on the type of device context. It frees only common and window device contexts. It has no effect on class or private device contexts.

int ReleaseDC(HWND hWnd, HDC hDC);  

Parameters
hWnd: Identifies the window whose device context is to be released.
hDC: Identifies the device context to be released.

Return Values
The return value specifies whether the device context is released. If the device context is released, the return value is 1. If the device context is not released, the return value is zero.

Remarks
The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common device context.
An application cannot use the ReleaseDC function to release a device context that was created by calling the CreateDC function; instead, it must use the DeleteDC function.

=============================

Ultima modifica effettuata da AldoBaldo il 06/05/2024 alle 21:49


ATTENZIONE! Sono un hobbista e l'affidabilità delle mie conoscenze informatiche è molto limitata. Non prendere come esempio il codice che scrivo, perché non ho alcuna formazione accademica e rischieresti di apprendere pratiche controproducenti.
PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1373
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 23:28
Lunedì, 06/05/2024
Testo quotato

Postato originariamente da AldoBaldo:

Puoi provare a ricavare l'HWND del desktop, ricavare poi l'HDC di quell'HWND e disegnare direttamente su quello con le classiche API di GDI.




Ho fatto una prova veloce, ma disegna sopra alle icone del desktop e alle finestre (allegato eseguibile)
Codice sorgente - presumibilmente C++

  1. using System;
  2. using System.Runtime.InteropServices;
  3.  
  4. class Program
  5. {
  6.     [DllImport("user32.dll")]
  7.     static extern IntPtr GetWindowDC(IntPtr hWnd);
  8.  
  9.     [DllImport("user32.dll")]
  10.     static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
  11.  
  12.     [DllImport("gdi32.dll")]
  13.     static extern bool LineTo(IntPtr hdc, int x, int y);
  14.  
  15.     [DllImport("gdi32.dll")]
  16.     static extern bool MoveToEx(IntPtr hdc, int x, int y, IntPtr lpPoint);
  17.  
  18.     [DllImport("user32.dll")]
  19.     static extern IntPtr GetDesktopWindow();
  20.  
  21.     static void Main(string[] args)
  22.     {
  23.         IntPtr desktopHandle = GetDesktopWindow();
  24.         IntPtr desktopDC = GetWindowDC(desktopHandle);
  25.  
  26.         // Disegna una linea nera diagonale sul desktop
  27.         MoveToEx(desktopDC, 0, 0, IntPtr.Zero);
  28.         LineTo(desktopDC, 1800, 1600);
  29.  
  30.         ReleaseDC(desktopHandle, desktopDC);
  31.     }
  32. }



Invece non ho provato il metodo logico di Thejuster adatto per un'immagine fissa.


Carlo ha allegato un file: Desktop.zip (1803 bytes)
Clicca qui per scaricare il file

Ultima modifica effettuata da Carlo il 07/05/2024 alle 0:02


in programmazione tutto è permesso
PM Quote
Avatar
AldoBaldo (Member)
Guru


Messaggi: 708
Iscritto: 08/01/2015

Segnala al moderatore
Postato alle 23:40
Lunedì, 06/05/2024
Sì, Carlo, le icone e il resto fanno comunque parte dell'immagine mostrata nell'HDC. Quando disegni in un HDC sovrapponi i nuovi segni a quelli già esistenti. Se ora ho ben capito, tu vorresti invece modificare lo sfondo del desktop e ritracciarlo prima che il sistema ci sovrapponga le icone e il resto. Non so neppure se è o non è possibile!


ATTENZIONE! Sono un hobbista e l'affidabilità delle mie conoscenze informatiche è molto limitata. Non prendere come esempio il codice che scrivo, perché non ho alcuna formazione accademica e rischieresti di apprendere pratiche controproducenti.
PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1373
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 0:13
Martedì, 07/05/2024
Testo quotato

Postato originariamente da AldoBaldo:

Sì, Carlo, le icone e il resto fanno comunque parte dell'immagine mostrata nell'HDC. Quando disegni in un HDC sovrapponi i nuovi segni a quelli già esistenti. Se ora ho ben capito, tu vorresti invece modificare lo sfondo del desktop e ritracciarlo prima che il sistema ci sovrapponga le icone e il resto. Non so neppure se è o non è possibile!



Non ho trovato api.

Il metodo di Thejuster, anche se non l'ho provato funziona sicuramente: prende lo sfondo, lo copia in una bitmap, crea una nuova bitmap ci disegna lo sfondo e poi ci disegna sopra i caratteri, salva la nuova bitmap e la ricarica come sfondo del desktop. Ripete il ciclo usando sempre come partenza la bitmap con lo sfondo originale.

Potresti controllare in C se esiste un mezzo per sostituire in modo efficiente lo sfondo del desktop... Thejuster per farlo è passato per un file...


in programmazione tutto è permesso
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2321
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 10:11
Martedì, 07/05/2024
Forse ho trovato un modo.
Il tempo che faccio qualche piccolo test e vi faccio sapere.
Sarebbe bello proprio pubblicarlo come programma se funziona.

Un desktop alla matrix sarebbe il top.

Il tempo che faccio qualche test e vi faccio sapere.


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2321
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 15:45
Martedì, 07/05/2024
Quello che ho scoperto, e che il processo che disegna sul desktop è chiamato Progman
che fa riferimento all'istanza Worker  contenuta in  Program Manager aka Progman.

Penso che sia proprio a quello che dobbiamo puntare per poter disegnarci sopra.


ad esempio

Codice sorgente - presumibilmente C#

  1. [DllImport("user32.dll", SetLastError = true)]
  2. public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  3.  
  4.  
  5. IntPtr progman = FindWindow("Progman", null);



Si potrebbe in seguito usare un loop per disegnare

Codice sorgente - presumibilmente C#

  1. [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  2.         public static extern IntPtr SendMessageTimeout(IntPtr windowHandle, uint Msg, IntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags flags, uint timeout, out IntPtr result);
  3.  
  4.  
  5. IntPtr risultato = IntPtr.Zero;
  6.  
  7. //Processo, Messaggio, wParam,lParam,Stato,Timeout in millis,ritorna IntPtr risultato
  8. SendMessageTimeout(progman,0x052C,new IntPtr(0),IntPtr.Zero,0x0,20,out risultato);



Da qui in poi sto cercando di capire come fare ho tentato di versi modi ma non succede nulla.
il desktop rimane invariato.

Non penso sia impossibile. Anche perché nulla è impossibile nella programmazione.
Bisogna solo capire come fare.

Solitamente si usa il DC.

in c++ basta collegare il paint diretto al DC, mentre in c# si potrebbe fare sfruttando IntPtr
del tipo

Codice sorgente - presumibilmente C#

  1. [DllImport("user32.dll")]
  2.         public static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, uint flags);
  3.  
  4.  
  5. IntPtr workerW = FindWindowEx("WorkerW",IntPtr.Zero);
  6.  
  7. //403 sta per ottenere un DC per l'intera finestra incluso il non Client area
  8. IntPtr dc = GetDC(workerW,IntPtr.Zero,0x403);
  9.  
  10.  
  11. //in seguito
  12.  
  13. Graphics g = Graphics.FromHdc(dc);



Ma non accade nulla.
Magari sbaglio io qualcosa non saprei...


Thejuster ha allegato un file: Cattura.PNG (16206 bytes)
Clicca qui per guardare l'immagine

Ultima modifica effettuata da Thejuster il 07/05/2024 alle 16:01


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Pagine: [ 1 2 ] Precedente | Prossimo