Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    C4D HWND

    PYTHON Development
    0
    14
    1.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 11/04/2013 at 09:32, xxxxxxxx wrote:

      Great, thanks!

      but that's a cpp function isn't it?
      I can use that in python? Oo

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 11/04/2013 at 11:49, xxxxxxxx wrote:

        ok, I found I can use c/cpp in python with Ctypes, but the problem is I can't find the .so files of the cpp api (that I found here: C:\Program Files\MAXON\CINEMA 4D R13\resource\_api)

        is the api already compiled for windows or should I do it myself?

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 11/04/2013 at 13:32, xxxxxxxx wrote:

          There is no dynamic library exposing the complete Cinema 4D API. You
          need to compile it on your own.

          -Niklas

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 12/04/2013 at 02:41, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            but that's a cpp function isn't it?
            I can use that in python? Oo

            Sorry, I didn't paid attention your question was related to the Python API.
            Why do you need main CINEMA 4D Window Handle?

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 12/04/2013 at 04:36, xxxxxxxx wrote:

              Yannick, could you please elaborate more on how to retrieve the Window handle?
              GetEditorWindow() returns an EditorWindow pointer and I don't see how it can be
              converted to an HWND. Thanks!

              -Niklas

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 12/04/2013 at 05:30, xxxxxxxx wrote:

                Originally posted by xxxxxxxx

                Yannick, could you please elaborate more on how to retrieve the Window handle?
                GetEditorWindow() returns an EditorWindow pointer and I don't see how it can be
                converted to an HWND. Thanks!

                Ok, I'll ask the developers to get more information on this.

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 12/04/2013 at 10:27, xxxxxxxx wrote:

                  Hi Yannick,

                  Basicaly, what I do is creating a Plug-in that will create a menu based on information given when c4d starts. those menus will be linked to apps that are supposed to be working with several softwares (maya, nuke, photoshop...)

                  the thing is that the majority of those apps runs with PySide and opens QtGui.QWidget.

                  now what I (try to) do is to link those QWidgets to the main c4d window because if I don't, I get an R6025 runtime error...

                  here is the part of the code from the maya Plug-in that I'm trying to reproduce, if it can help you see what I'm trying to do:

                  def show_dialog(self, title, bundle, widget_class, *args, **kwargs) :
                  _
                  _
                  _        import maya.OpenMayaUI as OpenMayaUI_
                  _        from PySide import QtCore, QtGui_
                  _        import shiboken_
                  _        _
                  _        # first construct the widget object _
                  _        obj = widget_class(*args, **kwargs)_
                  _
                  _
                  _        # now create a dialog to put it inside_
                  _        ptr = OpenMayaUI.MQtUtil.mainWindow()_
                  _        parent = shiboken.wrapInstance(long(ptr), QtGui.QMainWindow)_
                  _        self.log_debug("Parenting dialog to main window %08x %s" % (ptr, parent))_
                  _        dialog = myqdialog.MyQDialog(title, bundle, obj, parent)_

                  so what I'd like to make is the  ptr = OpenMayaUI.MQtUtil.mainWindow() part.

                  Hi Nicklas, first of all, thanks for the bad news ^^
                  I tried to compile the c4d API thanks to what I found in the CINEMA 4D R13\resource\_api_lib folder.

                  the problem is I can only make a static library. I tried to modify the properties to make a dll instead, but so far, I only get errors during compiling. And I'm beginning to wonder if it is even possible to create a dll ^^'

                  Ekibyo

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    On 15/04/2013 at 01:50, xxxxxxxx wrote:

                    Originally posted by xxxxxxxx

                    Yannick, could you please elaborate more on how to retrieve the Window handle?
                    GetEditorWindow() returns an EditorWindow pointer and I don't see how it can be
                    converted to an HWND.

                    You have to cast it into the system specific window handle type. E.g.:

                    HWND winHandle = (HWND)GetEditorWindow();
                    
                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      On 15/04/2013 at 02:30, xxxxxxxx wrote:

                      Originally posted by xxxxxxxx

                      Basicaly, what I do is creating a Plug-in that will create a menu based on information given when c4d starts. those menus will be linked to apps that are supposed to be working with several softwares (maya, nuke, photoshop...)

                      the thing is that the majority of those apps runs with PySide and opens QtGui.QWidget.

                      now what I (try to) do is to link those QWidgets to the main c4d window because if I don't, I get an R6025 runtime error...

                      here is the part of the code from the maya Plug-in that I'm trying to reproduce, if it can help you see what I'm trying to do:

                      ...

                      so what I'd like to make is the  ptr = OpenMayaUI.MQtUtil.mainWindow() part.

                      ...

                      Hi Ekibyo,

                      You'd better use an alternative with the Win32 API functions (like your first solution).
                      This thread on stackoverflow contains some useful information: http://stackoverflow.com/questions/1888863/how-to-get-main-window-handle-from-process-id

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        On 15/04/2013 at 08:26, xxxxxxxx wrote:

                        @Ekibyo:
                        First get the Cinema 4D API to compile (not necessarily the cinema4dsdk examples). I haven't yet
                        tried, but I'm sure there is a way to get all the symbols exported to a DLL in the API. But remember
                        that Cinema fills a function table containing all SDK functions when your plugin is loaded, and if
                        Cinema does not call c4d_main() from your DLL, you won't be able to use the exported functions.

                        @Yannick:
                        Thanks! I'll check that out.

                        1 Reply Last reply Reply Quote 0
                        • H
                          Helper
                          last edited by

                          On 15/04/2013 at 14:25, xxxxxxxx wrote:

                          thanks guys, I finally did it.

                          I found my hwnd using the win32api!

                          if somebody need to do it, here is how I did it:

                          use this function to enumerate all process
                          EnumWindows(EnumWindowsProc(enum_windows_proc), None)

                          create a function enum_windows_proc that will check if the hwnd given is the same as the c4d one.
                          if it is, check the class name (RealGetWindowClass(hwnd, buffer, buffer_len))
                          and make sure it correspond to something like that: C4DR_WIN1_130_0 (C4D version R13)

                          I got three of them, the last one was the good one!

                          thank you for your help Yannick, Nicklas. 😄

                          1 Reply Last reply Reply Quote 0
                          • H
                            Helper
                            last edited by

                            On 18/11/2014 at 03:08, xxxxxxxx wrote:

                            Were you ever able to get the shiboken wrapInstance method to work?

                            i came up with the following code but cinema freezes when i actually bind a qt widget to the instance returned by wrapInstance...

                            import ctypes
                            from Shiboken import *
                            from PySide import QtGui
                            GetWindowText = ctypes.windll.user32.GetWindowTextW
                            GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW

                            def getActiveWindow() :
                              curW = ctypes.windll.user32.GetForegroundWindow()#getActive window
                              parW = ctypes.windll.user32.GetWindow(curW,4)#get owner window
                             
                              length = GetWindowTextLength(parW)
                              buff = ctypes.create_unicode_buffer(length + 1)
                             
                              ctypes.windll.user32.GetWindowTextW(parW,buff,length+1)
                             
                              #print window text just to make sure we're good
                              print buff.value
                              return parW

                            app = QtGui.QApplication.instance()
                            if not app:app = QtGui.QApplication([])
                            ptr = getActiveWindow()
                            parent = shiboken.wrapInstance(ptr, QtGui.QMainWindow)
                            print parent,ptr
                            QtGui.QMessageBox.about(parent,'','Hello!!!') #this line cuses the freeze comment it out

                            any ideas???

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post