VC++ - putting 2 application window into one program

May I know how should I start doing the coding pf a program such that two diferent windows can be run simultaneously? Please help me as I am a novice in this field.
Thank you.
cinderallaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

akalmaniCommented:
Hi !!

 Yes u can do it by creating 2 threads .
In the thread function u can create a window
U can use AfxBeginThread() function or BeginThread() anyone right now. If u could be clear i can tell u which one to use when.

LPVOID lpvoid;//Parameter to the function
AfxBeginThread(Functionname,lpvoid);

UINT Functionname(LPVOID lpvoid)
{
   Create()//Window Creation
}
0
nietodCommented:
>> Yes u can do it by creating 2 threads
Or by creating 100 threads.  Or by creating 1 thread.   The number of threads has NOTHING to do with it.

There is nothing special to be done.  Just create the 2 windows instead of 1.  
0
basantCommented:
Nietod is correct. Win16 didn't had threads even though you can create multiple windows.

Just Guess :

May be second window, you need to create as a Popupwindow. ( Again it depends on a need).

What kind of windows you want MDI or SDI.
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

nietodCommented:
>> May be second window, you need
>> to create as a Popupwindow
No, it can be an ordinary top-level window.

You can create two windows of the same class by calling CreateWindow() twice for the same window class, or you can create two windows of different classes by calling CreateWindow() for different window classes.  It doesn't matter.  There is no trick here.
0
andlaCommented:
Varing don't write code like this.

while(1)
{
Create....//window
}

If you do you would probely be suprised of all the window comming up.

A big varing.

don't create windows in a loop that is not a child of you application.
You would have to remove all windows manually.

:-)
0
TryCommented:
Start getting use to the terminology; just saying "windows" is not enough.

There are three basic types of windows:
1)  Overlapped
2)  Popup
3)  Child

Overlapped windows are usually reserved for your application's main window, and (in fact) are sometimes called, "Main" windows or "Frame" windows.

Popup windows are usually used to communicate with the user in the form od Dialog boxes and Message boxes.

Child windows are usually used in views such as the text display in a text editor and in controls such as the "OK" button in a Dialog box.  Another name for a Child window that looks like a button or any other control is a "Control" window.


As you can see, there are several types of windows and within one you can many others.  Therefore to say that you want to write a program that can run two different windows simultaneously, a simple dialog program can have a number of buttons which would all be windows.

What I think you mean (and it is NOT my style to second guess what people mean, but in this instance I think it is safe), is that you are referring to a Main window and a Child window.

The main difference between a Child window and an Overlapped window is that a Child window can only appear inside another window with a lot of the features an Overlapped window would normally have, such as a menu bar.  A Child window cannot have a menu bar, because then it wouldn't be a Child window.


Would you be using VC++?
0
nietodCommented:
>> What I think you mean is that you
>> are referring to a Main window and
>> a Child window.
I suspect he means two "main" windows, i.e. two top-level windows.

>> A Child window cannot have a menu
>> bar, because then it wouldn't be a
>> Child window.
Why?  There is no logical reason a child window can't have a menu.  i.e. there is no restriction due to the child window's bbehavior.  There is a restriction due to how windows impliments menus, but that can be circumvented.
0
TryCommented:
Allow me to clarify and correct myself on my earlier comment.

In the last paragraph, I stated that, "The main difference between a Child window and an Overlapped window is that a Child window can only appear inside another window."  That part is perfectly true.

The part I wish to correct is what I said about, "... with a lot of the features an Overlapped window would normally have, such as a menu bar."

What I meant to say, is, "... WITHOUT a lot of the features an Overlapped window would normally have, such as a menu bar.'

---------------------------------------

