Run MFC Program Without Dialog Showing
-
Hi, dear all, I have a MFC program which do some calculation, store in a file, then plot the results to a graphic on dialog. Now I have another program which only want to use the calculation result stored in file from above MFC program but don't want to show the dialog, how can I do it? I modify the codes in InitInstance() as below: m_pMainWnd->ShowWindow(SW_HIDE); m_pMainWnd->UpdateWindow(); return FALSE; the dialog is not shown, but user still can see the dialog flush before hiding, how can I avoid it? Thanks!
-
Hi, dear all, I have a MFC program which do some calculation, store in a file, then plot the results to a graphic on dialog. Now I have another program which only want to use the calculation result stored in file from above MFC program but don't want to show the dialog, how can I do it? I modify the codes in InitInstance() as below: m_pMainWnd->ShowWindow(SW_HIDE); m_pMainWnd->UpdateWindow(); return FALSE; the dialog is not shown, but user still can see the dialog flush before hiding, how can I avoid it? Thanks!
Maybe you could give the window zero width and height before it's shown.
-
Maybe you could give the window zero width and height before it's shown.
-
Hmm... Maybe you could try: ShowWindow(SW_MINIMIZE);
-
Hi, dear all, I have a MFC program which do some calculation, store in a file, then plot the results to a graphic on dialog. Now I have another program which only want to use the calculation result stored in file from above MFC program but don't want to show the dialog, how can I do it? I modify the codes in InitInstance() as below: m_pMainWnd->ShowWindow(SW_HIDE); m_pMainWnd->UpdateWindow(); return FALSE; the dialog is not shown, but user still can see the dialog flush before hiding, how can I avoid it? Thanks!
-
Hmm... Maybe you could try: ShowWindow(SW_MINIMIZE);
-
Take the calculation code and move it to a separate source file so you can add it to different projects.
Veni, vidi, abiit domum
-
Richard, Thanks for reply. the existing program is used by several projects, soome want the dialog, some not. so I just want to pass a argument to indicate show dialog or not.
OK, so accept a parameter and if it's false do not show the dialog, something like:
int APIENTRY WinMain(HINSTANCE hInstance, // instance value of the invoked application
HINSTANCE hPrevInstance, // no longer used
PSTR pszCmdLine, // pointer to the MS-DOS command line
int nCmdShow // value indicating initial state of the window
)
{
BOOL myParameter;
// get the parameter from the command line and convert to BOOLif (myParameter == TRUE) { DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD\_DLG), NULL, (DLGPROC)DlgProc, NULL ); } else { // call the function to calculate and write the file } return TRUE;
}
Where is the problem?
Veni, vidi, abiit domum
-
I try it, but you can see the process that the dialog is minimized, that's not what I expected. Thanks!
Another idea: Use this: http://msdn.microsoft.com/en-us/library/kc4ez6dk%28v=vs.90%29.aspx[^] to lock the window while you bring up the dialog, with the window hidden. LockWindowUpdate may prevent the flash while the dialog is displayed then hidden.
-
OK, so accept a parameter and if it's false do not show the dialog, something like:
int APIENTRY WinMain(HINSTANCE hInstance, // instance value of the invoked application
HINSTANCE hPrevInstance, // no longer used
PSTR pszCmdLine, // pointer to the MS-DOS command line
int nCmdShow // value indicating initial state of the window
)
{
BOOL myParameter;
// get the parameter from the command line and convert to BOOLif (myParameter == TRUE) { DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD\_DLG), NULL, (DLGPROC)DlgProc, NULL ); } else { // call the function to calculate and write the file } return TRUE;
}
Where is the problem?
Veni, vidi, abiit domum
Following Richard's idea , if you program based on MFC Dialog , I think you can change InitialInstance() like this ...........
BOOL myParameter; CMFCApplication4Dlg \*pMainWnd = new CMFCApplication4Dlg; if(myParameter) // need a dialog { pMainWnd->DoModal(); }else { // needn't a dialog pMainWnd->CreateEx(NULL,\_T("STATIC"), L"Hi", **WS\_BORDER** , //WS\_VISIBLE is not need CRect(-15, -15, -15, -15), NULL,NULL); // start a thread which include **while** loop, // that can keep dialog running until you stop it by yourself // otherwise the programe will exit very quickly }
........
-
Following Richard's idea , if you program based on MFC Dialog , I think you can change InitialInstance() like this ...........
BOOL myParameter; CMFCApplication4Dlg \*pMainWnd = new CMFCApplication4Dlg; if(myParameter) // need a dialog { pMainWnd->DoModal(); }else { // needn't a dialog pMainWnd->CreateEx(NULL,\_T("STATIC"), L"Hi", **WS\_BORDER** , //WS\_VISIBLE is not need CRect(-15, -15, -15, -15), NULL,NULL); // start a thread which include **while** loop, // that can keep dialog running until you stop it by yourself // otherwise the programe will exit very quickly }
........
I wouldn't create the main window at all if no Dialog/MainFrame is needed. Just call the class doing the processing from InitInstance(), if no window is requested. The program will end automatically when the processing is complete. In case of the windowed mode you can start the same processing from a button click or menu item click.
The good thing about pessimism is, that you are always either right or pleasently surprised.
-
Hi, dear all, I have a MFC program which do some calculation, store in a file, then plot the results to a graphic on dialog. Now I have another program which only want to use the calculation result stored in file from above MFC program but don't want to show the dialog, how can I do it? I modify the codes in InitInstance() as below: m_pMainWnd->ShowWindow(SW_HIDE); m_pMainWnd->UpdateWindow(); return FALSE; the dialog is not shown, but user still can see the dialog flush before hiding, how can I avoid it? Thanks!
Hi, dear all, I solve this issue, thanks for all of you for your help. inside InitInstance() function m_nCmdShow = SW_HIDE; CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); ......... ....... ....... m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return FALSE;
-
Hi, dear all, I have a MFC program which do some calculation, store in a file, then plot the results to a graphic on dialog. Now I have another program which only want to use the calculation result stored in file from above MFC program but don't want to show the dialog, how can I do it? I modify the codes in InitInstance() as below: m_pMainWnd->ShowWindow(SW_HIDE); m_pMainWnd->UpdateWindow(); return FALSE; the dialog is not shown, but user still can see the dialog flush before hiding, how can I avoid it? Thanks!
Andraw111 wrote:
Now I have another program which only want to use the calculation result stored in file
Then why are you creating such overhead by making it an MFC app? Why not just create a console app with a hidden window? My guess would be 10-15 lines of code within
main()
."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
Hi, dear all, I solve this issue, thanks for all of you for your help. inside InitInstance() function m_nCmdShow = SW_HIDE; CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); ......... ....... ....... m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return FALSE;
It seems no different compared with your original version. why it works?