Galawa, éditeur de scripts mirc (+ créateur de picwins et dialog boxes)


Description

Voici un projet assez laborieux pour quelqu'un qui, comme moi, titille le C/C++ sans vraiment en connaître les bases.
Galawa est un éditeur de scripts mIRC. J'utilise pour cela Scintilla.dll (projet open source). Il y a également la possibilité de créer des picwins et dialog boxes (toujours en construction).
Galawa utilise les APIs Windows, et n'est donc pas multi-plateformes.

Options de l'éditeur de scripts:
- coloration syntaxique (mIRC / html / C/C++)
- auto-indentation par ligne ou pour tout le texte
- numérotation des lignes
- fonctions de recherche (atteindre ligne ou chercher un mot)
- fonctions basiques d'éditeur de texte (copier,coller, charger, enregistrer, etc...)
- explorateur des commandes mIRC (identifieurs + commandes + événements)
- reconstitution de l'aide mIRC, par recherche alphabétique et lien vers des pages html
Attention toutefois, la base de données s'arrête à la version 6.15 de mIRC :p

Options du créateur de picwins:
- figures géométriques simples (rectangle, lignes, points)
- choix de l'épaisseur du trait et de la couleur (en valeur RGB)
- taille et options de la fenêtre réglables, avec un aperçu qui simule la proportionnalité entre la fenêtre et l'écran
- marquage de texte selon les normes de mIRC (avec ou sans fond, les couleurs étant aussi réglables)
- génération automatique du code mIRC de la picwin par un simple appui sur un bouton

Options du créateur de dialog boxes:
- cet outils est encore en construction, pour vous amuser, vous pouvez toujours tenter de créer un bouton par exemple (seuls button, checkbox, radiobutton et combobox sont faisables, avec un beug de redimensionnement sur ce dernier).

Après hésitation, je laisse le code source visible. Je pense qu'il y a pas mal de remarques à faire, étant donné que je gère vraiment mal les notions de pointeurs, ainsi que le traitement des variables. Je soupçonne également à mon application quelques fuites de mémoire (mais pas sûr) ainsi que quelques beugs d'affichage (dûs au message WM_PAINT que je ne maîtrise pas non plus à la perfection).
Pour la petite histoire, je n'apprendrais réellement le C que l'an prochain. Disons que pour le moment, je trifouille un peu pour savoir à quoi m'attendre.

Informations supplémentaires:
- codé sous Code::Blocks, sous Windows XP sp2
- utilisation de codes d'autres auteurs que moi:
---- le composant Scintilla (open source)
---- la fonction split(char*,const char*,int) que j'ai trouvé sur ce site
---- l'aide complète de mIRC v6.15

(ci-dessous, le code du créateur de picwin)

Source / Exemple :


