dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] Call SetWindowPos(Form1.hwnd, HWND_TOPMOST,,,,,) Does NOT return FORM FOCUS

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    2

    Resolved [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

    AppActivate (Me.Caption)
    Form1.List1.SetFocus
    SendKeys "{End}"
    Me.SetFocus
    --------------------------------------------------------------------------------------------------------------------------------------

    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

  2. #2
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,223

    Re: Call SetWindowPos(Form1.hwnd, HWND_TOPMOST,,,,,) Does NOT return FORM FOCUS

    In cases like this it is good to provide an example of the problem with a small project that can reproduce it.

    I tried to recreate the problem, but is is working fine here.

    See attachment.
    Attached Files Attached Files
    vbExtra: Print preview for VB6, print FlexGrids and more.
    MSDN online for VB6, Language reference.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    2

    Re: [RESOLVED] Call SetWindowPos(Form1.hwnd, HWND_TOPMOST,,,,,) Does NOT return FORM

    Quote Originally Posted by Timber View Post
    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

    AppActivate (Me.Caption)
    Form1.List1.SetFocus
    SendKeys "{End}"
    Me.SetFocus
    --------------------------------------------------------------------------------------------------------------------------------------

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width