Loading ...
Sorry, an error occurred while loading the content.

Positioning prompt dialog

Expand Messages
  • John
    When using NOMAINWIN is there a way to set the position of a Prompt dialog? I am playing around with a program trying to learn a bit about LB and when I use
    Message 1 of 2 , Aug 4, 2011
    • 0 Attachment
      When using NOMAINWIN is there a way to set the position of a Prompt dialog?

      I am playing around with a program trying to learn a bit about LB and when I use the command:

      prompt "Enter something here : "; answer$

      the prompt dialog box opens at the top of the screen and I would like it to appear much lower on the screen. Is there a way to do this?

      Thanks.
    • Stefan Pendl
      ... The PROMPT, NOTICE and CONFIRM dialogs are standard Windows dialogs, which do not support custom positioning. If you want to have full control, you will
      Message 2 of 2 , Aug 5, 2011
      • 0 Attachment
        >
        > nomainwin
        > WindowWidth = 190 :WindowHeight = 160
        > textbox #w.tbx,20,20,100,25
        > open "Test1" for window as #w
        > print #w, "trapclose [quit]"
        > prompt "Enter something : "; ans$
        > #w.tbx, ans$
        > wait
        > [quit]
        > close #w
        > end
        >
        > If the dialog box can be moved, I too like to learn how.
        >

        The PROMPT, NOTICE and CONFIRM dialogs are standard Windows dialogs, which do not support custom positioning.

        If you want to have full control, you will have to roll your own.

        You can use a bunch of API functions to position the build in Windows dialogs, but it is not worth the code overhead in my opinion.


        '---code start (watch for line wraps)

        ' Position notice box
        ' by Brent Thorn
        ' URL: http://libertybasic.conforums.com/index.cgi?board=LB3&action=display&num=1086889028

        nomainwin
        posX = 200
        posY = 200
        message$ = "Positioned at ..."; chr$(13); "Hello from X"; posX; " Y"; posY
        Call NoticeAt message$, posX, posY
        End

        Sub NoticeAt Msg$, centerX, centerY
        Callback lpfnHook, NoticeAtHook( Long, ULong, ULong ), Long

        CallDLL #kernel32, "GetModuleHandleA", _
        _NULL As uLong, _
        hInst As ULong

        CallDLL #kernel32, "GetCurrentThreadId", _
        ThreadId As ULong

        CallDLL #user32, "SetWindowsHookExA", _
        _WH_CBT As ULong, _
        lpfnHook As ULong, _
        hInst As ULong, _
        ThreadId As ULong, _
        hHook As ULong

        HookData(0) = hHook
        HookData(1) = centerX
        HookData(2) = centerY

        Notice Msg$
        End Sub

        Function NoticeAtHook( lMsg, wParam, lParam )
        If _HCBT_ACTIVATE = lMsg Then
        struct Rect,_
        left as long,_
        top as long,_
        right as long,_
        bottom as long

        calldll #user32, "GetWindowRect", _
        wParam as ulong,_
        Rect as struct,_
        result as long

        width = Rect.right.struct - Rect.left.struct
        height = Rect.bottom.struct - Rect.top.struct

        hHook = HookData(0)
        x = HookData(1) - int(width /2)
        y = HookData(2) - int(height /2)

        flags = _SWP_NOZORDER or _SWP_NOSIZE or _SWP_NOACTIVATE

        CallDLL #user32, "SetWindowPos", _
        wParam As ULong, _
        _NULL As ULong, _
        x As Long, _
        y As Long, _
        0 As Long, _
        0 As Long, _
        flags As ULong, _
        r As Long

        CallDLL #user32, "UnhookWindowsHookEx", _
        hHook As ULong, _
        r As Long
        End If

        CallDLL #user32, "CallNextHookEx", _
        hHook as uLong, _
        lMsg as long, _
        wParam as uLong, _
        lParam as uLong, _
        NoticeAtHook as long
        End Function

        '---code end

        ---
        Stefan Pendl
        http://stefanpendl.runbasichosting.com/

        Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
        Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

        Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/

        Books at http://www.lulu.com/ and http://www.amazon.com/
        Alyce Watson ... APIs for Liberty BASIC
        Carl Gundel .... Beginning Programming with Liberty BASIC

        Windows 7 Home Premium 64-bit SP1
        AMD Turion X2 RM-70 2GHz, 4GB RAM
      Your message has been successfully submitted and would be delivered to recipients shortly.