butterhook
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
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
ASKER
This project is a Word Addin, so there is no 'Main project form'
ASKER
I am trying it with .Visible = True before the SetWindowPos
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have taken the SETWINDOWPOS out, and shown the form Modal. Seems to work fine. Hasn't crashed yet
ASKER
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....
usually, the tabindex = 0 defines the control that gets the focus when the form loads....
ASKER
I seem to have fixed it by doing the rtfBox.setFocus on the Form_Paint event. Here are your points - thanks!
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...)