We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

SETWINDOWPOS and showing a form vbModal -CRASHING

butterhook
butterhook asked
on
Medium Priority
488 Views
Last Modified: 2008-03-10
Hello EE,

I have inherited a piece of software and it tends to crash intermittently but very annoyingly. On the off-chance that wsome of you would know about this, I will explain what I think might be crashing it -

Basically, is it a bad idea to call SetWindowPos before showing a form vbModal as per the following?

' ------------------------------------------------------------------------------------------------

320         Call SetWindowPos(Me.hWnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, _
                        SWP_NOMOVE Or SWP_NOSIZE Or SWP_FRAMECHANGED)
   
330         Me.Show modal:=1

' ------------------------------------------------------------------------------------------------

Cheers,

Charlie
Comment
Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
what are you trying to achieve with that code?

usually, to put one of your forms in front of all the others in the same project (where MainForm is the Main project form), but allowing the focus to go to any of the forms:

330         Me.Show vbModeless, MainForm  

usually, to put one of your forms in front (of all the others in the same project)
but only allow focus to the form itself :

330         Me.Show vbModal, Parentform


you should not need the SetWindowPos at all, that is only useful to put the form in front of ALL windows of all applications, while then you don't need the Me.show vbModal at all (but only a me.visible = true, but that BEFORE The setwindowpos call...)

Author

Commented:
This project is a Word Addin, so there is no 'Main project form'

Author

Commented:
I am trying it with .Visible = True before the SetWindowPos
Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
you don't need the setwindowpos at all then.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I have taken the SETWINDOWPOS out, and shown the form Modal. Seems to work fine. Hasn't crashed yet

Author

Commented:
I have found the place where my crash occurs - it's where I set the form to visible, but I need to set the focus to a richtextbox, but I can't do this in the code after I have set the form to Modal, and can't do it before. Any ideas? Thanks a lot
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
>but I need to set the focus to a richtextbox,
usually, the tabindex = 0 defines the control that gets the focus when the form loads....

Author

Commented:
I seem to have fixed it by doing the rtfBox.setFocus on the Form_Paint event. Here are your points - thanks!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.