Announcement

Collapse
No announcement yet.

A receipt for question: "Save changes to ...?"

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

  • A receipt for question: "Save changes to ...?"

    Hello!
    I try windows Program (e.g. Excel, Word...) close:
    ...
    SendMessage hTargetWindow, %WM_CLOSE OR %WM_NCDESTROY, 0, 0
    ...
    and get: "Save changes to ...?" <Yes/No/Cancel>

    How can AUTOsave to... + CLOSE? without program
    message "Save changes to ...?" <Yes/No/Cancel> ???
    I like the change (doc, xls,...) save. (

    Thanks
    Alexander

  • #2
    First, you _cannot_ ever combine messages as you have done (%WM_CLOSE OR %WM_NCDESTROY)... you must send such messages separately!

    However, there is no reason at all to send a %WM_NCDESTROY message (this message should originate from Windows itself, not your code!), so just %WM_CLOSE should be adequate.

    To close the dialog that pop's up, you could try sending a %BM_CLICK message to the OK or NO button - to get the the handles to the buttons on the dialog, you could try using EnumChildWindows() - I think it works across process boundaries.




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

    Comment


    • #3
      Lance already cautioned ou about trying to send multiple messages with the OR operator...

      As far as your underlying question goes, what you need to do is process the WM_CLOSE message inside the target window.

      FUNCTION WindowProcOfTargetWindow (..params..)

      STATIC SaveNeeded AS LONG

      SELECT CASE WMsg

      ....
      CASE %WM_CLOSE
      IF SaveNeeded THEN
      SaveMe = MSGBOX("Save current file?" ...options)
      IF SaveMe= %IDYES...


      Etc etc

      MCM

      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        I don't suppose you have the source code to WORD or EXCEL lying around do you Michael?


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

        Comment


        • #5
          Alexander --
          To do this in VB is very easy
          Dim Word As Object
          Set Word = CreateObject("Word.Application")
          ...
          Word.Quit wdDoNotSaveChanges
          Set Word = Nothing

          But how do you work with such objects in PB ?



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

          Comment


          • #6
            I don't suppose you have the source code to WORD or EXCEL lying around do you Michael?
            I didn't read the question that way. I thought we wanted to know "How to do this, "like" Word(r) or Excel(r) do it.

            Or maybe it's the combimation of too many birthdays and the fact that my vacation is now scheduled.

            MCM

            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Lance --

              Thank for your hint, but my prog-a work without success.
              Can you help me?
              This is source:
              '=======================
              #COMPILE EXE
              #INCLUDE "WIN32API.INC"

              GLOBAL sWindowTitle AS STRING
              GLOBAL hTargetWindow AS LONG
              GLOBAL hButtonYes AS LONG

              FUNCTION PBMAIN
              'Running:
              '"C:\MSOffice\Office\WINWORD.EXE C:\TEMP\OPEN_CLOSE.DOC"

              sWindowTitle = "Microsoft Word - Open_Close.doc"
              hTargetWindow = FindWindow("", BYVAL STRPTR(sWindowTitle))

              SendMessage hTargetWindow, %WM_CLOSE, 0, 0
              SendMessage hTargetWindow, %WM_DESTROY, 0, 0
              'WM_DESTROY for save original windows size by close!!!

              '...dialog "Save changes to ...?" <Yes/No/Cancel>
              '...sWindowTitle = "Microsoft Word"
              '...hTargetWindow = FindWindow("", BYVAL STRPTR(sWindowTitle))
              EnumChildWindows hTargetWindow , hButtonYes, %IDYES
              ' The EnumChildWindows function - fail !??
              ' where is mistake?
              SendMessage hButtonYes, %BM_CLICK, 0, 0 'without success

              END FUNCTION
              '====================

              Thanks
              Alexander


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

              Comment


              • #8
                Lance --

                Hello!
                SUCCEED!!! YES!!!
                My simple sample:
                '-------------------------------------------------------
                #COMPILE EXE
                #INCLUDE "WIN32API.INC"

                GLOBAL sWindowTitle AS STRING
                GLOBAL hTargetWindow AS LONG
                GLOBAL sMsgboxTitle AS STRING
                GLOBAL hMsgboxWindow AS LONG
                GLOBAL hButtonYes AS LONG

                FUNCTION PBMAIN
                'Running:
                '"C:\MSOffice\Office\WINWORD.EXE C:\TEMP\OPEN_CLOSE.DOC"
                letsgo$="C:\MSOffice\Office\WINWORD.EXE C:\TEMP\OPEN_CLOSE.DOC"
                go& = SHELL(letsgo$,3)

                SLEEP 10000 ''...10 sec time for change | simulate change...

                '...close application
                sWindowTitle = "Microsoft Word - Open_Close.doc"
                hTargetWindow = FindWindow("", BYVAL STRPTR(sWindowTitle))
                PostMessage hTargetWindow, %WM_CLOSE, 0, 0
                PostMessage hTargetWindow, %WM_QUIT, 0, 0

                '...dialog "Save changes to ...?" <Yes/No/Cancel>
                '... YES!
                sMsgboxTitle = "Microsoft Word"
                hMsgboxWindow = FindWindow("", BYVAL STRPTR(sMsgboxTitle))
                hButtonYes=GetDlgItem(hMsgboxWindow, %IDYES)
                SendMessage hButtonYes, %BM_CLICK, 0, 0

                END FUNCTION
                '---------------------------------------------------------

                Thanks for your hint!
                Alexander


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

                Comment

                Working...
                X