Réalisé avec Microsoft Visual C++ .NET
CREATION DU PROJET
- Nouveau projet (nommé "test" ici)
- MFC > Application MFC
- Type d'application > Basée sur une boîte de dialogue
- Fonctionnalités de l'interface utilisateur :
- Bouton Réduire
- Bouton Agrandir
- Menu Système
- Boîte de dialogue A propos de
ORGANISATION DE L'INTERFACE
- Supprimer tous les éléments de IDD_TEST_DIALOG (voir affichage des ressources)
- Bouton OK
- Bouton Annuler
- Texte "TODO : ..."
- Etendre le rectangle bleu (limite des composants) aux 4 coins
- Clic droit au centre > Inserer un contrôle ActiveX > Shockwave Flash Object
- Etirer l'object aux 4 coins
- Clic droit sur le contrôle > Ajouter une variable > Nom de variable : m_flash
- Selectionner le contrôle > Propriétés > Evènement de contrôle
- FSCommand : Selectionner "
FSCommandShockwaveflash1"
- Selectionner la fenêtre (barre de titre) > Propriétés > Messages
- WM_SIZE > Sélectionner " OnSize"
- WM_SIZING > Sélectionner " OnSizing"
- Selectionner la fenêtre (barre de titre) > Propriétés > Propriétés > Apparence
- Border : Resizing
CHARGEMENT DU FLASH
- ouvrir le fichier testDlg.cpp,
- aller au "TODO" de la fonction CtestDlg::OnInitDialog
- ajouter le code suivant :
// Charge le swf depuis le repertoire courant
char currentDir[2048];
GetCurrentDirectory(2047, currentDir);
CString swfPath = currentDir;
swfPath = "file://" + swfPath + "/test.swf";
m_flash.put_Movie(swfPath);
// Redimensionne la fenêtre et le contrôle flash aux dimensions du swf
CRect clientRect, windowRect;
GetClientRect(&clientRect);
GetWindowRect(&windowRect);
long windowW = windowRect.right - windowRect.left + 1;
long windowH = windowRect.bottom - windowRect.top + 1;
long clientW = clientRect.right - clientRect.left + 1;
long clientH = clientRect.bottom - clientRect.top + 1;
long marginW = windowW - clientW;
long marginH = windowH - clientH;
long flashW = atol(m_flash.GetVariable("width"));
long flashH = atol(m_flash.GetVariable("height"));
long newWinW = flashW + marginW;
long newWinH = flashH + marginH;
windowRect.right = windowRect.left + newWinW -1;
windowRect.bottom = windowRect.top + newWinH -1;
clientRect.right = flashW;
clientRect.bottom = flashH;
MoveWindow(windowRect, 1);
m_flash.MoveWindow(clientRect, 1);
CenterWindow();
MINIMISER ET MAXIMISER LA FENETRE
- aller au "TODO" de la fonction CtestDlg::OnSize
- ajouter le code suivant :
// Minimiser & maximiser
static bool init = false;
if (init)
{
CRect clientRect;
GetClientRect(&clientRect);
m_flash.MoveWindow(clientRect, 0);
}
init = true;
REDIMENSIONNER MANUELLEMENT LA FENETRE
- aller au "TODO" de la fonction CtestDlg::OnSizing
- ajouter le code suivant :
// Redimensionner
static bool init = false;
if (init)
{
CRect clientRect;
GetClientRect(&clientRect);
m_flash.MoveWindow(clientRect, 0);
}
init = true;
RECEVOIR LES REQUETES DU FLASH, LES TRAITER ET REPONDRE
- aller au "TODO" de la fonction CtestDlg::FSCommandShockwaveflash1
- ajouter le code suivant :
// Traiter la requête
if (strcmp(command, "send")==0)
{
// votre code (après analyse des paramètres args si besoin)
// ...
// Acquitement
m_flash.SetVariable("MFCobjet.msg", "done");
}
// Quitter l'application
if (strcmp(command, "quit")==0)
OnCancel();
CODE DU FLASH : ENVOI DE DONNEES VERS LE CODE C
fscommand("send", "mes paramètres");
fscommand("exit");
fscommand("exec", "monappli.exe -mesparam"); // à coder dans le MFC
...
Attention > Maintenant, toutes les commandes de fscommand sont à traiter dans le MFC,
elles ne sont plus active par défaut
CODE DU FLASH : RECEPTION DE DONNEES DEPUID LE CODE C
// Création d'un object
MFCobjet = new Object();
MFCobjet.msg = "";
// appellé par le watch quand le paramètre surveillé change
MFCobjet_callback = function (prop, oldVal, newVal, userData)
{
// votre code (après analyse des paramètres newVal si besoin)
// ...
msg = newVal;
return newVal;
}
// paramètre "msg" de l'objet "MFCobjet" surveillé
MFCobjet.watch("msg", MFCobjet_callback);
Un exemple dans un précédent post : http://www.cppfrance.com/code.aspx?ID=36405