SETWINDOWPOS and showing a form vbModal -CRASHING

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
LVL 1
butterhookAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
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...)
0
butterhookAuthor Commented:
This project is a Word Addin, so there is no 'Main project form'
0
butterhookAuthor Commented:
I am trying it with .Visible = True before the SetWindowPos
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
you don't need the setwindowpos at all then.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
butterhookAuthor Commented:
I have taken the SETWINDOWPOS out, and shown the form Modal. Seems to work fine. Hasn't crashed yet
0
butterhookAuthor 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
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>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....
0
butterhookAuthor Commented:
I seem to have fixed it by doing the rtfBox.setFocus on the Form_Paint event. Here are your points - thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.