Chaine radio/tv

Description

Chaine RADIO/TV est un petit programme qui liste un certain nombre de chaîne radio/TV cliquez sur un mon et le lecteur multimédias par défaut (qui lit le m3u) s'ouvre avec la chaîne désiré (les chaînes son modifiable dans le config.cfg)
Attention un point importent :
dans le config.cfg la syntaxe est la suivant .
[VIDE] //une ligne du listbox vide
[TITRE]=Le titre;
//les deux suivent doive être toujours ensemble
[CHAINE]=Nom de la chaine;
[URL]=Url de la page;

exemple:

[TITRE]= «»«»«»«»«]TV[»«»«»«»«»;

[VIDE]

[CHAINE]=[!] TF1;
[URL]=mms://a889.l4162624888.c41626.e.lm.akamaistream.net/D/889/41626/v0001/reflector:24888;

Source / Exemple :


#include <windows.h>
#include <fstream>
#include <vector>
#define IDB_BUTTON 0X0ff
#define IDM_HELP 0x1ff
#define IDM_APROPO 0x2ff 
#define WM_ICONE 0x3fff
HWND hButton,hButtont;
using namespace std;

/*  Declare Windows procedure  */
const HBRUSH hCouleur_blue   =  CreateSolidBrush(RGB(200,200,255)); 
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
HINSTANCE Inst;
ifstream fStr; 
string sCint,sTempo,sTempo2;
int a,infoSelect,infomom;
int nbChaine=0;
vector<std::string> vLien;
HMENU hMenu,jmenupopup;
HBITMAP fond;
HRGN Rgn; 
POINT point;
const char* ccNULL="NULL";
const char* ccCHAINE="[CHAINE]";
const char* ccTITRE="[TITRE]";
const char* ccVIDE="[VIDE]";
const char* ccURL="[URL]";
const char* ccECPACE=" ";
/*  Make the class name into a global variable  */
char szClassName[ ] = "Chaine RADIO/TV";

void error(std::string);
BOOL Deleticone(HWND fen);
DWORD WINAPI add_icone(HWND fen,char *infobulle);

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

{
    Inst=hThisInstance;
    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 = szClassName;
    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 (hThisInstance, "A");
    wincl.hIconSm = LoadIcon (hThisInstance, "A");
    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) hCouleur_blue;

    /* 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 = CreateWindowEx (
          WS_EX_CLIENTEDGE|WS_EX_TOPMOST,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Chaine RADIO/TV",       /* Title Text */
           WS_VISIBLE|WS_SYSMENU, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           190,                 /* The programs width */
           275,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    // Création du menu ------------------------------------------------------------
    hMenu = CreateMenu();
    hMenuPopup = CreateMenu();
    AppendMenu (hMenuPopup , MF_SEPARATOR, 0 ,NULL); 
    AppendMenu (hMenuPopup , MF_STRING, WM_DESTROY , "&Quitter");
    AppendMenu (hMenu, MF_POPUP,(UINT)(hMenuPopup), "&Fichier");
    hMenuPopup = CreateMenu();
    AppendMenu (hMenuPopup , MF_STRING, IDM_APROPO ,"&A Propos");
    AppendMenu (hMenuPopup , MF_STRING, IDM_HELP ,"A&ide");
    AppendMenu (hMenu, MF_POPUP,(UINT)(hMenuPopup), "&Aide");
    hMenuPopup = CreateMenu();
    //afficher le menu
    SetMenu(hwnd, hMenu);
    /* 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 :
           
                hButton=CreateWindowEx(0, "LISTBOX", "",
                           WS_CHILD | WS_VISIBLE | LBS_STANDARD ,	//création d'un liste box							  
                          0,0,180,230,hwnd, (HMENU)0X0ff  , 
                           Inst, NULL);
           fStr.open("config.cfg", fstream::in);//ouverture du fichier config
           if(fStr)//si le fichier existe
           {     
                
                while(getline(fStr, sCint) )//on le lit ligne par ligne
                {
                     reteste :
                    if(sCint.length()!=0)//si la ligne a quelque chose
                    {    
                        if(sCint.substr(0,8)==ccCHAINE)
                        {
                            a=sCint.find_first_of('=')+1; //on cherche le premier =  
                            sTempo="\0";//on vide sTempo
                            while((sCint[a]==';')==false)
                            {      
                                sTempo+=sCint[a];
                                a++;
                            }
                            //on écri le nom dans le listbox 
                            SendMessage(hButton,LB_INSERTSTRING,nbChaine,(LPARAM) (LPCTSTR)sTempo.c_str());
                            nbChaine++;
                        }
                       
                        if(sCint.substr(0,7)==ccTITRE)
                        {
                            a=sCint.find_first_of('=')+1; 
                            sTempo="\0";
                            while((sCint[a]==';')==false)
                            {   
                                sTempo+=sCint[a];
                                a++;
                            }
                            SendMessage(hButton,LB_INSERTSTRING,nbChaine,(LPARAM) (LPCTSTR)sTempo.c_str()); 
                            nbChaine++;
                            vLien.push_back(ccNULL);
                        }
                        
                        if(sCint.substr(0,6)==ccVIDE)
                        {
                            SendMessage(hButton,LB_INSERTSTRING,nbChaine,(LPARAM) (LPCTSTR)""); 
                            nbChaine++;
                            vLien.push_back(ccNULL);
                        }
                        
                        if(sCint.substr(0,5)==ccURL)
                        {
                            a=sCint.find_first_of('=')+1; 
                            sTempo2="\0";
                            while((sCint[a]==';')==false)
                            {   
                                sTempo2+=sCint[a];
                                a++;
                            }
                            vLien.push_back(sTempo2);
                        }
                        
                        if(sCint.substr(0,1)==ccECPACE)
                        {
                            sCint.erase(0,1);
                            goto reteste;
                        }
                        
                    }    
                }
                if(!nbChaine)
                {
                    error("config.cfg est vide");
                }
            }
            else
            {
                error("Impossible d'ouvrire config.cfg");
            }
            fStr.close(); 
            SendMessage(hButton,LB_SETCURSEL ,(WPARAM)0,0);
             
           break;
             
            
            case WM_COMMAND : 
            {
                switch (LOWORD(wParam))
                {
                    case  IDB_BUTTON : 
                          infoSelect = SendMessage(hButton,LB_GETCURSEL,0,0); 
                          if(infoSelect==infomom)
                          {break;}
                          else
                          {infomom=infoSelect;}
                          if(vLien[infoSelect].compare(ccNULL)==1)
                          { 
                                     Sleep(300);     
                                    ofstream fichier("TV.m3u");
                                    fichier<<vLien[infoSelect];
                                    fichier.close();
                                    ShellExecute(NULL,"open","TV.m3u",0,0,0);
                                
                            } 
                          break;
                    case IDM_APROPO:
                        MessageBox(NULL,"\nNom : Chaine RADIO/TV\nVersion N° 0.9.5\nCréateur : Andrey Galen\n\nAF(R)",
                                        "Chaine N°0.9.5",MB_OK);
                        break; 
                    case IDM_HELP:
                        MessageBox(NULL,"[!] = Source pas sur. (Peut ne pas diffuser)\n[-] = Source sur. (Diffuse no-stop)"
                                        "\n\nPour quitter le programme fair Fichier\\Quitter ou Double click droit quitte"
                                        " quand le programme est dans la bar des taches.",
                                        "Help",MB_OK);
                        break;
                    case WM_DESTROY:
                        SendMessage(hwnd,WM_DESTROY,0,0); 
                        break;
                    
                
                }
            }break;
       
        case WM_ICONE :
                    if(lParam == WM_LBUTTONDOWN)
                    {
                    ShowWindow (hwnd, SW_SHOW);
                    Deleticone(hwnd);
                    }
                     if(lParam == WM_RBUTTONDBLCLK)
                    {
                    Deleticone(hwnd);
                    SendMessage(hwnd,WM_DESTROY,0,0);
                    }
                    break;
                
               break;
            case WM_CLOSE :
                ShowWindow (hwnd, SW_HIDE);
                add_icone(hwnd,"Chaine RADIO/TV\nClick gauche restore\nDouble click droit quitte");
                return 0;
           case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                 
                 break;
                 
            
    }

    return DefWindowProc (hwnd, message, wParam, lParam);
}

void error(std::string error)
{
    MessageBox(NULL,error.c_str(),0,MB_OK);
    exit(0);
}

DWORD WINAPI add_icone(HWND fen,char *infobulle)
//fen est la fenetre "mere"
//infobulle est le texte qui s'affiche quand on passe dessus l'icone avec la souris .
{

NOTIFYICONDATA tnid;
tnid.cbSize = sizeof(NOTIFYICONDATA);

tnid.hWnd = fen;

tnid.uID = 2;
tnid.uFlags =NIF_MESSAGE|NIF_TIP|NIF_ICON ;
tnid.uCallbackMessage = WM_ICONE;
tnid.hIcon = LoadIcon(Inst,"A" );
if (infobulle)
lstrcpyn(tnid.szTip, infobulle, sizeof(tnid.szTip));
else
tnid.szTip[0]='\0';
Shell_NotifyIcon(NIM_ADD, &tnid);
return 0;
}

BOOL Deleticone(HWND fen)
// fen est la fenetre "mere" de cette icone
{
BOOL res;
NOTIFYICONDATA tnid;

tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = fen;
tnid.uID =2;

res = Shell_NotifyIcon(NIM_DELETE, &tnid);
return res;
}

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.