Solved

MFC DLL.

Posted on 2004-04-05
8
2,432 Views
Last Modified: 2013-11-25
Hi,
   I need to write an MFC Dialog that communicates with a delphi program. The delphi program is the master which will call up this MFC dialog and communicate with it via windows messages. The delphi program and the MFC dialog must run in parallel.

I wrote the MFC Dialog as an MFC regular DLL. The dialog is created at the initinstance of the winApp in the MFC DLL.
However, the MFC Dialog does not seem to have its own message queue becoz it is not refreshed. What is the correct way to do this?

Thanks.


0
Comment
Question by:pcssecure
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 125 total points
ID: 10763023
Is it a modal or modeless dialog box? Modal dialog requires a valid parent window to be modal. Check out

How to Create a Modal Dialog from Within a USRDLL
http://support.microsoft.com/default.aspx?scid=kb;en-us;121947
0
 

Author Comment

by:pcssecure
ID: 10763289
Modeless. Modal is not applicable because if the Dialog is modal, the master delphi program will not be able to continue until the user clicks on the OK button.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 10763837
Hi,
What do you mean by "it is not refreshed"? Do you send some 'refreshing' messages to the dialog and it doesn't react?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:pcssecure
ID: 10763871
Let me rephrase the question.

I need to do some number crunching in a win32 console program and update a dialog as the number crunching progresses. Also, I want to write the modeless CDialog as a MFC regular DLL. How can I achieve this?

Do I need to create a separate thread for the message pump of the MFC DLL?
As it is now, when I add a message pump (while loop) to the winApp class, it seem to be taking up all the processing time and I am not able to return to the number crunching program to do my data processing.

How do I make the MFC DLL's message pump run on a separate thread?

Please advise.

Thanks.
0
 
LVL 15

Assisted Solution

by:lakshman_ce
lakshman_ce earned 125 total points
ID: 10765949
>Do I need to create a separate thread for the message pump of the MFC DLL?
Have your own class derived from CWinThread and have a class derived from CFrameWnd. Associate your CFramewnd derived class with your modelless dialog. And in the initinstance of CWinThread derived class call show dialog. Add required message handlers to your CWinThread derived class.
Please refer to the following links for more info
http://www.codersource.net/mfc_tutorial_Part1.html
http://www.codersource.net/mfc_tutorial_Part2.html
http://www.codersource.net/mfc_user_interface_thread.html

-Lakshman
0
 
LVL 23

Expert Comment

by:chensu
ID: 10767503
>Do I need to create a separate thread for the message pump of the MFC DLL?

No. Why do you think it is a message pump problem? What exactly is the problem? Please respond to nonubik's question.
0
 

Author Comment

by:pcssecure
ID: 10773027
Thanks for all the help.

Lakshman: Do I still need to do all that if I am already wusing CWinApp? As far as i know, CWinApp is derived from CWinThread.

ChenSu: I think (though I am not sure) it is a message pump problem because i read from MSDN that for a modeless dialog in a MFC regular DLL, the message pump is owned by the application calling it.

The paragraph below is from MSDN TN011.
"Note that the CWinApp::Run mechanism doesn't apply to a DLL, since the application owns the main message pump. If your DLL brings up modeless dialogs or has a main frame window of its own, your application's main message pump must call a DLL-exported routine that calls CWinApp::PreTranslateMessage."

In my case, the win32 console program calling the MFC Dialog in the regular DLL does not have any message pump. What do I do?

Thanks.
0
 
LVL 23

Assisted Solution

by:chensu
chensu earned 125 total points
ID: 10776372
Now I understand what you are doing. I answered a similar question.

http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20909513.html

Check out

ConGui: Sample for Console I/O with GUI I/O
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample98/html/vcsmpcongui.asp

"The ConGui sample demonstrates how a standard console application can take advantage of some of the graphical capabilities of Windows NT.

Caution   This sample application illustrates a method by which a console application can utilize some (but not all) of the graphical user interface (GUI) capabilities of the Win32 API. It was not the original design intention of the Console layer of Windows NT to allow it to interact in this manner with the graphical API, and because of this, problems can occur if you try to accomplish too much. Therefore, exercise restraint in using the graphical Win32 API in your console application. If your needs go beyond the simple methods illustrated here, consider designing your application as a full GUI application."
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java ^ examples 8 70
fix34  challenge 9 164
ClickOnce Install - Shortcut Question 3 108
Excel file not created as expected 7 90
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question