Announcement

Collapse
No announcement yet.

DIALOG SET LOC?

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

  • DIALOG SET LOC?

    I can't get the DIALOG SET LOC to work as I expect. The following short
    program illustrates the problem I'm having. The idea is to move a child
    window to a location relative to its parent. In the following program, a
    child window should move to a position 10,10 units relative to its parent,
    hDlg, but instead, moves it to a position 10,10 relative to the screen.
    I've read and reread the user's manual, but I can't figure it out.

    Please, someone, help.

    Code:
    #COMPILE EXE
    #DEBUG ERROR ON
    #DIM ALL
    #INCLUDE "win32api.inc"
    GLOBAL style AS LONG
    DECLARE CALLBACK FUNCTION dlgProc()
    DECLARE CALLBACK FUNCTION childDlgProc()
    DECLARE SUB childWindow
    
    FUNCTION PBMAIN
       GLOBAL hDlg AS LONG
       style=%WS_SYSMENU + %WS_MINIMIZEBOX
       DIALOG NEW 0,"Problem with moving windows",,,250,200,style TO hDlg
       CONTROL ADD BUTTON, hDlg, 100, "Child", 100, 100, 60, 30
       DIALOG SHOW MODAL hDlg CALL dlgProc
    END FUNCTION
    
    CALLBACK FUNCTION dlgProc()
       SELECT CASE CBMSG
       CASE %WM_COMMAND
          IF CBCTL = 100 THEN
             childWindow
          END IF
       END SELECT
    END FUNCTION
    
    SUB childWindow
       LOCAL hChildDlg AS LONG
       DIALOG NEW hDlg,"Window to move",0,0,150,100,style TO hChildDlg
       CONTROL ADD BUTTON, hChildDlg, 200, "Move", 40, 40, 60, 30
       DIALOG SHOW MODAL hChildDlg CALL childDlgProc
    END SUB
    
    CALLBACK FUNCTION childDlgProc()
       SELECT CASE CBMSG
       CASE %WM_COMMAND
          IF CBCTL = 200 THEN
             DIALOG SET LOC CBHNDL, 10, 10
          END IF
       END SELECT
    END FUNCTION

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


    [This message has been edited by Charles Dietz (edited October 17, 2001).]

  • #2
    Charles, because your child window is a popup, it's coordinates are
    relative to the desktop, you just need to map the coordinates back to
    your dialog.

    keywords MapWindowPoints, ScreenToClient, ClientToScreen.

    Code:
    'Convert RECT structure from Screen to Client coordinates
    Call GetWindowRect(hWndChild,rc)
    Call MapWindowPoints(%HWND_DESKTOP,hWndClient,rc,2)
    Regards,
    Jules



    [This message has been edited by Jules Marchildon (edited October 17, 2001).]
    Best regards
    Jules
    www.rpmarchildon.com

    Comment


    • #3
      Alternatively, use DIALOG GET LOC on the parent, add your child values to those (ie, the 10 dialog units), then use DIALOG SET LOC. This saves the need to use API functions or delve into pixels, etc.

      For example, say the parent is at 100,100 and you want the child to be at 10,10 relative to the parent. Therefore, set the child to 110,110.

      IHTH!

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

      Comment


      • #4
        PS: I will ask R&D about this. It looks like DIALOG SET LOC is based on the desktop origin, rather than the parent dialog origin.


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

        Comment


        • #5
          Yes, seems to be problem with DIALOG GET/SET LOC in sub-dialogs.
          Many ways left to use - here another:
          Code:
                  IF CBCTL = 200 THEN
                     LOCAL rc AS RECT
                     GetWindowRect hDlg, rc
                     DIALOG PIXELS CBHNDL, rc.nLeft, rc.nTop TO UNITS rc.nLeft, rc.nTop
                     DIALOG SET LOC CBHNDL, rc.nLeft + 10, rc.nTop + 10
                  END IF

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

          Comment


          • #6
            Thank you all for your replies, but I still can't get what I want. Whether
            I use the API calls offered by Jules and Borje, or the DDT calls offered by
            Lance, the GET call retrieves the screen coordinates of the parent client area,
            whereas the SET call positions the child relative to the screen coordinates of
            the parent upper, left window corner. For example, the following code should
            not move the child window, but it does.

            Code:
                IF CBCTL = 200 THEN
                   DIALOG GET LOC hDlg TO x, y
                   DIALOG SET LOC CBHNDL, x, y
                END IF
            ------------------

            Comment


            • #7
              Can be tricky to position dialogs exactly without using API. GET LOC
              gives upper left position of main dialog, so if to position in client
              area, must calculate where that area is first. Menu and caption bar,
              etc. affects position. Without +10, sub-dialog stands still for me,
              like it should..
              Code:
                      IF CBCTL = 200 THEN
                         LOCAL rc AS RECT, rc2 AS RECT, x AS LONG, y AS LONG
                         GetWindowRect hDlg, rc
                         GetClientRect hDlg, rc2
                         rc.nLeft = rc.nLeft + ((rc.nRight - rc.nLeft) - (rc2.nRight - rc2.nLeft)) - 3
                         rc.nTop = rc.nTop + ((rc.nBottom - rc.nTop) - (rc2.nBottom - rc2.nTop)) - 3
                         DIALOG UNITS CBHNDL, 10, 10 TO PIXELS x, y
                         SetWindowPos CBHNDL, 0, rc.nLeft + x, rc.nTop + y, 0, 0, %SWP_NOSIZE OR %SWP_NOZORDER
                      END IF
              ------------------
              Deleted incorrect way and inserted more exact code.




              [This message has been edited by Borje Hagsten (edited October 17, 2001).]

              Comment


              • #8
                Thanks Borje,

                Its not perfect, but its pretty darn close... close enough for government work.

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

                Comment

                Working...
                X