A Child window is usually USED in views.  A child window and a view window is synonymous.  It is confined to the client area of its parent window.  The view window has no visible elements except the text and graphics that the view class explicitly displays.  You will NEVER find a menu bar inside a client area, ... NEVER, NEVER, NEVER!!!  This is because when you create a child window, you give it an integer identifier.  You supply this integer identifier (instead of a menu handle) in the 'hmenu' parameter of the CreateWindow function.  This integer identifier and a menu handle are mutually exclusive.  You can only give one, and if it turns out to be the integer identifier, then it's a child window that's going to be created.  If you supply a menu handle, then it's a parent window that's going to be created.  If you use NULL, then it's the class menu that will be used and a parent window is what gets created.  You CANNOT physically supply both.  (I thought you knew that.)
0
andlaCommented:
Why not think about windows as different displayable tools (windows) that has different properties for you to play with. It is then up to the programmer to do what he pleases. It is always possible to hack so there are no waterproof rules. ?
0
TryCommented:
"andla" you're not making sense!

There are rules to follow, and if you want to break one or some of the rules (or deviate from them), don't blame anyone (and certainly NOT the computer nor the operating system) when things don't turn out the way you want them, or you find yourself stuck and don't know how to get out of the mess you're in.
0
andlaCommented:
Notice that i said waterproof rules. What i mean with waterproof is that there is no way to change it. But every move or change you make in your code gives new rules and can remove other rules.

For exsample (not a good one but makes my point)lets say you have a macro. If you start to change in your compiler directory where all .h files is. And makes changes to that macro to give it more power then i would say that this can change the original rule. (i did this only once without knowing what i did. I was lucky a few month later that i found that change. :-D)

0
TryCommented:
I am not going to comment about making changes to macros and what residual effects they may bring to bear as a consequnce.  I want to get back to "cinderella's" main question about creating two (or multiple) windows and have them run simultaneously.

"cinderella", I really don't want to second guess you here.  You will have to help me out and tell me what you really have in mind.  So let me give a few scenarios and you can  pick which one is more on target.  (I am only doing this because you stated you are a novice, and a little guidance may be all you need.)

