Private Sub TextBox1_GotFocus () Me. Hide Me. Enabled=False Form2. Show Form2. SetFocus End Sub
Form2: Private Sub Form_Activate () Me. SetFocus TextBox1. SetFocus MsgBox "!" End Sub
If no msgbox Form2 won the focus though it may seem, but can't operation, must click on the icon on the taskbar gains focus again to operate, but if there is one msgbox, can direct access to the focus,
My question is, if there is a problem of my code, how to get focus directly?
CodePudding user response:
Is one of the characteristics of the operating system, the prohibition of ordinary form gains focus (only sparkles in the taskbar), If you use Win98 is direct access to the focus,
CodePudding user response:
Public Sub myFocus (hWnd&) Dim hWnd& HForeWnd& DwForeID& DwCurID& HForeWnd=GetForegroundWindow () DwForeID=GetWindowThreadProcessId (hForeWnd, 0) DwCurID=GetCurrentThreadId () AttachThreadInput dwCurID dwForeID, True SetWindowPos hWnd HWND_TOPMOST, 0, 0, 0, 0, + SWP_NOMOVE SWP_NOSIZE SetWindowPos hWnd HWND_NOTOPMOST, 0, 0, 0, 0, + SWP_NOMOVE SWP_NOSIZE The SetForegroundWindow hWnd AttachThreadInput dwCurID dwForeID, False End Sub