Link to home
Start Free TrialLog in
Avatar of butterhook
butterhookFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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...)
Avatar of butterhook

ASKER

This project is a Word Addin, so there is no 'Main project form'
I am trying it with .Visible = True before the SetWindowPos
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have taken the SETWINDOWPOS out, and shown the form Modal. Seems to work fine. Hasn't crashed yet
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
>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....
I seem to have fixed it by doing the rtfBox.setFocus on the Form_Paint event. Here are your points - thanks!