IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Visual C++ Discussion :

lancer une application par click sur son document


Sujet :

Visual C++

  1. #1
    Membre habitué
    Inscrit en
    Avril 2002
    Messages
    180
    Détails du profil
    Informations forums :
    Inscription : Avril 2002
    Messages : 180
    Points : 157
    Points
    157
    Par défaut lancer une application par click sur son document
    salut
    j'ai une application qui ecrit un document mon_app.ses

    je veut que avec un double click sur mon_app.ses ouvrire mon application et charger mon_app.ses. j'aurai crue que appret avoir associer l'extention ".ses" a mon application je receverait en argument une chaine de caractere "mon app.ses" mais ce que je recois est "/dde" ?

    comment est-ce que je pourait faire pour recuperer le nom du fichier qui a ouvert mon application soit "mon_app.ses" ???

    merci.

  2. #2
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    salut,
    quelle type d'application, MFC ?
    logiquement tu devrais avoir le fichier en argument..

  3. #3
    Membre habitué
    Inscrit en
    Avril 2002
    Messages
    180
    Détails du profil
    Informations forums :
    Inscription : Avril 2002
    Messages : 180
    Points : 157
    Points
    157
    Par défaut
    ces vraiment étrange
    tout est fait dans initinstance de mon app.
    si j'appel
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    RegisterShellFileTypes(FALSE)
    je recois le fichier et son chemin en parametre
    et si jappel
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    RegisterShellFileTypes(TRUE)
    je recois "/dde" en parametre

    pourtant le flag TRUE ne fait qu'ajouter des entré au registre pour pouvoir envoyer le fichier directement a une imprimente !!! ca ne devrait pas changer le comportement???

    autre comportement bizard qui vas surment me péter dans la gueule
    dans cette meme fonction InitInatanse j'appelle une fonction qui utilise
    GetModuleFileName(...)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
      TCHAR szFileMask[MAX_PATH+10];
      DWORD cch= GetModuleFileName( NULL, szFileMask, MAX_PATH);
      ASSERT(cch!=0);
      LPTSTR pszExtension= PathFindExtension(szFileMask);
      lstrcpy(pszExtension, _T("_???.dll"));
    si l'application est ouverte avec un doubleclic sur un document associer
    je recois dans szFileMask une chaine de caractere dasn un format resemblant a fat16 soit: C:\PROGRA~1\PLANT\PATRIO~1_???.dll

    si j'ouvre l'application directement en clickan sur l'executable ou bien en passant le fichier en parametre soit : PatriotMonitor.exe sesion.ses
    dans szFileMask j'ai : C:\Program Files\Plant\PatriotMonitor_???.dll

    pouriez vous m'éclairer sur ??? la raison du pourquoi que ???
    merci

  4. #4
    Membre habitué
    Inscrit en
    Avril 2002
    Messages
    180
    Détails du profil
    Informations forums :
    Inscription : Avril 2002
    Messages : 180
    Points : 157
    Points
    157
    Par défaut
    Bon filalement le probleme est que la methode CDocTemplate::RegisterShellFileTypes() recupere le chemin de l'executable avec la fonction AfxGetModuleShortFileName(...) soit au format : C:\PROGRA~1\PLANT\PATRIO~1...

    Pour resoudre mon probleme j'ai surcharger RegisterShellFileTypes() dans ma classe CMonApp. Bon ces un peut un hack et ca scrap la <<backward compatibilite>> mais je ne croie pas qu'il reste boucoup de system en fat16 anyway.

    le code done ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
     
    void CMonApp::RegisterShellFileTypes(BOOL bCompat)
    {
    	ASSERT(!m_templateList.IsEmpty());  // must have some doc templates
     
       const TCHAR SHELL_OPEN[]        = _T("%s\\shell\\open\\%s");
       const TCHAR SHELL_PRINT[]       = _T("%s\\shell\\print\\%s");
       const TCHAR SHELL_PRINTTO[]     = _T("%s\\shell\\printto\\%s");
       const TCHAR DEFAULT_ICON[]      = _T("%s\\DefaultIcon");
       const TCHAR SHELL_NEW[]         = _T("%s\\ShellNew"); 
       const TCHAR ICON_INDEX[]        = _T(",%d");
       const TCHAR COMMAND[]           = _T("command");
       const TCHAR OPEN_ARG[]          = _T(" \"%1\"");
       const TCHAR PRINT_ARG[]         = _T(" /p \"%1\"");
       const TCHAR PRINTTO_ARG[]       = _T(" /pt \"%1\" \"%2\" \"%3\" \"%4\"");
       const TCHAR DDE_ARG[]           = _T(" /dde"); 
       const TCHAR DDE_EXEC[]          = _T("ddeexec");
       const TCHAR DDE_OPEN[]          = _T("[open(\"%1\")]");
       const TCHAR DDE_PRINT[]         = _T("[print(\"%1\")]");
       const TCHAR DDE_PTINTTO[]       = _T("[printto(\"%1\",\"%2\",\"%3\",\"%4\")]"); 
       const TCHAR SHELL_NEW_NAME[]    = _T("NullFile");
       const TCHAR SHELL_NEW_VALUE[]   = _T(""); 
     
    	CString strTemp;
     
    	TCHAR strPathName[256];
    	GetModuleFileName(NULL,strPathName,255);
     
       POSITION pos = GetFirstDocTemplatePosition();
    	for (int nTemplateIndex = 1; pos != NULL; nTemplateIndex++)
    	{
    		//CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
          CDocTemplate* pTemplate = GetNextDocTemplate(pos);
    		CString strOpenCommandLine = strPathName;
    		CString strPrintCommandLine = strPathName;
    		CString strPrintToCommandLine = strPathName;
    		CString strDefaultIconCommandLine = strPathName;
     
    		if (bCompat)
    		{
    			CString strIconIndex;
    			HICON hIcon = ::ExtractIcon(AfxGetInstanceHandle(), strPathName, nTemplateIndex);
    			if (hIcon != NULL)
    			{
    				strIconIndex.Format(ICON_INDEX, nTemplateIndex);
    				DestroyIcon(hIcon);
    			}
    			else
    			{
    				strIconIndex.Format(ICON_INDEX, DEFAULT_ICON_INDEX);
    			}
    			strDefaultIconCommandLine += strIconIndex;
    		}
     
    		CString strFilterExt, strFileTypeId, strFileTypeName;
    		if (pTemplate->GetDocString(strFileTypeId,
    		   CDocTemplate::regFileTypeId) && !strFileTypeId.IsEmpty())
    		{
    			// enough info to register it
    			if (!pTemplate->GetDocString(strFileTypeName,
    			   CDocTemplate::regFileTypeName))
    				strFileTypeName = strFileTypeId;    // use id name
     
    			ASSERT(strFileTypeId.Find(' ') == -1);  // no spaces allowed
     
    			// first register the type ID of our server
    			if (!SetRegKey(strFileTypeId, strFileTypeName))
    				continue;       // just skip it
     
    			if (bCompat)
    			{
    				// path\DefaultIcon = path,1
    				strTemp.Format(DEFAULT_ICON, (LPCTSTR)strFileTypeId);
    				if (!SetRegKey(strTemp, strDefaultIconCommandLine))
    					continue;       // just skip it
    			}
     
    			// If MDI Application
    			if (!pTemplate->GetDocString(strTemp, CDocTemplate::windowTitle) ||
    				strTemp.IsEmpty())
    			{
    				// path\shell\open\ddeexec = [open("%1")]
    				strTemp.Format(SHELL_OPEN, (LPCTSTR)strFileTypeId,
    					(LPCTSTR)DDE_EXEC);
    				if (!SetRegKey(strTemp, DDE_OPEN))
    					continue;       // just skip it
     
    				if (bCompat)
    				{
    					// path\shell\print\ddeexec = [print("%1")]
    					strTemp.Format(SHELL_PRINT, (LPCTSTR)strFileTypeId,
    						(LPCTSTR)DDE_EXEC);
    					if (!SetRegKey(strTemp, DDE_PRINT))
    						continue;       // just skip it
     
    					// path\shell\printto\ddeexec = [printto("%1","%2","%3","%4")]
    					strTemp.Format(SHELL_PRINTTO, (LPCTSTR)strFileTypeId,
    						(LPCTSTR)DDE_EXEC);
    					if (!SetRegKey(strTemp, DDE_PTINTTO))
    						continue;       // just skip it
     
    					// path\shell\open\command = path /dde
    					// path\shell\print\command = path /dde
    					// path\shell\printto\command = path /dde
    					strOpenCommandLine += DDE_ARG;
    					strPrintCommandLine += DDE_ARG;
    					strPrintToCommandLine += DDE_ARG;
    				}
    				else
    				{
    					strOpenCommandLine += OPEN_ARG;
    				}
    			}
    			else
    			{
    				// path\shell\open\command = path filename
    				// path\shell\print\command = path /p filename
    				// path\shell\printto\command = path /pt filename printer driver port
    				strOpenCommandLine += OPEN_ARG;
    				if (bCompat)
    				{
    					strPrintCommandLine += PRINT_ARG;
    					strPrintToCommandLine += PRINTTO_ARG;
    				}
    			}
     
    			// path\shell\open\command = path filename
    			strTemp.Format(SHELL_OPEN, (LPCTSTR)strFileTypeId,
    				(LPCTSTR)COMMAND);
    			if (!SetRegKey(strTemp, strOpenCommandLine))
    				continue;       // just skip it
     
    			if (bCompat)
    			{
    				// path\shell\print\command = path /p filename
    				strTemp.Format(SHELL_PRINT, (LPCTSTR)strFileTypeId,
    					(LPCTSTR)COMMAND);
    				if (!SetRegKey(strTemp, strPrintCommandLine))
    					continue;       // just skip it
     
    				// path\shell\printto\command = path /pt filename printer driver port
    				strTemp.Format(SHELL_PRINTTO, (LPCTSTR)strFileTypeId,
    					(LPCTSTR)COMMAND);
    				if (!SetRegKey(strTemp, strPrintToCommandLine))
    					continue;       // just skip it
    			}
     
    			pTemplate->GetDocString(strFilterExt, CDocTemplate::filterExt);
    			if (!strFilterExt.IsEmpty())
    			{
    				ASSERT(strFilterExt[0] == '.');
     
    				LONG lSize = _MAX_PATH * 2;
    				LONG lResult = ::RegQueryValue(HKEY_CLASSES_ROOT, strFilterExt,
    					strTemp.GetBuffer(lSize), &lSize);
    				strTemp.ReleaseBuffer();
     
    				if (lResult != ERROR_SUCCESS || strTemp.IsEmpty() ||
    					strTemp != strFileTypeId)
    				{
    					// no association for that suffix
    					if (!SetRegKey(strFilterExt, strFileTypeId))
    						continue;
     
    					if (bCompat)
    					{
    						strTemp.Format(SHELL_NEW, (LPCTSTR)strFilterExt);
    						(void)SetRegKey(strTemp, SHELL_NEW_VALUE, SHELL_NEW_NAME);
    					}
    				}
    			}
    		}
    	}
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. lancer une application de Windows sur ubuntu
    Par fabricen26 dans le forum Ubuntu
    Réponses: 7
    Dernier message: 24/07/2013, 16h02
  2. Lancer une application au clic sur une notification
    Par K-you dans le forum Android
    Réponses: 4
    Dernier message: 08/06/2012, 13h18
  3. [débutant] lancer une application par la console
    Par LeBabouin dans le forum Ubuntu
    Réponses: 1
    Dernier message: 29/04/2008, 18h05
  4. Lancer une application par applet
    Par maikof dans le forum Applets
    Réponses: 3
    Dernier message: 18/10/2007, 17h26
  5. Réponses: 2
    Dernier message: 05/12/2003, 11h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo