CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Faltering Windows support
  • Internet Explorer 8 Click Clever Click Safe
  • Release Candidate 2 for ASP.NET MVC 2
  • Learn How to Create Dual Mode Windows Services

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 12th, 2009, 09:30 AM
    IceGothic IceGothic is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 4
    IceGothic is an unknown quantity at this point (<10)
    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&...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!
    Reply With Quote
      #2    
    Old November 12th, 2009, 10:15 AM
    hoxsiew hoxsiew is offline
    Senior Member
     
    Join Date: Feb 2005
    Posts: 1,471
    hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+)
    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.
    Reply With Quote
      #3    
    Old November 12th, 2009, 10:19 AM
    IceGothic IceGothic is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 4
    IceGothic is an unknown quantity at this point (<10)
    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?
    Reply With Quote
      #4    
    Old November 12th, 2009, 11:10 AM
    hoxsiew hoxsiew is offline
    Senior Member
     
    Join Date: Feb 2005
    Posts: 1,471
    hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+)
    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);
    }
    Reply With Quote
      #5    
    Old November 12th, 2009, 01:15 PM
    IceGothic IceGothic is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 4
    IceGothic is an unknown quantity at this point (<10)
    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" ?
    Reply With Quote
      #6    
    Old November 12th, 2009, 01:29 PM
    hoxsiew hoxsiew is offline
    Senior Member
     
    Join Date: Feb 2005
    Posts: 1,471
    hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+)
    Re: I need some help for something simple!!

    Yes. Just call SetWindowLong again and pass the pointer to the original wndproc
    Reply With Quote
      #7    
    Old November 12th, 2009, 01:35 PM
    IceGothic IceGothic is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 4
    IceGothic is an unknown quantity at this point (<10)
    Re: I need some help for something simple!!

    Allright, thanx Gonna try that tonight!
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 08:17 AM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.