Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Lambda connection with winapi EnumWindows
Forum Updated to NodeBB v4.3 + New Features

Lambda connection with winapi EnumWindows

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 492 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Roberrt
    wrote on last edited by
    #1
    BOOL CALLBACK Enum_Windows_Callback(HWND handle, LPARAM lParam)
    {
    }
    
    HWND Find_Main_Window(unsigned long process_id)
    {
         EnumWindows(Enum_Windows_Callback, (LPARAM)&data);
         return data.window_handle;
    }
    

    I mean, is it possible to create the Enum_Windows_Callback inside of a lambda connection?

    Chris KawaC 1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #4

      No, you can't do that. QObject::connect function takes a QObject derived class instance as its first parameter. When that instance emits a signal a functor is called. That functor can be another QObject derived instance, a lambda or a class with () operator, but the first param has to be QObject, because it is the thing that emits a signal.

      You don't have objects at all in that code, just two functions, and even if you had, those are WinAPI functions. WinAPI knows nothing about existence of Qt and they certainly don't emit Qt signals, so there's nothing to connect that lambda to.

      You can pass a lambda to EnumWindows if you want

      EnumWindows([](HWND handle, LPARAM lParam){ return TRUE; }, (LPARAM)&data);
      

      but that has nothing to do with Qt.

      1 Reply Last reply
      2
      • R Roberrt
        BOOL CALLBACK Enum_Windows_Callback(HWND handle, LPARAM lParam)
        {
        }
        
        HWND Find_Main_Window(unsigned long process_id)
        {
             EnumWindows(Enum_Windows_Callback, (LPARAM)&data);
             return data.window_handle;
        }
        

        I mean, is it possible to create the Enum_Windows_Callback inside of a lambda connection?

        Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #2

        I'm not sure what you mean by a lambda connection. What is that? Do you mean you want to define a function inside a lambda expression? If that's the case then no, you can't nest functions in C++, otherwise what would be a signature of that function?

        If it's in a class then you have Class::method().
        In a namespace it's Namespace::function().
        What would it be for a lambda ???::function()?

        Can you describe what you want to achieve in more detail or give a code example (even if it's the wrong syntax) of what you'd like to do?

        R 1 Reply Last reply
        0
        • Chris KawaC Chris Kawa

          I'm not sure what you mean by a lambda connection. What is that? Do you mean you want to define a function inside a lambda expression? If that's the case then no, you can't nest functions in C++, otherwise what would be a signature of that function?

          If it's in a class then you have Class::method().
          In a namespace it's Namespace::function().
          What would it be for a lambda ???::function()?

          Can you describe what you want to achieve in more detail or give a code example (even if it's the wrong syntax) of what you'd like to do?

          R Offline
          R Offline
          Roberrt
          wrote on last edited by Roberrt
          #3

          @Chris-Kawa

          connect(<?>,  <the callback necessary for the winapi EnumWindows>, [this] (HWND handle, LPARAM lParam)
          {     
              //...
          });
          

          something like this

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #4

            No, you can't do that. QObject::connect function takes a QObject derived class instance as its first parameter. When that instance emits a signal a functor is called. That functor can be another QObject derived instance, a lambda or a class with () operator, but the first param has to be QObject, because it is the thing that emits a signal.

            You don't have objects at all in that code, just two functions, and even if you had, those are WinAPI functions. WinAPI knows nothing about existence of Qt and they certainly don't emit Qt signals, so there's nothing to connect that lambda to.

            You can pass a lambda to EnumWindows if you want

            EnumWindows([](HWND handle, LPARAM lParam){ return TRUE; }, (LPARAM)&data);
            

            but that has nothing to do with Qt.

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved