Announcement

Collapse
No announcement yet.

Set Window to Foreground

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Set Window to Foreground

    We are using the Console Compiler for data input, and use the DLL Compiler to bring up a window containing field specific help if the user needs it.

    The problem we are encountering in win98 is that when we call the DLL the first time to bring up help over the console screen, windows seems to treat the DLL as a seperate program and the help panel ends up flashing on the task bar.

    Subsequent calls to the DLL after the help screen has been maximised and then closed work OK and arrive topmost to the Console screen.

    We are not using %WS_EX_TOPMOST only %DS_SETFOREGROUND

    Is there a work around to this Windows quirk?

    ------------------

  • #2
    If you are using DDT I suspect you could use:

    CONTROL SEND hDlg&, Id&,%WM_SETFOCUS,0&,0& during WM_INITDIALOG

    Otherwise SendMessage hDlg, GetDlgItem(102 or whatever it is), %WM_SETFOCUS,0&,0&

    Hope that helps!

    Scott


    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #3
      It's been a while since I've mixed Console and GUI windows so I'm a tad rusty, but I have to ask... have you specified the console window as the parent to the DDT dialog, or does the dialog use zero (%HWND_DESKTOP) as the parent?


      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Hi Guys
        Thanks for the speedy response

        Lance originally we were passing 0 as the parent, and then we figured out we should send the value in hCurInstance in WinMain in the Console program, but no change, hence my posting.
        We are printing this value on the dialog to prove we are not doing something stupid.

        Scott we have tried CONTROL SEND hDlg&, Id&,%WM_SETFOCUS,0&,0& and it makes no difference.

        We are trying to reduce the problem to basics and have discovered the following.

        If we start with the console window and do nothing except call the DLL the DIALOG comes on top.
        If we click the mouse on the console window before calling the DLL it goes to the task bar.

        Once it has correctly come on top from then on it is always on top when called.

        ------------------


        [This message has been edited by Geoff Stow (edited January 24, 2001).]

        Comment


        • #5
          Geoff --
          Post fragments from PB/CC and PB/DLL, and explain more exactly, what do you need.
          Here are important all details:
          - in which mode is PB/CC module (full screen/window mode);
          - is PB/DLL modal or modeless dialog
          - what should happend, when DDT loses focus and so on.

          To coordinate PB/CC and modal DDT is more than simple.
          But, of course, you should inform Windows about your "wishes" and don't prove it to decide what's better - mother or father.

          ------------------
          E-MAIL: [email protected]

          Comment


          • #6
            Thank you for your reply Semen

            PBCC has to be in a window of course.
            The dialog is modal.

            The dialog we use for a pop up help screen for each input field in PBCC.
            They call it on a hot key and close it afterwards.

            The very first time it is called it dives onto the task bar, but only if the mouse has been used on the console screen first.
            Once it has been maximised from there it works every time perfectly.

            I will reduce the code to a blank console screen and an empty dialog and post the fragments tomorrow, it is 7.30pm here in Manila.

            Kind regards
            Geoff



            ------------------

            Comment


            • #7
              Lance originally we were passing 0 as the parent, and then we figured out we should send the value in hCurInstance in WinMain in the Console program, but no change, hence my posting.
              We are printing this value on the dialog to prove we are not doing something stupid.
              The Instance handle is not the same as the Window handle. To get the window handle, you'll need to use the FindWindow() API, but you must first make sure that the console title is unique (to ensure that FindWindow() returns the correct window handle). If you must change the console title (say, with CONSOLE NAME, be sure to follow it with SLEEP 250 before using FindWindow() to ensure that Windows has sufficient time to carry out the update.

              Fun stuff!




              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment


              • #8
                Geoff --

                > originally we were passing 0 as the parent, and then
                > we figured out we should send the value in hCurInstance
                > in WinMain in the Console program,

                hCurInstance is your application's Instance Handle, not a Window Handle. You'll need to obtain the console window handle and use it as the parent of the GUI elements. Search this BBS for "FindWindow" and you'll find a couple of routines that do a good job most of the time (SetConsoleTitle, SLEEP, etc.), but you will probably find that they are not 100% reliable, especially on Windows 9x, and especially after your software leaves the lab. For an "industrial strength" solution that has been thoroughly field-tested, check out my company's Console Tools add-on for PB/CC. It includes a console window handle function that is virtually 100% reliable on all versions of Windows. Console Tools also includes a number of other functions that you will find valuable if you are mixing console and GUI elements.

                What you are trying to do is not easy, but it can be done. With the right Tools. And the results can be quite impressive.

                -- Eric Pearson, Perfect Sync Software

                ------------------
                Perfect Sync: Perfect Sync Development Tools
                Email: mailto:[email protected][email protected]</A>

                [This message has been edited by Eric Pearson (edited January 24, 2001).]
                "Not my circus, not my monkeys."

                Comment


                • #9
                  I modified a sample, which I already posted.
                  I didn't nontice something under 98SE, incl. full screen

                  PB/CC

                  Code:
                      #Compile Exe
                      #Dim All
                      #Register None
                      #Include "Win32Api.Inc"
                  
                      Declare Function AskUser Lib "Pb1.Dll" Alias "AskUser" (hWndParent As Long, Question As String) As String
                  
                      Global HotKeyProc() As Dword
                  
                      Function MyInkey As String
                  
                         Dim s As String, HotKey As Dword
                         s = InKey$
                         If s = Chr$(0, 59) Then Print: Print AskUser(GetForegroundWindow, "What's your name ?") Else _
                         Function = s
                         If Len(s) = 0 Then Sleep 1
                      End Function
                  
                      Function PbMain
                         Dim x As String
                         Print "F1 - Help F2 - Exit ... Echo for other symbols"
                         Do
                            x = MyInkey$
                            If x = Chr$(0, 60) Then Exit Do
                            If Len(x) = 1 Then Print x;
                         Loop
                      End Function
                  PB/DLL

                  Code:
                    #Compile Dll "Pb1.Dll"
                    #Register None
                    #Dim All
                    #Include "Win32Api.Inc"
                  
                    %IDTEXT     = 100
                  
                    CallBack Function DlgProc
                       Select Case CbMsg
                          Case %WM_INITDIALOG
                             Dim UserName As Global String, hWndParent As Static Long
                             hWndParent = GetParent(CbHndl)
                             Control Add TextBox, CbHndl, %IDTEXT, "", 14,  12, 134, 12
                             Control Add Button, CbHndl, %IDOK, "OK", 34, 32, 40, 14, %BS_DEFAULT
                             Control Add Button, CbHndl, %IDCANCEL, "Cancel", 84, 32, 40, 14
                             SetForegroundWindow CbHndl
                             EnableWindow hWndParent, %False
                          Case %WM_COMMAND
                             If CbCtl = %IDOK Or CbCtl = %IDCANCEL Then
                                If CbCtl = %IDOK Then Control Get Text CbHndl, %IDTEXT To UserName Else UserName = ""
                                EnableWindow GetParent(CbHndl), %True
                                SetForegroundWindow GetParent(CbHndl)
                                Dialog End CbHndl
                             End If
                          Case %WM_DESTROY
                             If IsIconic(hWndParent) Then ShowWindow hWndParent, %SW_MINIMIZE: _
                                ShowWindow hWndParent, %SW_RESTORE
                       End Select
                    End Function
                  
                    Function AskUser Alias "AskUser" (hWndParent As Long, Question As String) Export As String
                       Local hDlg As Long
                       Dialog New hWndParent, Question, , , 160, 50 To hDlg
                       Dialog Show Modal hDlg Call DlgProc
                       Function = UserName
                    End Function



                  ------------------
                  E-MAIL: [email protected]

                  Comment


                  • #10
                    Hi Everyone
                    Many thanks for all your replies to this, the problem is now solved.

                    Dave we have both ConTools and GfxTools so have now used hConsoleWindow to pass the console handle to the DLL.

                    Dave, the reason we are not using ConsoleInputBox type 6 to achieve the pop up help is that there is no way to supress the horizontal scroll bar.
                    This means we have to format all our help text line width ourselves, which is harder to achieve than write the DLL. Possibly your company should look at this missing feature.

                    Kind regards
                    Geoff


                    ------------------

                    Comment

                    Working...
                    X