First, to run anything 'simultaneously', you are talking about multiple threads (or even multiple processes; one process can be a child of another process).  However, such topic are considered more advanced for novices, which makes me believe 'simultaneous' processing is not what you really have in mind, but simply a parent window that has two (or more) children windows.  Each of those children windows can receive and display different renderings of the same data.  (Picture a database with a large collection of information for one record [let's say, 100 fields].  The information for the first 20 fields can be displayed on one child window, while information for the last 20 fields can be displayed on another child window, with still more fields [mixed, matched, whatever] being able to be displayed on yet other child windows.)  What you have is a single parent with multiple children, and you can activate any of those children anytime.  This is known as a Single Document Interface.

The next scenario is where you have many parents with one or more children (and each parent having the same setting as I've just described above) but where you have each of those individual parents getting their respective data from different databases (that distinction is important).  This is known as Multiple Document Interface.

Variations of either of these interfaces can be the result of the programmer's creativity, but in the end, they'd fall under one of those two categories (whether you have two separate top-level windows, or one parent window with two [or multiple] children views).

The point about 'simultaneous' execution, however, adds a whole different dimension to the picture, and is what is needful of further clarification.  Getting into that area is definitely more advanced.

If none of my sample descriptions fit what you have in mind, then could you explain your thoughts a little more?


NOTE:  Using VC++, Step 1 of AppWizard gives you the option of choosing a Single Document Interface as your method of constructing the framework for the Document/View architecture of the application you wish to create.  The wizard will automatically set you up with those codes.  If you wish to add a second view (etc.), let me know.


If you have any further questions, don't hesitate.
0
cinderallaAuthor Commented:
I guess I am sorry fro not explaining the situation correctly. I am doing a project on image acquisition and I have 2 seperate images. So, the job I have to do now is to write a program such that both image can be processed simultaneously.

Thank you for all the help.

0
andlaCommented:
Do you want to show two windows with each picture?

Do you have .h .lib .dll to show your image?
0
TryCommented:
Is this homework assignment?
0
TryCommented:
Will your data be coming from two separate sources, or from one?
0
cinderallaAuthor Commented:
dear try,
my data will be coming from 2 seperate sources and you don't have to worry whether if this a homework assignment.

Thank you
0
TryCommented:
Because your data will be coming from two separate sources, your best choice is to develop an MDI application.  This is the default in Step 1 of AppWizard.

After AppWizard has generated your basic MDI application, it is ready to be used (though not to the extent you want it to be) and just from that setup, you can generate or read as many documents as you'd like by choosing New/Open from the File Menu.  (You are interested in only two documents, so that's all you'll generate.)

The views for these documents will appear in their respective child frame window, which you can activate by clicking on it (the view) or by pressing Ctrl-Tab, or Ctrl-F6 to go to the next view (use Ctrl-Shift-Tab to activate the previous child window).  You can also activate a specific child frame window by choosing its title from the Window Menu.

The type of view you'll want is CScrollView and the document type is binary; flat file (be it of 'bmp', 'tiff', or 'jpg' format).

You will need three threads:  a GUI thread and two worker threads.  The GUI thread will be the one controlling which worker thread gets activated, and can either be a separate GUI thread or the application main thread.  The two worker threads will be responsible for the application's individual image processing activities.  These worker threads can be created WHEN the documents are created (this means you will have to direct the code for the creation of these threads where activity shows the documents are being created.)

An MDI program's document class stores the document data and performs file I/O.  However, unlike an SDI application, the MDI program creates a separate instance of this class for each document it opens (rather than reusing a single one as in the case of the SDI application).

For your MDI application, AppWizard will generate an application class, a document class, a main frame class, a view class, and a child frame window class.

On the matter of threads, use the "CWinThread* AfxBeginThread()" function to create your threads.  DO NOT use CreateThread() nor _beginthreadex().  Having said that, there are two forms to "CWinThread* AfxBeginThread()"; one for a worker thread, and the other for a GUI thread.  The first two parameters of either version is what tells the computer which thread is going to be created.  The other parameters can be ignored since they all have default values.

For the worker thread, the first two parameters are, "AFX_THREADPROC pfnThreadProc" and "LPVOID pParam".  The first parameter is a pointer to a function that will be used to start the thread.  The second is a 4-byte value that will be used to passed (this value) to the new thread.

For the GUI thread, the first two parameters are, "CRuntimeClass* pThreadClass" and "int nPriority".  The first parameter is a pointer to the runtime class you have created that is derived from CWinThread.  The second parameter represents the priority of the new thread (if you use 0 [zero], the new thread will have the same priority as the current thread).


Except for the creation of the two threads that will be responsible for the processing of the images (along with the names you'll have to give for your document and view), AppWizard will generate just about all the code you'll be needing.  The customization of thoses codes is your responsibility.  (It may look difficult, and it may sound difficult, but it is not.  You've just got to try!)

If you have any further questions, don't hesitate!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cinderallaAuthor Commented:
thank you for your help
0
TryCommented:
I don't believe I submitted an answer!  I didn't want your points.

Don't look forward to me giving you anymore assistance in the future.
0
andlaCommented:
>>Don't look forward to me giving you >>anymore assistance in the future.

Try>> What ?!!??
0
cinderallaAuthor Commented:
what do u actually mean by that? I am just thankful to u who gave me some pointers for me to start working on and you sound as if I had insulted your intelligence. I am sorry if I made you feel that way. So is there any way which I can take back the points?
0
TryCommented:
For the record, I had asked EE if points awarded for a question could be returned to the giver and have everything assosciated with it removed.  Their answer, "NO".

You are free to try, and if they are willing to remove the question and everything associated with it, be my guest!

The subject of intelligence is not salient to the issue.  It was your pre-emptive willingness to take an incomplete explanation as the answer to your question, even though I had not submitted a response as an answer.  All my responses were done in the form of comments.
0
cinderallaAuthor Commented:
Merry X'mas, Try and really sorry for making you feeling this way.
0
cinderallaAuthor Commented:
Merry X'mas, Try and really sorry for making you feeling this way.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.