Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Focus no longer on the correct form due to message box.

Status
Not open for further replies.

moreCA

Programmer
Feb 11, 2003
68
US
I am trying to implement hot key access to my command buttons that are located within a frame. The frame is physically located on form2. Form1 is the only form showing. It contains frame1. I use WinSetParent to position frame2 within frame1. Seems that whenever a messagebox is displayed, the focus shifts back to form1, thereby disallowing the hot keys on the command buttons that are located on form2. I have a small sample app. if anyone cares to delve into this issue for me. I have tried to set focus in code, use the SetActiveWindow, and the SetForegroundWindow...nothing worked. I do have a solution, but I don't care for it. I can use an API call other than WinSetParent that will make the form the child instead of the frame. This solution makes form1 actually look out of focus by graying the title bar...not good. Any ideas.
 
Although I appreciate your suggestion, the msgbox function is tooo easy, plus there are too many of them currently in my code to change. I'm not even sure that that would solve it, being that I would want to use a modal message box form. Anyway thanks for the suggestion. Any other ideas...anybody???
 
FYI: For anyone checking out this thread...I tested out zemp's suggestion of creating my own forms to act as message boxes. Whether modal or not it doesn't seem to affect it either way.

Thanks
 
Maybe it's just me but I'm not fully understanding your problem. You said form1 is the only form showing so I'm not sure how form2 is losing focus. How about this, create a small sample project that duplicates the problem then post the code here, something like

Add frame1, command1, etc to form1
form1 code:

'Code

Add frame1, command1, etc to form2
form2 code:

'Code



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Create form1 and add frame1, command1
Command1.Caption = "WinSetParent"

form1 code:

Private Sub Command1_Click()
Load Form2
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Unload Form2
End Sub

Create form2 and add frame2, command1(0), command1(1), command1(2), and label1 with the command buttons and label1 on frame2
Command1(0).Caption = "&A TEST"
Command1(1).Caption = "&B TEST"
Command1(2).Caption = "&Clear"

form2 code:

Private Sub Command1_Click(Index As Integer)
If Index = 0 Then
Label1 = "A TEST"
ElseIf Index = 1 Then
Label1 = "B TEST"
MsgBox "B TEST"
ElseIf Index = 2 Then
Label1 = ""
End If
End Sub

Private Sub Form_Load()
Dim lResult As Long
lResult = WinSetParent(Frame2.hWnd, Form1.Frame1.hWnd)
End Sub

Create module1

module1 code:

Declare Function WinSetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long


Test by:
1) Starting Program
2) MouseClick WinSetParent
3) MouseClick A TEST
4) KeyPress ALT-C
5) KeyPress ALT-A
6) KeyPress ALT-B
7) MouseClick OK button

Focus is no longer on 'Form2', therefore ALT keys do not respond.

If you want me to email the zipped project so you don't have to do the above...post your email address.

Thanks for the response,
CA
 
OK button is on the message box that displays when you press the B TEST button.

Thanks for checking out my thread,
CA
 
Yes, I recreated this case. I don't know how to fix it. I would simply use TabStrip control in your case.
 
AEtherson, have you tried that yourself?

moreCA, I just got around to test your problem, I see what you are talking about. I'll play around with it this afternoon but I'm going to be in and out of meetings today.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top