[RESOLVED] Call SetWindowPos(Form1.hwnd, HWND_TOPMOST,,,,,) Does NOT return FORM FOCUS
I am still using VS-6 (VB6) [Don't ask why], am working on an Application with Advanced Crypto functions. EVERYTHING works and passes QA test except 1 annoying effect: when I call SetWindowPos(Form1.hwnd, HWND_TOPMOST,,,,,); it DOES NOT return focus to the FORM. I've tried everything known to professional developers; to no avail. Does anyone have a suggestion? Here is the offending code snippet:
--------------------------------------------------------------------------------------------------------------------------------------
' BEFORE loading the SETTINGS form, turn OFF the "KEEP ON TOP" state, otherwise the SETTINGS form is behind
' the main form and unaccessible
'
If PKeepTop = True Then
Call SetWindowPos(Form1.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, _
SWP_ASYNCWINDOWPOS Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
End If
Load frmSetting
frmSetting.Show vbModal, Form1
' AFTER responding to the SETTINGS form, turn ON the "KEEP ON TOP" state if the PKeepTop flag is set
'
If PKeepTop = True Then
' Call SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0,
' SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
Call SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_ASYNCWINDOWPOS Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
End If
I've tried all the variants of Uflags & combinations, no change. At the end, the List1.SetFocus works, but the FORM itself is not
activated. I removed (but found in SourceSafe)
AppActivate gCaption
a = SetActiveWindow(Form1.hwnd)
neither made any difference. All I want it the FORM to be activated (BLUE FOREGROUND TITLE BAR) once it returns from the "frmSettings" form.
ANY and ALL guidance will be MOST appreciated.
Last edited by Timber; Feb 12th, 2018 at 10:19 AM.
Reason: spelling
Re: [RESOLVED] Call SetWindowPos(Form1.hwnd, HWND_TOPMOST,,,,,) Does NOT return FORM
Originally Posted by Timber
I am still using VS-6 (VB6) [Don't ask why], am working on an Application with Advanced Crypto functions. EVERYTHING works and passes QA test except 1 annoying effect: when I call SetWindowPos(Form1.hwnd, HWND_TOPMOST,,,,,); it DOES NOT return focus to the FORM. I've tried everything known to professional developers; to no avail. Does anyone have a suggestion? Here is the offending code snippet:
--------------------------------------------------------------------------------------------------------------------------------------
' BEFORE loading the SETTINGS form, turn OFF the "KEEP ON TOP" state, otherwise the SETTINGS form is behind
' the main form and unaccessible
'
If PKeepTop = True Then
Call SetWindowPos(Form1.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, _
SWP_ASYNCWINDOWPOS Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
End If
Load frmSetting
frmSetting.Show vbModal, Form1
' AFTER responding to the SETTINGS form, turn ON the "KEEP ON TOP" state if the PKeepTop flag is set
'
If PKeepTop = True Then
' Call SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0,
' SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
Call SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_ASYNCWINDOWPOS Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
End If
I've tried all the variants of Uflags & combinations, no change. At the end, the List1.SetFocus works, but the FORM itself is not
activated. I removed (but found in SourceSafe)
AppActivate gCaption
a = SetActiveWindow(Form1.hwnd)
neither made any difference. All I want it the FORM to be activated (BLUE FOREGROUND TITLE BAR) once it returns from the "frmSettings" form.
ANY and ALL guidance will be MOST appreciated.
For anyone else that comes across this illogical issue, the problem was SOLVED by the following line of code:
a = SetActiveWindow(hwnd)
I changed: "Form1.hwnd" to just "hwnd" AFTER the "SetWindowPos(" call, and FORM1 automatically becomes the ACTIVE window. I did some research on both the MSDN (archive) and TechNet sites, and there is no information why there is a difference between "FORM1.hwnd" and just plain "hwnd". Point of reference - this legacy APP also uses System Calls to "Minimize to SYSTRAY"; which may have been contributing to the issue. The APP now passes ALL the QA standards, and goes into an ALPHA TEST phase (we use the Standard Development Process). Thanks to ALL that popped in to read, and Eduardo for validating "what is supposed" to work (I wasn't losing my mind after all!).
Timber
→ The Comprehensive Guide to Cloud Computing
A complete overview of Cloud Computing focused on what you need to know, from selecting a platform to choosing a cloud vendor.