Thread: ...how will I know...?

  1. #1
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708

    Question ...how will I know...?

    I need to recieve data dragged from another application into my program in the form of Clipboard data. Question: how will I know when the user has dropped the data "in" (my app will already be running)? I will use a thread, presumably, but I just don't know when to initiate the transfer. I thougt maybe windows sends my app a message, but of the possible ones, none seemed conspicuous. Nonetheless, I'll try those first, but if anyone here knows, I'd appreciate the tip!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Aargh! One more thing. Windows won't let me drag anything onto my app anyway! How do I tell it to do so?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708

    Post got it!

    Ok, here's a little class that will take care of the implementation.
    Just be sure to place the Allow() function under your WM_DROPFILES handler, and pass it your WPARAM.
    Enjoy.



    Code:
    class DragDrop {
     public:
    
     int file_count;
     String * files;
    
     void Allow(HWND hwnd) {
       DragAcceptFiles(hwnd, TRUE);
      }
    
     bool Accept(WPARAM wp) {
       if( files ){
        delete [] files;
       }
       iter = 0;
       data = (HDROP)wp;
       file_count =  DragQueryFile(data, 0xFFFFFFFF, NULL, 0);
       files = new String[ file_count ];
         if( files == NULL ){
          return false;
          }
       while(iter < file_count) {
        DragQueryFile(data, iter, buffer, 256);
        files[iter++] = buffer;
       }
      DragFinish(data);
      return true;
     }
    
     DragDrop()
     :files(NULL) {
      /* */
     }
    
     ~DragDrop() {
       if( files ){
        delete [] files;
       }
     }
     private:
    
      HDROP data;
      int iter;
      char buffer[256];
    
    };
    Last edited by Sebastiani; 10-26-2002 at 02:07 AM.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    I've had this in my favorites for a while, I hope it's of use to you: http://cprogramming.com/cboard/showt...&threadid=7829

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    ...or can register your wnd as a drop target by giving it the WS_EX_ACCEPTFILES extended style. Presumably that's what DragAcceptFiles does: calls SetWindowLong with the GWL_EXSTYLE flag to set the extended style bit.

Popular pages Recent additions subscribe to a feed