I want to create an application that consists of several "modules", each of which would be based on a database table, and will be opened either from a menu or from a button in an Outlook-styled toolbar. Obviously I'll create a "main" window, but then there will be several windows, one for each "module", of different sizes, each with its own toolbar and controls, that I want to be constrained within the boundaries of the main window. In other words, I don't want the module window(s) to appear as Windows taskbar buttons (I can do that part), but I also don't want the windows to be draggable beyong the frame of the main window, and if minimized, I want these windows to minimize within the main window.
I have tried using MDI, but that doesn't seem suited to what I'm trying to do, unless I haven't fully explioted the functionality of that concept. As usual, I don't really need code examples (but I'll sure take 'em); if someone could just explain the concept or the general procedure I can run with it.

Recommended Answers

All 3 Replies

Well, The main idea behind what you are trying to do is completely MDI. However, I'm going to treat you to a little gem, that, depending on the app (since you are using your own forms, it's no problem) can cause troubles. This is a ... technique of sorts, that is namely taboo. Here you go, Though.
In A Code Module, Add This:

Public Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Dim oldhwnd As Long

Now, in your MAIN Form Load, you just simple add this (keep in mind, that you can add this anywhere that you want to in your main form... a menu, a button... whatever). This is the code to grab your form, and stick it inside your other form.

oldhwnd = SetParent(Form2.hWnd, MainForm.hWnd)

Now, make sure to replace Form2 with the name of the form that you want inside (or however many forms you want inside) of the main window. Change the name of MainForm, To the name of your main form (don't lose the .hWnd's that follow).

Slick! Thanks, I'll try it. Also, I guess I need to bone up a little more on MDI.

OK. Here's what I figured out:

I started a new Standard EXE project, which of course automatically creates a form (Form1). I then created a new MDI form, made it the default form in the project properties and set the "MDIChild" property of the automatically created form (Form1) to "true", which keeps it within the boundaries of the MDI form. So now the MDI form acts as the "main" window. I can now create other forms and by setting their MDIChild property to true, each of them will behave in the same manner.
Thanks for pointing me in the right direction. I think I'm well on my way to becoming a rookie programmer!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.