void DrawToFile(HWND hand,HDC hdc);
typedef struct pCouleur {
    int r;
    int v;
    int b;
} COULEUR;
COULEUR co;
int epaisseur=1;
HPEN hp2px,hpOld;
char pTexte[100]="";
char pTitre[100]="Picwin";
int pX=306,pY=233;
int pDrag_x=0,pDrag_y=0;
COLORREF ColorChoose(HWND hParent,COLORREF previous) {
	static COLORREF customcolor[16];	//16 couleurs personnalisées
	CHOOSECOLOR cc;
	ZeroMemory(&cc,sizeof(CHOOSECOLOR));
	cc.lStructSize=sizeof(CHOOSECOLOR);
	cc.hwndOwner=hParent;
	cc.Flags=CC_FULLOPEN|CC_RGBINIT;
	cc.rgbResult=previous;
	cc.lpCustColors=customcolor;
	if (!ChooseColor(&cc))
		return previous;
	return cc.rgbResult;
}
void DrawButton(HWND hDlg,COLORREF newCT,COLORREF newCF) {
    PAINTSTRUCT ps;
    HDC Hdc=BeginPaint(hDlg,&ps);
    /** Couleur du texte **/
    HBRUSH brush=CreateSolidBrush(newCT);
    RECT rect;
    rect.left=118;
    rect.top=59;
    rect.right=142;
    rect.bottom=78;
    FillRect(Hdc,&rect,brush);
    /** Couleur du fond (ou pas) **/
    brush=CreateSolidBrush((IsDlgButtonChecked(hDlg,3))?newCF:RGB(255,255,255));
    rect.left=118;
    rect.top=83;
    rect.right=142;
    rect.bottom=102;
    FillRect(Hdc,&rect,brush);
    DeleteObject(brush);
    EndPaint(hDlg,&ps);
}
COLORREF newColorT=0,newColorF=RGB(255,255,255);
int pTexteBOOL=0,pFondBOOL=0;
/** Mise en forme du pinceau **/
void Prepare(HDC hdc) {
    char ep[4]="";
    GetWindowText(pTaille,ep,4);
    epaisseur=atoi(ep);
    if ((epaisseur <= 1) && (!SendMessage(htb3,TB_ISBUTTONCHECKED,303,0)) && (!SendMessage(htb3,TB_ISBUTTONCHECKED,304,0)))
        epaisseur=2;
    co.r=(GetWindowText(pRouge,ep,4))?atoi(ep):0;
    co.v=(GetWindowText(pVert,ep,4))?atoi(ep):0;
    co.b=(GetWindowText(pBleu,ep,4))?atoi(ep):0;
    hp2px=CreatePen(PS_SOLID,epaisseur,RGB(co.r,co.v,co.b));
    hpOld=(HPEN)SelectObject(hdc,hp2px);
}
/** Editeur de picwin **/
void VerifPicwin(HWND hand,int pos_x,int pos_y) {
    /** Initialisation du pinceau **/
    PAINTSTRUCT ps;
    HDC hdc=BeginPaint(hand,&ps);
    //SetBkMode(hdc,TRANSPARENT);
    HBRUSH brush;
    HFONT NewFont,OldFont;
    LOGFONT lf;
    ZeroMemory(&lf,sizeof(LOGFONT));
    lstrcpy(lf.lfFaceName,"Arial");
    lf.lfHeight=15;
    NewFont=CreateFontIndirect(&lf);
    OldFont=(HFONT)SelectObject(hdc,NewFont);
    /** Récupérations des coordonnées **/
    RECT area;
    GetWindowRect(hand,&area);
    PosFin_x=pos_x;
    PosFin_y=pos_y;
    /** Dessin d'un point (2/2) **/
    if (SendMessage(htb3,TB_ISBUTTONCHECKED,302,0)) {
        Rectangle(hdc,-1,-1,area.right-area.left+2,area.bottom-area.top+2);
        DrawToFile(hand,hdc);
        Prepare(hdc);
        MoveToEx(hdc,PosDepart_x,PosDepart_y,NULL);
        LineTo(hdc,PosDepart_x,PosDepart_y);
    }
    /** Dessin d'une ligne **/
    else if (SendMessage(htb3,TB_ISBUTTONCHECKED,303,0)) {
        Rectangle(hdc,-1,-1,area.right-area.left+2,area.bottom-area.top+2);
        DrawToFile(hand,hdc);
        Prepare(hdc);
        MoveToEx(hdc,PosDepart_x,PosDepart_y,NULL);
        LineTo(hdc,pos_x,pos_y);
    }
    /** Dessin d'un rectangle **/
    else if (SendMessage(htb3,TB_ISBUTTONCHECKED,304,0)) {
        Rectangle(hdc,-1,-1,area.right-area.left+2,area.bottom-area.top+2);
        DrawToFile(hand,hdc);
        Prepare(hdc);
        //Rectangle(hdc,PosDepart_x,PosDepart_y,pos_x,pos_y);
        /** Ligne honrizontale haute **/
        MoveToEx(hdc,PosDepart_x,PosDepart_y,NULL);
        LineTo(hdc,pos_x,PosDepart_y);
        /** Ligne honrizontale basse **/
        MoveToEx(hdc,PosDepart_x,pos_y,NULL);
        LineTo(hdc,pos_x,pos_y);
        /** Ligne verticale gauche **/
        MoveToEx(hdc,PosDepart_x,PosDepart_y,NULL);
        LineTo(hdc,PosDepart_x,pos_y);
        /** Ligne verticale droite **/
        MoveToEx(hdc,pos_x,PosDepart_y,NULL);
        LineTo(hdc,pos_x,pos_y);
        /** Remplissage (ou pas) **/
        if (IsDlgButtonChecked(hwnd,ID_PREMPLI)) {
            RECT rect;
            rect.left=PosDepart_x;
            rect.top=PosDepart_y;
            rect.right=pos_x;
            rect.bottom=pos_y;
            HBRUSH brush=CreateSolidBrush(RGB(co.r,co.v,co.b));
            FillRect(hdc,&rect,brush);
        }
    }
    /** Ecriture du texte **/
    else if (pTexteBOOL == 1) {
        Rectangle(hdc,-1,-1,area.right-area.left+2,area.bottom-area.top+2);
        DrawToFile(hand,hdc);
        SetTextColor(hdc,newColorT);
        if (pFondBOOL == 1) {
            SetBkMode(hdc,OPAQUE);
            SetBkColor(hdc,newColorF);
        }
        else
            SetBkMode(hdc,TRANSPARENT);
        TextOut(hdc,PosFin_x,PosFin_y,pTexte,strlen(pTexte));
    }
    DeleteObject(NewFont);
    DeleteObject(brush);
    EndPaint(hand,&ps);
}
/** Raffraichissement de la fenêtre **/
void DrawToFile(HWND hand,HDC hdc) {
    FILE* B_Pic=fopen(fichierPicwin,"r");
    if (B_Pic == NULL)
        return;
    char lecture[999]="";
    while (fgets(lecture,999,B_Pic) != NULL) {
        char** param=split(lecture,"¶",0);
        //POINT <epaisseur> <[rouge] [vert] [bleu]> <x> <y> END\n
        if (strcmp(param[0],"POINT") == 0) {
            /** Mise en forme du pinceau **/
            //char ep[4]="";
            epaisseur=atoi(param[1]);
            COULEUR co2;
            co2.r=atoi(param[2]);
            co2.v=atoi(param[3]);
            co2.b=atoi(param[4]);
            hp2px=CreatePen(PS_SOLID,epaisseur,RGB(co2.r,co2.v,co2.b));
            hpOld=(HPEN)SelectObject(hdc,hp2px);
            /** Dessin **/
            int x=0,y=0;
            x=atoi(param[5]);
            y=atoi(param[6]);
            MoveToEx(hdc,x,y,NULL);
            LineTo(hdc,x,y);
        }
        //LIGNE <epaisseur> <[rouge] [vert] [bleu]> <x1> <y1> <x2> <y2> END\n
        else if (strcmp(param[0],"LIGNE") == 0) {
            /** Mise en forme du pinceau **/
            //char ep[4]="";
            epaisseur=atoi(param[1]);
            COULEUR co2;
            co2.r=atoi(param[2]);
            co2.v=atoi(param[3]);
            co2.b=atoi(param[4]);
            hp2px=CreatePen(PS_SOLID,epaisseur,RGB(co2.r,co2.v,co2.b));
            hpOld=(HPEN)SelectObject(hdc,hp2px);
            /** Dessin **/
            int x1=0,y1=0,x2=0,y2=0;
            x1=atoi(param[5]);
            y1=atoi(param[6]);
            x2=atoi(param[7]);
            y2=atoi(param[8]);
            MoveToEx(hdc,x1,y1,NULL);
            LineTo(hdc,x2,y2);
        }
        //RECTANGLE <epaisseur> <[rouge] [vert] [bleu]> <x1> <y1> <x2> <y2> <rempli> <ellipse> END\n
        else if (strcmp(param[0],"RECTANGLE") == 0) {
            /** Mise en forme du pinceau **/
            //char ep[4]="";
            epaisseur=atoi(param[1]);
            COULEUR co2;
            co2.r=atoi(param[2]);
            co2.v=atoi(param[3]);
            co2.b=atoi(param[4]);
            hp2px=CreatePen(PS_SOLID,epaisseur,RGB(co2.r,co2.v,co2.b));
            hpOld=(HPEN)SelectObject(hdc,hp2px);
            /** Dessin **/
            int x1=0,y1=0,x2=0,y2=0,remp=0;
            x1=atoi(param[5]);
            y1=atoi(param[6]);
            x2=atoi(param[7]);
            y2=atoi(param[8]);
            remp=atoi(param[9]);
            /** Ligne honrizontale haute **/
            MoveToEx(hdc,x1,y1,NULL);
            LineTo(hdc,x2,y1);
            /** Ligne honrizontale basse **/
            MoveToEx(hdc,x1,y2,NULL);
            LineTo(hdc,x2,y2);
            /** Ligne verticale gauche **/
            MoveToEx(hdc,x1,y1,NULL);
            LineTo(hdc,x1,y2);
            /** Ligne verticale droite **/
            MoveToEx(hdc,x2,y1,NULL);
            LineTo(hdc,x2,y2);
            /** Remplissage (ou pas) **/
            if (remp == 1) {
                RECT rect;
                rect.left=x1;
                rect.top=y1;
                rect.right=x2;
                rect.bottom=y2;
                HBRUSH brush=CreateSolidBrush(RGB(co2.r,co2.v,co2.b));
                FillRect(hdc,&rect,brush);
            }
        }
        //TEXTE <texte> <couleur (texte)> <couleur (fond)> <x> <y> END\n
        if (strcmp(param[0],"TEXTE") == 0) {
            /** Mise en forme du pinceau **/
            //char ep[4]="";
            int coulT=atoi(param[2]),coulF=atoi(param[3]);
            SetTextColor(hdc,coulT);
            if (strcmp(param[3],"-1") == 0)
                SetBkMode(hdc,TRANSPARENT);
            else {
                SetBkMode(hdc,OPAQUE);
                SetBkColor(hdc,coulF);
            }
            /** Dessin **/
            int x=0,y=0;
            x=atoi(param[4]);
            y=atoi(param[5]);
            TextOut(hdc,x,y,param[1],strlen(param[1]));
        }
        free(param);
    }
    fclose(B_Pic);
}
/** Dessin de l'écran **/
void pEcran(HWND hDlg,int cx,int cy,bool draw) {
    PAINTSTRUCT ps;
    HDC Hdc=BeginPaint(hDlg,&ps);
    /** Calculs **/
    cx=GetSystemMetrics(SM_CXSCREEN);
    cy=GetSystemMetrics(SM_CYSCREEN);
    float diff2=cx/120;
    int diff=(int)diff2;
    /** Bord de l'écran **/
    RoundRect(Hdc,180,10,300,cy/diff+10,10,10);
    /** Pied de l'écran **/
    Rectangle(Hdc,210,cy/diff+20,270,cy/diff+25);
    Rectangle(Hdc,220,cy/diff+10,260,cy/diff+21);
    /** Ecran **/
    Rectangle(Hdc,185,15,295,cy/diff+5);
    if (!draw) {
        HFONT NewFont,OldFont;
        LOGFONT lf;
        ZeroMemory(&lf,sizeof(LOGFONT));
        lstrcpy(lf.lfFaceName,"Arial");
        lf.lfHeight=12;
        NewFont=CreateFontIndirect(&lf);
        OldFont=(HFONT)SelectObject(Hdc,NewFont);
        SetBkMode(Hdc,TRANSPARENT);
        TextOut(Hdc,195,30,"Fenêtre MDI incluse",strlen("Fenêtre MDI incluse"));
        TextOut(Hdc,215,40,"dans mIRC",strlen("dans mIRC"));
        DeleteObject(NewFont);
        EndPaint(hDlg,&ps);
        return;
    }
    RECT rect;
    rect.left=186;
    rect.top=16;
    rect.right=294;
    rect.bottom=cy/diff+4;
    HBRUSH brush=CreateSolidBrush(RGB(0,180,195));
    FillRect(Hdc,&rect,brush);
    /** Fenêtre **/
    Rectangle(Hdc,185,15,185+pX/diff,pY/diff+15);
    rect.left=186;
    rect.top=16;
    rect.right=184+pX/diff;
    rect.bottom=pY/diff+14;
    brush=CreateSolidBrush(RGB(150,150,150));
    FillRect(Hdc,&rect,brush);
    DeleteObject(brush);
    EndPaint(hDlg,&ps);
}
/** Box: Pic **/
BOOL APIENTRY BoxPic(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
    int cx=0,cy=0;
    switch(uMsg) {
        case WM_PAINT:
        {
            pEcran(hDlg,cx,cy,(IsDlgButtonChecked(hDlg,7))?TRUE:FALSE);
            break;
        }
        case WM_INITDIALOG:
        {
            cx=GetSystemMetrics(SM_CXSCREEN);
            cy=GetSystemMetrics(SM_CYSCREEN);
            char resol[]="";
            sprintf(resol,"%d x %d pixels",cx,cy);
            SetDlgItemText(hDlg,18,resol);
            sprintf(resol,"%d",pX);
            SetDlgItemText(hDlg,4,resol);
            sprintf(resol,"%d",pY);
            SetDlgItemText(hDlg,5,resol);
            SetDlgItemText(hDlg,2,"sans importance");
            SetDlgItemText(hDlg,3,"sans importance");
            SetDlgItemText(hDlg,1,pTitre);
            CheckDlgButton(hDlg,6,BST_CHECKED);
            CheckDlgButton(hDlg,7,BST_CHECKED);
            CheckDlgButton(hDlg,9,BST_CHECKED);
            CheckDlgButton(hwnd,13,BST_CHECKED);
            break;
        }
        case WM_COMMAND:
            if (HIWORD(wParam) == EN_CHANGE) {
                cx=GetSystemMetrics(SM_CXSCREEN);
                cy=GetSystemMetrics(SM_CYSCREEN);
                char resol[30]="";
                switch(LOWORD(wParam)){
                    case 1:
                        GetDlgItemText(hDlg,1,pTitre,30);
                        sprintf(resol,"@%s",pTitre);
                        SetWindowText(hMDIChild2,resol);
                        break;
                    /**case 4:
                        GetDlgItemText(hDlg,4,resol,30);
                        pX=atoi(resol)+8;
                        if (pX <= cx) {
                            pEcran(hDlg,cx,cy,(IsDlgButtonChecked(hDlg,7))?TRUE:FALSE);
                            InvalidateRect(hDlg,NULL,FALSE);
                            UpdateWindow(hDlg);
                            SetWindowPos(hMDIChild2,0,0,0,pX,pY,SWP_NOMOVE);
                        }
                        break;
                    case 5:
                        GetDlgItemText(hDlg,5,resol,30);
                        pY=atoi(resol)+34;
                        if (pY <= cx) {
                            pEcran(hDlg,cx,cy,(IsDlgButtonChecked(hDlg,7))?TRUE:FALSE);
                            InvalidateRect(hDlg,NULL,FALSE);
                            UpdateWindow(hDlg);
                        }
                        break;**/
                }
            }
            if (LOWORD(wParam)== 7) {
                //pEcran(hDlg,cx,cy,(IsDlgButtonChecked(hDlg,7))?TRUE:FALSE);
                InvalidateRect(hDlg,NULL,FALSE);
                UpdateWindow(hDlg);
                break;
            }
            break;
        case WM_CLOSE:
            EndDialog(hDlg,0);
            SetFocus(edit);
            break;
        default:
            return FALSE;
    }
}
/** Box: GenerePic **/
BOOL APIENTRY BoxGenerePic(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
    switch(uMsg) {
        case WM_INITDIALOG:
        {
            SetFocus(GetDlgItem(hDlg,1));
            FILE* B_Pic=fopen(fichierPicwin,"r");
            if (B_Pic == NULL)
                return 0;
            char ajout[50]="";
            char lecture[999]="",pChaine[9999]="",
            pChaine2[9999]="/*\r\n"
                "  Script de window généré par Galawa\r\n"
                "  (attention, votre couleur de background par défaut doit être le blanc pour des résultats optimisés)\r\n"
                "  Pour ouvrir la fenêtre, tapez /ma_fenetre\r\n"
                "*/\r\n\r\n"
                "alias ma_fenetre {\r\n"
                "  ;Ouverture de la fenêtre en mode 'desktop'\r\n"
                "  if ($windows(@";
            strcat(pChaine2,pTitre);
            strcat(pChaine2,")) window -c @");
            strcat(pChaine2,pTitre);
            strcat(pChaine2,"\r\n  window -pk");
            /** Ajout des propriétés de la picwin **/
            strcat(pChaine2,(IsDlgButtonChecked(pptPic,13))?"0":"1");
            if (IsDlgButtonChecked(pptPic,6))
                strcat(pChaine2,"a");
            if (IsDlgButtonChecked(pptPic,7))
                strcat(pChaine2,"d");
            if (IsDlgButtonChecked(pptPic,8))
                strcat(pChaine2,"o");
            if (IsDlgButtonChecked(pptPic,9))
                strcat(pChaine2,"C");
            if (IsDlgButtonChecked(pptPic,10))
                strcat(pChaine2,"n");
            if (IsDlgButtonChecked(pptPic,11))
                strcat(pChaine2,"x");
            if (IsDlgButtonChecked(pptPic,12))
                strcat(pChaine2,"h");
            if ((IsDlgButtonChecked(pptPic,13)) ||
                (IsDlgButtonChecked(pptPic,14)) ||
                (IsDlgButtonChecked(pptPic,15)) ||
                (IsDlgButtonChecked(pptPic,16)) ||
                (IsDlgButtonChecked(pptPic,17)))
                strcat(pChaine2," +");
            if (IsDlgButtonChecked(pptPic,14))
                strcat(pChaine2,"b");
            if (IsDlgButtonChecked(pptPic,15))
                strcat(pChaine2,"d");
            if (IsDlgButtonChecked(pptPic,16))
                strcat(pChaine2,"e");
            if (IsDlgButtonChecked(pptPic,17))
                strcat(pChaine2,"s");
            strcat(pChaine2," @");
            strcat(pChaine2,pTitre);
            strcat(pChaine2," -1 -1 ");
            sprintf(ajout,"%d %d",pX,pY);
            strcat(pChaine2,ajout);
            strcat(pChaine2,"\r\n  ;Ajout des éléments choisis\r\n");
            int compt=0;
            while (fgets(lecture,999,B_Pic) != NULL) {
                strcat(pChaine,lecture);
                strcat(pChaine,"\n");
                compt++;
            }
            fclose(B_Pic);
            char* add=strtok(pChaine,"\n");
            //char ajout[50]="";
            while (add != NULL) {
                char** param=split(add,"¶",0);
                //POINT <epaisseur> <[rouge] [vert] [bleu]> <x> <y> END\n
                if (strcmp(param[0],"POINT") == 0) {
                    int ep=atoi(param[1])/2;
                    sprintf(ajout,"  drawdot -r @%s $rgb(%s,%s,%s) %d %s %s\r\n",pTitre,param[2],param[3],param[4],ep,param[5],param[6]);
                    strcat(pChaine2,ajout);
                }
                //LIGNE <epaisseur> <[rouge] [vert] [bleu]> <x1> <y1> <x2> <y2> END\n
                else if (strcmp(param[0],"LIGNE") == 0) {
                    sprintf(ajout,"  drawline -r @%s $rgb(%s,%s,%s) %s %s %s %s %s\r\n",pTitre,param[2],param[3],param[4],param[1],param[5],param[6],param[7],param[8]);
                    strcat(pChaine2,ajout);
                }
                //RECTANGLE <epaisseur> <[rouge] [vert] [bleu]> <x1> <y1> <x2> <y2> <rempli> <ellipse> END\n
                else if (strcmp(param[0],"RECTANGLE") == 0) {
                    int Long1=atoi(param[5]);
                    int Long2=atoi(param[7]);
                    int Larg1=atoi(param[6]);
                    int Larg2=atoi(param[8]);
                    if (strcmp(param[9],"1") == 0)
                        sprintf(ajout,"  drawrect -rf @%s $rgb(%s,%s,%s) %s %s %s %d %d\r\n",pTitre,param[2],param[3],param[4],param[1],param[5],param[6],Long2-Long1,Larg2-Larg1);
                    else
                        sprintf(ajout,"  drawrect -r @%s $rgb(%s,%s,%s) %s %s %s %d %d\r\n",pTitre,param[2],param[3],param[4],param[1],param[5],param[6],Long2-Long1,Larg2-Larg1);
                    strcat(pChaine2,ajout);
                }
                //TEXTE <texte> <couleur (texte)> <couleur (fond)> <x> <y> END\n
                if (strcmp(param[0],"TEXTE") == 0) {
                    if (strcmp(param[3],"-1") == 0)
                        sprintf(ajout,"  drawtext -r @%s %s Arial 14 %s %s %s\r\n",pTitre,param[2],param[4],param[5],param[1]);
                    else
                        sprintf(ajout,"  drawtext -rb @%s %s %s Arial 14 %s %s %s\r\n",pTitre,param[2],param[3],param[4],param[5],param[1]);
                    strcat(pChaine2,ajout);
                }
                free(param);
                add=strtok(NULL,"\n");
            }
            strcat(pChaine2,"}");
            fclose(B_Pic);

            SetDlgItemText(hDlg,1,pChaine2);
            CHARRANGE fselect;
            fselect.cpMin=0;
            fselect.cpMax=5;
            SendMessage(GetDlgItem(hDlg,1),EM_EXSETSEL,0,(LPARAM)&fselect);
            SetFocus(GetDlgItem(hDlg,1));
            SendMessage(GetDlgItem(hDlg,1),SCI_COPY,0,0);
            break;
        }
        case WM_COMMAND:
            if (LOWORD(wParam) == 3) {
                EndDialog(hDlg,0);
                SetFocus(edit);
            }
            break;
        case WM_CLOSE:
            EndDialog(hDlg,0);
            SetFocus(edit);
            break;
        default:
            return FALSE;
    }
}
/** Box: Texte (picwin) **/
BOOL APIENTRY BoxTexte(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
    char TextC[100]="";
    switch(uMsg) {
        case WM_INITDIALOG:
            SetFocus(GetDlgItem(hDlg,2));
            break;
        case WM_PAINT:
            DrawButton(hDlg,newColorT,newColorF);
            break;
        case WM_COMMAND:
            switch(LOWORD(wParam)) {
                case 3:
                    EnableWindow(GetDlgItem(hDlg,6),(IsDlgButtonChecked(hDlg,3))?TRUE:FALSE);
                    InvalidateRect(hDlg,NULL,FALSE);
                    UpdateWindow(hDlg);
                    break;
                case 5:
                    newColorT=ColorChoose(hDlg,RGB(0,0,0));
                    InvalidateRect(hDlg,NULL,FALSE);
                    UpdateWindow(hDlg);
                    break;
                case 6:
                    newColorF=ColorChoose(hDlg,RGB(255,255,255));
                    InvalidateRect(hDlg,NULL,FALSE);
                    UpdateWindow(hDlg);
                    break;
                case 2:
                    if (HIWORD(wParam) == EN_CHANGE) {
                        GetWindowText(GetDlgItem(hDlg,2),TextC,sizeof(TextC));
                        if (strcmp(TextC,"") != 0)
                            EnableWindow(GetDlgItem(hDlg,1),TRUE);
                        else
                            EnableWindow(GetDlgItem(hDlg,1),FALSE);
                    }
                    break;
                case 1:
                {
                    pTexte[100]=GetWindowText(GetDlgItem(hDlg,2),pTexte,sizeof(pTexte));
                    pTexteBOOL=1;
                    pFondBOOL=(IsDlgButtonChecked(hDlg,3))?1:0;
                    char erer[]="0"; sprintf(erer,"%d",(int)RGB(255,255,255)); SendMessage(bStatus,SB_SETTEXT,0,(LPARAM)erer);
                    EndDialog(hDlg,0);
                    SetFocus(edit);
                    break;
                }
                case 4:
                    pTexteBOOL=0;
                    pFondBOOL=0;
                    EndDialog(hDlg,0);
                    SendMessage(htb3,TB_CHECKBUTTON,301,TRUE);
                    break;
            }
            break;
        case WM_CLOSE:
            EndDialog(hDlg,0);
            SetFocus(edit);
            break;
        default:
            return FALSE;
    }
}
void DrawVisio(HWND hDlg) {
    PAINTSTRUCT ps2;
    HDC hdc2=BeginPaint(hDlg,&ps2);
    HPEN hp2px2,hpOld2;
    char ep[4]="";
    GetWindowText(pTaille,ep,4);
    int epaisseur2=atoi(ep);
    if ((epaisseur2 <= 1) && (!SendMessage(htb3,TB_ISBUTTONCHECKED,303,0)) && (!SendMessage(htb3,TB_ISBUTTONCHECKED,304,0)))
        epaisseur2=2;
    COULEUR co2;
    co2.r=(GetWindowText(pRouge,ep,4))?atoi(ep):0;
    co2.v=(GetWindowText(pVert,ep,4))?atoi(ep):0;
    co2.b=(GetWindowText(pBleu,ep,4))?atoi(ep):0;
    Rectangle(hdc2,-1,-1,102,102);
    hp2px2=CreatePen(PS_SOLID,epaisseur2,RGB(co2.r,co2.v,co2.b));
    hpOld2=(HPEN)SelectObject(hdc2,hp2px2);
    /** Ligne **/
    if (SendMessage(htb3,TB_ISBUTTONCHECKED,303,0)) {
        MoveToEx(hdc2,20,20,NULL);
        LineTo(hdc2,80,80);
    }
    /** Rectangle **/
    else if (SendMessage(htb3,TB_ISBUTTONCHECKED,304,0)) {
        Rectangle(hdc2,20,20,80,80);
        if (IsDlgButtonChecked(hwnd,ID_PREMPLI)) {
            RECT rect;
            rect.left=20;
            rect.top=20;
            rect.right=80;
            rect.bottom=80;
            HBRUSH brush=CreateSolidBrush(RGB(co.r,co.v,co.b));
            FillRect(hdc2,&rect,brush);
            DeleteObject(brush);
        }
    }
    /** Point **/
    else {
        MoveToEx(hdc2,50,50,NULL);
        LineTo(hdc2,50,50);
    }
    EndPaint(hDlg,&ps2);
}
/** Box: GenerePic **/
BOOL APIENTRY BoxVisio(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
    switch(uMsg) {
        case WM_COMMAND:
            if (LOWORD(wParam) == 3) {
                EndDialog(hDlg,0);
                SetFocus(edit);
            }
            break;
        case WM_PAINT:
            DrawVisio(hDlg);
            break;
        case WM_CLOSE:
            EndDialog(hDlg,0);
            SetFocus(edit);
            break;
        default:
            return FALSE;
    }
}
/******************************************************************************/
LRESULT CALLBACK ChildProc2(HWND hChild,UINT Message,WPARAM wParam,LPARAM lParam) {
    if ((Message != WM_MOUSEMOVE) && (Message != WM_PAINT)) {
        PAINTSTRUCT ps;
        HDC hdc=BeginPaint(hChild,&ps);
        HFONT NewFont,OldFont;
        LOGFONT lf;
        ZeroMemory(&lf,sizeof(LOGFONT));
        lstrcpy(lf.lfFaceName,"Arial");
        lf.lfHeight=15;
        NewFont=CreateFontIndirect(&lf);
        OldFont=(HFONT)SelectObject(hdc,NewFont);
        DrawToFile(hChild,hdc);
        DeleteObject(NewFont);
        EndPaint(hChild,&ps);
    }
    switch(Message) {
        case WM_CLOSE:
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        case WM_LBUTTONDOWN:
            /** Mise en place du pinceau **/
            GetCursorPos(&souris);
            RECT area;
            GetWindowRect(hChild,&area);
            PosDepart_x=souris.x-area.left-3;
            PosDepart_y=souris.y-area.top-30;
            /** Dessin d'un point (1/2) **/
            if (SendMessage(htb3,TB_ISBUTTONCHECKED,302,0)) {
                InvalidateRect(hChild,NULL,FALSE);
                UpdateWindow(hChild);
            }
            break;
        case WM_LBUTTONUP:{
            char ep[4]="";
            GetWindowText(pTaille,ep,4);
            epaisseur=atoi(ep);
            co.r=(GetWindowText(pRouge,ep,4))?atoi(ep):0;
            co.v=(GetWindowText(pVert,ep,4))?atoi(ep):0;
            co.b=(GetWindowText(pBleu,ep,4))?atoi(ep):0;
            /** Sauvegarde de la fenêtre **/
            FILE* B_Pic=fopen(fichierPicwin,"a");
            if (SendMessage(htb3,TB_ISBUTTONCHECKED,302,0))
                //POINT <epaisseur> <[rouge] [vert] [bleu]> <x> <y> END\n
                fprintf(B_Pic,"POINT¶%d¶%d¶%d¶%d¶%d¶%d¶END\n",((epaisseur <= 1) && (!SendMessage(htb3,TB_ISBUTTONCHECKED,303,0)) && (!SendMessage(htb3,TB_ISBUTTONCHECKED,304,0)))?2:epaisseur,
                    co.r,co.v,co.b,PosDepart_x,PosDepart_y,FALSE);
            else if (SendMessage(htb3,TB_ISBUTTONCHECKED,303,0))
                //LIGNE <epaisseur> <[rouge] [vert] [bleu]> <x1> <y1> <x2> <y2> END\n
                fprintf(B_Pic,"LIGNE¶%d¶%d¶%d¶%d¶%d¶%d¶%d¶%d¶END\n",epaisseur,co.r,co.v,co.b,PosDepart_x,PosDepart_y,PosFin_x,PosFin_y);
            else if (SendMessage(htb3,TB_ISBUTTONCHECKED,304,0)) {
                //RECTANGLE <epaisseur> <[rouge] [vert] [bleu]> <x1> <y1> <x2> <y2> <rempli> <ellipse> END\n
                int remp=(IsDlgButtonChecked(hwnd,ID_PREMPLI))?1:0;
                fprintf(B_Pic,"RECTANGLE¶%d¶%d¶%d¶%d¶%d¶%d¶%d¶%d¶%d¶0¶END\n",epaisseur,co.r,co.v,co.b,PosDepart_x,PosDepart_y,PosFin_x,PosFin_y,remp);
            }
            else if (SendMessage(htb3,TB_ISBUTTONCHECKED,305,0)) {
                //TEXTE <texte> <couleur (texte)> <couleur (fond)> <x> <y> END\n
                fprintf(B_Pic,"TEXTE¶%s¶%d¶%d¶%d¶%d¶END\n",pTexte,newColorT,(pFondBOOL == 1)?newColorF:(int)-1,PosFin_x,PosFin_y);
            }
            fclose(B_Pic);
            /**/
            pTexteBOOL=0;
            pFondBOOL=0;
            SendMessage(htb3,TB_CHECKBUTTON,301,TRUE);
            EnableWindow(pRempli,FALSE);
            SetClassLong(hChild,GCL_HCURSOR,(LONG)LoadCursor(NULL,IDC_ARROW));
            break; }
        case WM_MOUSEMOVE:
        {
            char mesure[]="0";
            sprintf(mesure,"%d\t%d",LOWORD(lParam),HIWORD(lParam));
            SetWindowText(pInfos1,mesure);
            /**/
            if (pTexteBOOL == 1) {
                VerifPicwin(hChild,LOWORD(lParam),HIWORD(lParam));
                InvalidateRect(hChild,NULL,FALSE);
                UpdateWindow(hChild);
            }
            if (wParam == MK_LBUTTON) {
                char mesure[]="0";
                sprintf(mesure,"%d\t%d",LOWORD(lParam)-pDrag_x,HIWORD(lParam)-pDrag_y);
                SetWindowText(pInfos2,mesure);
                /**/
                if (!SendMessage(htb3,TB_ISBUTTONCHECKED,302,0))
                    VerifPicwin(hChild,LOWORD(lParam),HIWORD(lParam));
                InvalidateRect(hChild,NULL,FALSE);
                UpdateWindow(hChild);
            }
            else {
                SetWindowText(pInfos2,"0\t0");
                pDrag_x=LOWORD(lParam);
                pDrag_y=HIWORD(lParam);
            }
            break;
        }
        case WM_RBUTTONUP:
            //pptPic=CreateDialog(hinstance,"BoxPic",hwnd,(DLGPROC)BoxPic);
            ShowWindow(pptPic,SW_SHOW);
            break;
        case WM_PAINT:
            VerifPicwin(hChild,PosFin_x,PosFin_y);
            break;
        case WM_SIZE:
        {
            if (wParam == SIZE_MAXIMIZED)
                MoveWindow(hChild,0,0,cX-210,cY-64,TRUE);
            pX=LOWORD(lParam)+8;
            pY=HIWORD(lParam)+34;
            /** Remplissage des editbox **/
            char resol[]="";
            sprintf(resol,"%d",pX);
            SetDlgItemText(pptPic,4,resol);
            sprintf(resol,"%d",pY);
            SetDlgItemText(pptPic,5,resol);
            /** Dessin de l'écran **/
            InvalidateRect(pptPic,NULL,FALSE);
            UpdateWindow(pptPic);
            break;
        }
        default:
            return DefMDIChildProc(hChild,Message,wParam,lParam);
	}
}

Conclusion :


Voilà, j'attends vos remarques.
Aussi, je sais que mettrela moitié des fonctions dans des headers (.h) est un tord, mais je n'ai pas réussi à faire le petit effort pour changer les extensions :s

A plus, dans l'bus.

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.