Solved

Forms Acitvation

Posted on 1998-08-27
9
243 Views
Last Modified: 2010-04-30
How can i open a vb form that can't get focus? (working with vb5 SP3,Win95)
0
Comment
Question by:Avi082798
[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
9 Comments
 
LVL 1

Expert Comment

by:blwatkins
ID: 1431331
I'm kind of confused on what you are trying to achieve?  You have a form that "Can't" get focus or you don't want it to get the focus when you load it?  Can you expand on you situation a little bit?
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1431332
Once you show the form, it can get focus via mouse selection, but you can place event logic in the gotfocus event to shift focus back to another form, if that helps you any.  
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1431333
Try this:

' 1. In the general declaration area of your form (say form2 is the one you don't want focus), add:
Private Declare Function GetForegroundWindow Lib "user32" () As Long

'              2. drop a timer to your form (form2), set the interval to 5 (you can adjust this).
             
               3. In the form2_gotfocus Event, add: Timer1.enabled = True

'              3. in the timer1_timer event, add:
             Timer1.Enabled = false
'            If GetForegroundWindow() = Me.hWnd Then Form1.Show (or what ever form you want focus to be on)
'              This will give away focus in 10 milliseconds

Regards
Dalin
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:Avi082798
ID: 1431334
This won't work because the form will filcker. And that's the one thing i don't want. But Thanks anyway.

Regards
Avi
0
 

Expert Comment

by:FrankG082898
ID: 1431335
I am assuming you are talking about a Form with the enabled property set to False.

Here's what I tried:

A project with two forms, Form1 and Form2.  A command button on Form1.  Enabled set to False on Form2.

Code in Form2:

Option Explicit

Public Sub ShowMe(frmCalling As Form)
    Me.Show vbModeless
    frmCalling.SetFocus
End Sub

Code in Form1:

Private Sub Command1_Click()
    Form2.ShowMe Me
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim i As Integer
   
    For i = 1 To Forms.Count - 1
        If Forms(i).Caption = "Form2" Then
            Unload Form2
        End If
    Next i
End Sub

I'm not sure this is what you want, but what I've basically done is put a method in Form2 that shows itself and returns focus to whatever form wants it opened.  The Unload event in Form1 is clean up to unload Form2 if it has been opened.  If you don't do this, the app won't terminate.


0
 

Expert Comment

by:FrankG082898
ID: 1431336
Sorry, I noticed an error in my proposed solution.  In Form_Unload, i should go from 0 to Forms.Count - 1.
0
 

Author Comment

by:Avi082798
ID: 1431337
Thanks, but it wont do it for me, your sample flickers and thats what i don't want.
0
 

Expert Comment

by:FrankG082898
ID: 1431338
I'm not sure what you mean by "flickers".  I noticed that the previous solution allows you to click and momentarily give focus to the window which flashs the title bar from blue to gray.  Didn't notice that on my solution.  But, again, I guess I don't know what "flickers" means.
0
 
LVL 2

Accepted Solution

by:
Bhargava earned 200 total points
ID: 1431339
Check if this helps

Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const HWND_BOTTOM = 1
Public Const SWP_NOACTIVATE = &H10

Private Sub Form_Paint()
    Me.AutoRedraw = False
    SetWindowPos Me.hwnd, HWND_BOTTOM, 0, Screen.Height / 2, 0, Screen.Width / 2, SWP_NOACTIVATE
    Me.AutoRedraw = True
End Sub
0

Featured Post

Technology Partners: 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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

617 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