Results 1 to 12 of 12

Thread: Form Subclassing question...I don't want a form to get focus

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Form Subclassing question...I don't want a form to get focus

    I have 2 forms.
    I do not want one form to get focus.
    This can be done by disabling the form...but I don't want to do this and more to the point, I can't do this. I have my reasons.

    I am subclassing the form and somehow how have to trap for the "get focus" event.
    I think if I ignore this message the form won't get focus...I think

    What event is it I'm looking for here? Is there such thing as I a "get focus" event on a form...Hmmmm...It's late and I'm tired.

    Whimper

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Form Subclassing question...I don't want a form to get focus

    As the simplest you can just pass focus back to your "main" form:
    VB Code:
    1. 'Form2
    2. Private Sub Form_GotFocus()
    3.     Form1.SetFocus
    4. End Sub
    Problem is that you might need to do the same thing for every control that can get focus.

  3. #3

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Form Subclassing question...I don't want a form to get focus

    Hmmmmm...not sure.
    I am tired and should have explained exactly what I wanted to do sorry, my bad
    I have a form, form1...and I have a picture box on this form.
    I am using the SetParent API command to place form2 inside the picturebox on form1. Standard stuff, we've all seen it before.

    What I would like...and I am not sure if this is possible, but I would like a control on form2 to get focus but I would form1 to keep focus.

    Am I taking rubbish

    Woof

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Form Subclassing question...I don't want a form to get focus

    Quote Originally Posted by Wokawidget
    ... Am I taking rubbish ...
    I don't think so ...
    I recently noticed kind of weird SourceSafe behaviour: while running project in IDE main form looses focus but all controls are accessible but you'll need to single click twice on each to set focus ... So maybe you want incorporate SS in your exe, eh ...
    But seriously, I'm afraid you're taking a little too far though.

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Form Subclassing question...I don't want a form to get focus

    I would like a control on form2 to get focus but I would form1 to keep focus
    Do you really mean focus? Only one Window/Control can have focus at a time.
    Are you saying you want all mouse and keyboard input to go to two things at once?

  6. #6

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Form Subclassing question...I don't want a form to get focus

    Here's an example of what I have so far.

    Notice how the controls don't get a click event...boooo. This isn't an issue though.

    Anyways...I want to intercept the lost and got focus events of the forms.
    But am not sure what messages to look for.

    WOka
    Attached Files Attached Files

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Form Subclassing question...I don't want a form to get focus

    You do nothing more that passing focus back to Form1 - that is what I suggested in my very first reply ...
    What you are after, Woka, requires system wide hook and not just simple subclassing.
    I recommend you to visit vbaccelerator and download what Steve Mac calls journal - some serious sample project that requires lots of attention. I don't want to describe what is does but you'll figure it out.

    Cheers and good luck.

  8. #8

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Form Subclassing question...I don't want a form to get focus

    Yea...I added in SetFocus after your post

    Ahhh poo sticks

    That's what I was afraid of.
    I suppose I could code round the controls issue...they were't in my agenda anyways. It was just that if you click form2 fast then u can see a flciker when form1 loses focus. That's what I want to get rid of...but I can't disable the form.

    Woof

  9. #9
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Form Subclassing question...I don't want a form to get focus

    Out of curiosity Woka, what are you trying to accomplish? Some sort of MDI type function?

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  10. #10

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Form Subclassing question...I don't want a form to get focus

    I am going to combine it with my "multithreading" code and produce a usercontrol that runs entirely in another "thread"...including the graphix rendering. Regardless of what your UI is doing the usercontrol will ALWAYS refresh itself...unless IT crashes that is
    So the form in the pic box will be a form in another process.

    It's something for my LiveUpdate code.

    Woka

  11. #11

  12. #12
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Form Subclassing question...I don't want a form to get focus

    I'm not sure what a system-wide Journal hook is going to do for you.

    You can, however, set a thread-specific CBT hook which processes HCBT_SETFOCUS messages. You can prevent the focus from changing to another control on your form, by returning a non-zero value when this message is received.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width