CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2009
    Posts
    4

    I need some help for something simple!!

    Hi guys,

    I need to make a winamp plugin (General Purpose), which will send the text "WinampIsActive" via network (To: 127.0.0.1 Port: 1024) when winamp gets the focus (keyboard focus). I also need need it to send the text "WinampIsInactive" when it loses it.

    The thing is, I have'nt been coding in C++ for years; I'm really rusty so I need you help. It dosen't look too complicated; I have the base that works to make the plugin; here's the .h & .cpp code:

    gen_myplugin.h:

    Code:
      #ifndef gen_myplugin_h
        #define gen_myplugin_h
        #include <windows.h>
    
        #define GPPHDR_VER 0x10
        #define PLUGIN_NAME "My first generic Winamp plugin!"
    
        typedef struct {
          int version;                   // version of the plugin structure
          char *description;             // name/title of the plugin 
          int (*init)();                 // function which will be executed on init event
          void (*config)();              // function which will be executed on config event
          void (*quit)();                // function which will be executed on quit event
          HWND hwndParent;               // hwnd of the Winamp client main window (stored by Winamp when dll is loaded)
          HINSTANCE hDllInstance;        // hinstance of this plugin DLL. (stored by Winamp when dll is loaded) 
        } winampGeneralPurposePlugin;
    
      #endif

    gen_myplugin.cpp:

    Code:
      #include "stdafx.h"
      #include <windows.h>
      #include "gen_myplugin.h"
    
      int  init(void);
      void config(void);
      void quit(void);
    
      winampGeneralPurposePlugin plugin = {
        GPPHDR_VER,  // version of the plugin, defined in "gen_myplugin.h"
        PLUGIN_NAME, // name/title of the plugin, defined in "gen_myplugin.h"
        init,        // function name which will be executed on init event
        config,      // function name which will be executed on config event
        quit,        // function name which will be executed on quit event
        0,           // handle to Winamp main window, loaded by winamp when this dll is loaded
        0            // hinstance to this dll, loaded by winamp when this dll is loaded
      };
    
    
      // event functions follow
    
      int init() {
        //A basic messagebox that tells you the 'init' event has been triggered.
        //If everything works you should see this message when you start Winamp once your plugin has been installed.
        //You can change this later to do whatever you want (including nothing)
        MessageBox(plugin.hwndParent, L"Init event triggered for gen_myplugin. Plugin installed successfully!", L"", MB_OK);
        return 0;
      }
    
      void config() {
        //A basic messagebox that tells you the 'config' event has been triggered.
        //You can change this later to do whatever you want (including nothing)
        MessageBox(plugin.hwndParent, L"Config event triggered for gen_myplugin.", L"", MB_OK);
      }
    
      void quit() {
        //A basic messagebox that tells you the 'quit' event has been triggered.
        //If everything works you should see this message when you quit Winamp once your plugin has been installed.
        //You can change this later to do whatever you want (including nothing)
        MessageBox(0, L"Quit event triggered for gen_myplugin.", L"", MB_OK);
      }
    
    
      // This is an export function called by winamp which returns this plugin info.
      // We wrap the code in 'extern "C"' to ensure the export isn't mangled if used in a CPP file.
      extern "C" __declspec(dllexport) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin() {
        return &plugin;
      }
    Source: (http://dev.winamp.com/wiki/Beginner&#39;...c_Plugin_Guide)

    Thanx in advance!


    Ps: For those who want to know why I wanna make this plugin, well it is simply to bypass a focus issue in EventGhost that happens when winamp has no taskbar button (http://www.eventghost.org/forum/view...php?f=2&t=1986). That's the only solution I could think of!

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: I need some help for something simple!!

    I don't know anything about winamp, but I do know a little about plugins. Looks like you don't get much of an API. According to the above, Winamp only notifies the plugin during init, config, and quit. None of those tell any info about the focus state. It looks like you do get a handle to the winamp main HWND so you'll probably have to hook the wndproc to get notification messages for windows messages.

  3. #3
    Join Date
    Nov 2009
    Posts
    4

    Re: I need some help for something simple!!

    I think so too! But I never figured out how to implant succesfully a wndproc (

    If it's not too much to ask, could you make me a working sample that works with a given HWND?

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    Re: I need some help for something simple!!

    It's a little much to ask because I haven't done it in a long time so I had to plod my way through it. It's roughly like this:

    Code:
    HWND m_hHookedWnd;  //assume this is valid HWND
    WNDPROC m_OrigDlgProc=NULL;
    
    LRESULT MyCustomWndProc(HWND hWnd,UINT msg,WPARAM wp,LPARAM lp)
    {
      switch(msg){
        case WM_SETFOCUS:
          //do something
          break;  //or return TRUE to bypass default handling
      }
      //call original proc for everything else
      return m_OrigDlgProc(hWnd,msg,wp,lp);
    }
    
    void HookWndProc()
    {
      //replace the wndproc with new proc and keep a pointer to the original proc
      m_OrigDlgProc=(WNDPROC)::GetWindowLong(m_hHookedWnd,GWL_WNDPROC);
      ::SetWindowLong(m_hHookedWnd,GWL_WNDPROC,(LONG)MyCustomWndProc);
    }

  5. #5
    Join Date
    Nov 2009
    Posts
    4

    Smile Re: I need some help for something simple!!

    Allright! Looks simple! Very informative

    Just to be sure;

    - I must call HookWndProc() in the "init", right?
    - Is there anything to do to deactivate the hook? Something I'd need to put in the "quit" ?

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: I need some help for something simple!!

    Yes. Just call SetWindowLong again and pass the pointer to the original wndproc

  7. #7
    Join Date
    Nov 2009
    Posts
    4

    Re: I need some help for something simple!!

    Allright, thanx Gonna try that tonight!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured