7 Replies Latest reply on Dec 3, 2014 5:02 PM by helgesonc

    ProcessBook Add-In, display.Close(False) not working in ProcessBook 2012 SP1

    helgesonc

      Hello,

       

      I have a ProcessBook Add-In that opens and closes embedded displays in a PIW workbook via a VB.NET windows form opened from a toolbar button.  This add-in works fine in ProcessBook 3.2:  clicking a button on the form will open and close the desired displays behind the still-open form, as designed.

       

      In ProcessBook 2012 Sp1 (3.3.1.1160), however, the displays will not close while my Add-In form is open.  Once I close the Add-In form, all the displays that were supposed to already be closed then start to close.  Is there a reason why the behavior would be different in these two versions of ProcessBook?  Is there a known workaround for getting the behavior seen in ProcessBook 3.2 to work in ProcessBook 2012?

       

      Here are some code excerpts from the project (VB.NET 3.5):

       
      Dim entries as Entries = procBook.Entries
      Dim entry As Entry = Nothing
      For index as Integer = 1 to entries.Count
          entry = entries.Item(index)
          Dim display As Display = Nothing
          If CType(entry.Type, pbEntryLinkType) = pbEntryLinkType.pbEntryPDIEmbeddedInLocalPIW Then
              entry.Execute(True)
              display = procBook.Application.ActiveDisplay
              display.Close(False)    'doesn't work in PB 2012 SP1 until after Add-In form is closed
              display = Nothing
          End If
      Next
      

       Thanks,
      Caleb

        • Re: ProcessBook Add-In, display.Close(False) not working in ProcessBook 2012 SP1
          dhollebeek

          Yes, there actually is a reason for the change.  If several add-ins had a hook for the same display, if the first add-in closed the display, the subsequent add-ins would get an event fired into them for the display that had already closed.  Since there is no simple way for ProcessBook to know whether a display was closed during an event, we changed the display closing logic to be delayed until all event handlers have been called.  (To be really technical, display closing happens during CWinApp::OnIdle).  Since the PB app message loop doesn't get processed until the form is closed, you get the behavior you see.

           

          There is not a known workaround that I know of (this is the first time I've heard this particular complaint), but I would certainly help to see if we can find one.  The first thing I would try is using SendMessage to call ProcessBook's idle routine.  Take a look at the question and answer in this thread: stackoverflow.com/.../how-to-use-sendmessage-in-c .  You can ignore the stuff about journal hooks since you are not simulating the keyboard or mouse.  You may have to keep sending idle messages until it returns 0.

           

          Let me know if this works.

            • Re: ProcessBook Add-In, display.Close(False) not working in ProcessBook 2012 SP1
              helgesonc

              David,

               

              Thanks for the response.  I am unfamiliar with the SendMessage function and am not sure how it would be used to send idle messages to ProcessBook.  Do you happen to have a small code example I could try?

               

              Thanks,

               

              Caleb

                • Re: ProcessBook Add-In, display.Close(False) not working in ProcessBook 2012 SP1
                  mhamel

                  @Caleb: SendMessage type of coding is not the easiest thing to do as it utilizes P/Invoke code. I can suggest you these two links (this and that) showing nice examples similar what it is described here.

                    • Re: ProcessBook Add-In, display.Close(False) not working in ProcessBook 2012 SP1
                      rohanar

                      Mathieu & Davd,

                       

                      Are you referring to Windows Message such as WM_ENTERIDLE or a specific ProcessBook idle routine? Could you provide some direction as to which routine/params? Are there header files for ProcessBook available for reference? I haven’t had much luck with the disassembled EXE. I did try WM_ENTERIDLE using SendMessage in a thread (as described below), but believe that does the opposite of what we're looking for -- blocks instead of unblocks.  

                       

                      On a side-note, it seems the modal nature of our dialog is causing the messages sent by Display.Close(False) to be queued until our form is dismissed in PB  2012. As a test, I changed the modal MyForm.ShowDialog() to the modeless MyForm.Show(). In that case, Display.Close(False) worked immediately when called. Unfortunately, losing the Modal property would mean re-architecting the add-in. Is there any other way to force the display to close immediately or suppress the blocking that is occurring?

                       

                      Thanks!

                       

                      Dim pbHandle As IntPtr = Process.GetCurrentProcess.Handle

                       

                      Dim result As IntPtr

                       

                      Dim FormHandle As IntPtr = MyForm.Handle

                       

                      While True

                       

                           result = SendMessage(pbHandle, WM_ENTERIDLE, New IntPtr(0), FormHandle)

                       

                           If result = IntPtr.Zero Then

                       

                                Debug.WriteLine("SendMessage = 0") ' always returns 0

                       

                           Else

                       

                                Debug.WriteLine("SendMessage <> 0")

                       

                           End If

                       

                           Threading.Thread.Sleep(500)

                       

                      End While