Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 20th, 2006, 03:55 AM
vb_programmer vb_programmer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 18 vb_programmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 52 sec
Reputation Power: 0
Problem with creating Multiple instances of Form in VB!

Hello!

In my currently under-development application, I need to create multiple instances of a Form with no title bar (ControlBox = False). I do it this way ...

Private oForm as frmNote

Public Sub CreateFormInstance()
Set oForm = new frmNote
oForm.Show
End Sub

This code works perfect and creates the multiple instances of Form called frmNote. However, I'm facing one very interesting problem with it! When a new instance of frmNote is created and it's hidden behind any already open Application window, whenever I click frmMain (the main form which has a button to create instances of frmNote) Title bar, the instance of frmNote, which was behind a certain application window comes in front of the Application window automatically! Why this happens so? I don't want this to happen. Any work-around for this problem?

To put my problem in a better way, I have created a sample VB Project, which has similar functionality coded. I request you to please download the attached ZIP file and run it from your IDE. All the necessary information to mimic my problem situation is written on the Form. I don't understand why this problem occur as I never faced such issue before!

Eagerly waiting for your reply ...

Thanks & Regards,

Ruturaj.
Attached Files
File Type: zip Form Instance Problem.zip (12.6 KB, 107 views)

Reply With Quote
  #2  
Old June 22nd, 2006, 02:29 PM
vb_programmer vb_programmer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 18 vb_programmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 52 sec
Reputation Power: 0
Ok, so it looks like no one is interested in this topic! So, should I post my solution on this forum or not?! hmmm ...

Reply With Quote
  #3  
Old June 24th, 2006, 11:40 AM
LozWare's Avatar
LozWare LozWare is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2005
Posts: 531 LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 10 h 56 m 31 sec
Reputation Power: 46
Send a message via MSN to LozWare
Yeah, this VB forum is pretty dead. I dont tend to get replies for any of my VB related questions, but they are all pretty hardcore, lol.
__________________
LozWare Website Directory

Whooo! Free submissions, no recip needed. I'm a nice guy

Last edited by LozWare : June 24th, 2006 at 12:32 PM.

Reply With Quote
  #4  
Old June 24th, 2006, 11:44 AM
LozWare's Avatar
LozWare LozWare is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2005
Posts: 531 LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 10 h 56 m 31 sec
Reputation Power: 46
Send a message via MSN to LozWare
I am pretty sure that when you give focus to a window, you are giving focus to that entire thread. In otherwords, when you have multiple windows running on the same thread (like in your sample program), and you lose focus of them, then regain focus of one of the windows, then all of the other windows will come into focus too.

There may be simpler ways to resolve this, but the only thing that I can think of is making each form run on a seperate thread... or a seperate process if you dont want to run down the road of multithreading in VB.

Last edited by LozWare : June 24th, 2006 at 11:47 AM.

Reply With Quote
  #5  
Old June 24th, 2006, 12:31 PM
LozWare's Avatar
LozWare LozWare is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2005
Posts: 531 LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 10 h 56 m 31 sec
Reputation Power: 46
Send a message via MSN to LozWare
Ok, I felt sorry for you, so I spent a few minutes compiling a multithreaded solution.

There are 2 processes: 1 that handles the main form, and 1 that handles the child forms. Each child form runs on a separate thread to one-another.

The 2 processes communicate via ActiveX, so it's pretty straight-forward when it comes to transferring data between the forms.

Read the captions on the ChildForm Window for a longer explanation.

INSTRUCTIONS ON HOW TO RUN:
1) Open up the NewWindow.vbp project, and compile the EXE
2) Open up the MainApp.vbp project, and run it from your IDE. You don’t need to compile the MainApp project, but you can if you want. However, you MUST compile the NewWindow project, otherwise it won’t work properly.
3) Come back to this thread and give me some REP!

:-)
Attached Files
File Type: zip Indipendant Windows.zip (4.8 KB, 80 views)

Reply With Quote
  #6  
Old June 25th, 2006, 07:49 AM
vb_programmer vb_programmer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 18 vb_programmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 52 sec
Reputation Power: 0
Thanks for your reply and time you spent for me! I'm downloading your solution now.

Reply With Quote
  #7  
Old June 25th, 2006, 07:52 AM
vb_programmer vb_programmer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 18 vb_programmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 52 sec
Reputation Power: 0
Great! It works fine. Thanks.

Reply With Quote
  #8  
Old June 25th, 2006, 01:54 PM
LozWare's Avatar
LozWare LozWare is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2005
Posts: 531 LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 10 h 56 m 31 sec
Reputation Power: 46
Send a message via MSN to LozWare
That’s ok!

P.S.
Welcome to the world of multithreading! There are more advantages to it than just independent form orders!

Reply With Quote
  #9  
Old June 25th, 2006, 02:26 PM
vb_programmer vb_programmer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 18 vb_programmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 52 sec
Reputation Power: 0
Yes, you are right! I just saw it and found very interesting. After your example, I wrote one simple module as a template for me to check how much I have understood Multithreading and I could make the program run fine. I tried to fill two Listboxes with 5000 items simultaniously in my multithreading.

However, when I tried to use the same function in AddressOf for creation of two different threads, the program failed. Also, I found that I can not pass param to function while using as AddressOf. So, can you tell me how to use same function with some ByVal or ByRef params passed to it?

What I tried is ... wrote one single function with iListIndex As Integer as function argument. My concept was to pass 1 and create a thread to fill Listbox_1; then pass 2 and create a thread to fill Listbox_2. But This does not go hand in hand! I found that both the threads are filling same Listbox (Listbox_2) and Listbox_1 remained empty.

It's interesting but really of very restricted use if separate function for each thread to handle is required!

Reply With Quote
  #10  
Old June 25th, 2006, 03:09 PM
LozWare's Avatar
LozWare LozWare is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2005
Posts: 531 LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level)LozWare User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 10 h 56 m 31 sec
Reputation Power: 46
Send a message via MSN to LozWare
Sorry, I have read your post over a few times, but Im not entirely sure what you mean. Could you post a sample project?

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Problem with creating Multiple instances of Form in VB!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT