Icones du bureau en cercle

Description

Recupere les icones du bureau et en fait un cercle.
Le diametre du cercle est modifiable grace a l'icone dans la barre des taches.

Realise avec DevC++
mais doit fonctionner sans grand pb avec BorlandC++ et VC++

Teste sur Win98 et WinNT4.
Devrait fonctionner sur les autres Windows

Source / Exemple :


#include <windows.h>
#include <shellapi.h>
#include <commctrl.h>
#include <math.h>

#define ID_RESET 1001
#define ID_RATIO 1002
#define ID_OK    1003
#define ID_ICON  1004
#define WM_PITASKBAR 2001

/*  Make the class name into a global variable  */
const char szAppName[] = "PosIcons";

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Variables globales */
int lScreen, hScreen, nIcons;
float actRatio;
HINSTANCE hInst;
HWND hWndMain, hWndReset, hWndRatio, hWndOK, hWndSysListView;

/***  ICONE BARRE DE TACHES ***/
void PITaskBarAdd(HICON hIcon, int idIcon)
{
	NOTIFYICONDATA tnid;

   tnid.cbSize = sizeof(NOTIFYICONDATA);
   tnid.hWnd = hWndMain;
   tnid.uID = idIcon;
   tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
   tnid.uCallbackMessage = WM_PITASKBAR;
   tnid.hIcon = hIcon;
   lstrcpyn(tnid.szTip, szAppName, sizeof(tnid.szTip));
   Shell_NotifyIcon(NIM_ADD, &tnid);
}

void PITaskBarDel(int idIcon)
{
   NOTIFYICONDATA tnid;

   tnid.cbSize = sizeof(NOTIFYICONDATA);
   tnid.hWnd = hWndMain;
   tnid.uID = idIcon;
   Shell_NotifyIcon(NIM_DELETE, &tnid);
}
/***  FIN ICONE BARRE DE TACHES ***/

/***  RECUPERATION Bureau ***/
void PIInfos(void)
{
   RECT r;
   hWndSysListView = GetWindow(GetWindow(FindWindowEx(NULL, NULL, "Progman", "Program Manager"), GW_CHILD), GW_CHILD);
   nIcons = ListView_GetItemCount(hWndSysListView);
   GetWindowRect(GetDesktopWindow(), &r);
   lScreen = r.right;
   hScreen = r.bottom;
}

/*** Realise le cercle ***/
void PICircle(float ratio)
{
   int i;
   float x, y;
   float x1 = lScreen / 2;
   float y1 = hScreen / 2;
   float ratio1 = lScreen * ratio / 100;
   float ratio2 = hScreen * ratio / 100;
      
   float M_PI = 3.14;
   float Constante = 2 * M_PI / nIcons;

   for (i = 0; i < nIcons; i++)
   {
       x = x1 + ratio1 * cos(i * Constante) - 16;
       y = y1 - ratio2 * sin(i * Constante) - 24;      
       ListView_SetItemPosition(hWndSysListView, i, (int)x, (int)y);
   }
}

int WINAPI
WinMain (HINSTANCE hThisInstance,
         HINSTANCE hPrevInstance,
         LPSTR lpszArgument,
         int nFunsterStil)

{
    HWND hWnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szAppName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_WINLOGO);
    wincl.hIconSm = LoadIcon (NULL, IDI_WINLOGO);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/

   hWnd = CreateWindow(szAppName, szAppName, 
   WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_CLIPCHILDREN, 
   0, 0, 0, 0, NULL, NULL, hThisInstance, NULL);
   hWndMain = hWnd;
   hInst = hThisInstance;
   
 
   PITaskBarAdd(LoadIcon (NULL, IDI_WINLOGO), ID_ICON);
   // Pour changer l'icone de la barre des taches
   // Il faut modifier cette variable :
   // LoadIcon (NULL, IDI_WINLOGO)
   
   // Fenetre invisible au demarrage 
   ShowWindow(hWnd, SW_HIDE);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_CREATE:
            PIInfos();
                   
            hWndReset = CreateWindow("button", "Reset", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 4, 4, 108, 24, hwnd, (HMENU)ID_RESET, hInst, NULL);
            SendMessage(hWndReset, WM_SETFONT, (WPARAM)GetStockObject(ANSI_VAR_FONT), 0);

            hWndOK = CreateWindow("button", "OK", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 4, 108, 108, 24, hwnd, (HMENU)ID_OK, hInst, NULL);
            SendMessage(hWndOK, WM_SETFONT, (WPARAM)GetStockObject(ANSI_VAR_FONT), 0);

            hWndRatio = CreateWindowEx(0, TRACKBAR_CLASS, "Ratio", WS_CHILD | WS_VISIBLE | TBS_NOTICKS | TBS_VERT, 44, 28, 24, 80, hwnd, (HMENU)ID_RATIO, hInst, NULL);
            SendMessage(hWndRatio, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 45));

            SendMessage(hWndRatio, TBM_SETPAGESIZE, (WPARAM)0, (LPARAM)4);
            SendMessage(hWndRatio, TBM_SETLINESIZE, (WPARAM)0, (LPARAM)1);
            SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_RESET, (LPARAM)0);
        return 0;
    
    
        case WM_COMMAND:
      	    switch(wParam)
            {
         	   case ID_RESET:
            	 	if ((actRatio = (nIcons - 1) * 100 / 36) > 45) actRatio = 45;
                    SendMessage(hWndRatio, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)actRatio);
                    PICircle(actRatio);
               break;
               
               case ID_OK:
            		ShowWindow(hwnd, SW_HIDE);
               break;
            }
      	return 0;
    
       	case WM_PITASKBAR:
       	    // Clic sur l'icone de la barre des taches 
      	    if ((wParam == ID_ICON) && (lParam == WM_LBUTTONDOWN)) ShowWindow(hwnd, SW_SHOW);
        return 0;
    
    
        case WM_VSCROLL:
         	actRatio = SendMessage(hWndRatio, TBM_GETPOS, (WPARAM)0, (LPARAM)0);
            PICircle(actRatio);
        return 0;

        case WM_ACTIVATE:
      	    switch(wParam)
            {
         	   case WA_ACTIVE:
               case WA_CLICKACTIVE:
                	PIInfos();
                    PICircle(actRatio);
                    MoveWindow(hwnd, (lScreen / 2) - 60, (hScreen / 2) - 80, 120, 160, TRUE);
                    SetForegroundWindow(hwnd);
                    break;

               case WA_INACTIVE:
                 	ShowWindow(hwnd, SW_HIDE);
                    break;
             }
        return 0;
    
    
        case WM_DESTROY:
            PITaskBarDel(ID_ICON);     // Supprimer l'icone de la barre des taches 
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

Conclusion :


Evolutions possibles :
- memoriser d'autres formes (carre, triangle, etoile, ...)
- rajouter des ressources (pour l'icone, ...)

si qqn trouve le code avant moi (pour d'autres formes), merci de m'aider un peu (-:

Bugs connus ???

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.

Du même auteur (mogwai93)