2008-10-09 6 views
2

J'ai utilisé l'Assistant Application de Visual Studio pour créer un programme MFC squelette avec une interface multi-document. Lorsque je démarre ce programme, il crée automatiquement un cadre enfant, ce que je ne veux pas qu'il fasse - J'ai besoin que la zone client du cadre principal soit vide jusqu'à ce que l'utilisateur choisisse d'ouvrir un fichier. Le débogueur m'indique qu'un objet CChildFrame est créé lorsque la fonction InitInstance() de la classe d'application appelle ProcessShellCommand(), mais qu'est-ce qu'un bon point d'entrée pour remplacer ce comportement?Comment puis-je empêcher mon application MFC d'appeler OnFileNew() au démarrage?

Répondre

3

Cela a fonctionné pour moi - changement

if (!ProcessShellCommand(cmdInfo)) 

à

if (cmdInfo.m_nShellCommand != CCommandLineInfo::FileNew && !ProcessShellCommand(cmdInfo)) 

dans la fonction InitInstance() de votre application.

+0

Merci, je vais essayer. –

+0

Ça marche! Mais ignorer complètement ProcessShellCommand() aura-t-il des conséquences indésirables? Que fait cette fonction? (J'ai échoué à trouver sa définition dans mon projet.) –

+0

Je l'ai cherché dans les documents Visual Studio, et il semble que toute la fonction est de traiter le paramètre, donc c'est génial. Merci encore. –

1

Ignorer l'appel ProcessShellCommand() (dans le cas de FileNew) dans InitInstance() est en effet le chemin à parcourir.

5

Cela fonctionne, il maintient l'impression/ouverture de la coquille, etc.

// Parse command line for standard shell commands, DDE, file open 
CCommandLineInfo cmdInfo; 
ParseCommandLine(cmdInfo); 

if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew) 
{ 
    cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing ; 
} 

// Dispatch commands specified on the command line 
if (!ProcessShellCommand(cmdInfo)) 
    return FALSE; 
+0

Je pense que cela équivaut à la réponse de jeffm. C'est plus long mais plus clair, et c'est plus proche de ce que j'ai fini par faire. –

1

Faites une chose ..

dans votre fichier XXXApp.cpp

dans cette méthode: -

commenter la ligne suivante .. /*

CCommandLineInfo cmdInfo; 
ParseCommandLine(cmdInfo); 

// Dispatch commands specified on the command line. Will return FALSE if 
// app was launched with /RegServer, /Register, /Unregserver or /Unregister. 
if (!ProcessShellCommand(cmdInfo)) 
    return; 

*/

comme ça ....

Questions connexes