Hi Developers!

> And just one question: can i add a new menu item using plugin API or
> not?
 

 Yes of course! :)
 I have successfully added menu into TB!
 Look at attachment.


 Here is my example code:


[...]

std::vector<std::string>        sLabels;


void TBP_EXPORT TBP_Initialize()
{

    //search  TB main window:
    BOOL rc = EnumWindows(
//                                    hDesk,                            // 
handle to desktop to enumerate
                                    (WNDENUMPROC)EnumWindowsProc,   // points 
to application's callback function
                                    (LPARAM)&hMainWindow                // 
32-bit value to pass to the callback function
                                );




    HMENU hMenu = GetMenu(hMainWindow);

    hMyMenu = CreateMenu();

    sLabels.push_back("MenuItem 1");
    sLabels.push_back("MenuItem 2");
    sLabels.push_back("MenuItem 3");

    BuildMenu(hMyMenu);

    //add menu :
    rc = AppendMenu(
                    hMenu,
                    MF_POPUP,       // menu-item flags
                    (UINT)hMyMenu,  // menu-item identifier or handle of 
drop-down menu or submenu
                    "TB-Plugin"          // menu-item content
                   );

    //replace original window proc
#ifdef STRICT
    lpPrevMainWndProc = (WNDPROC)SetWindowLong(hMainWindow, GWL_WNDPROC, 
(LONG)MainWindowProc);
#else
    lpPrevMainWndProc = (FARPROC)SetWindowLong(hMainWindow, GWL_WNDPROC, 
(LONG)MainWindowProc);
#endif

    if(lpPrevMainWndProc)
        MessageBox(NULL, "OK", "OK", MB_OK);    //debug msg
}
 


//EnumChildProcedure
BOOL CALLBACK EnumWindowsProc(
                                 HWND hwnd,         // handle to child window
                                 LPARAM lParam  // application-defined value
                             )
{
    HWND *hMailer = (HWND*)lParam;

    TCHAR ClassName[256];
    LPTSTR lpClassName = ClassName;

    int Ret = GetClassName(hwnd,        // handle of window
                        lpClassName,    // address of buffer for class name
                        256             // size of buffer, in characters
    );

    if(strncmp(ClassName, "TMailerForm", 256) == 0)
    {
        *hMailer = hwnd;
        return FALSE;
    }
    return TRUE;
}


   
void BuildMenu(HMENU hMenu)
{
    MENUITEMINFO mii;
    ZeroMemory(&mii, sizeof(MENUITEMINFO));
    mii.cbSize = sizeof(MENUITEMINFO);

    for(int i=0; i<sLabels.size(); i++)
    {
        mii.fMask = MIIM_STRING | MIIM_ID;
        TCHAR* pLabel = new TCHAR[sLabels[i].size()+1];
        ZeroMemory(pLabel, sLabels[i].size()+1);
        CopyMemory(pLabel,
                  sLabels[i].c_str(),
                  sLabels[i].size()+1);
        mii.cch = sLabels[i].size();
        mii.dwTypeData = pLabel;
        mii.wID = 500 + i;

        InsertMenuItem( hMenu,
                        GetMenuItemCount(hMenu),
                        TRUE,
                        &mii
                      );
        delete [] pLabel;
    }
}

//my Main Window Proc to replace original
LRESULT CALLBACK MainWindowProc(
    HWND hwnd,  // handle of window
    UINT uMsg,  // message identifier
    WPARAM wParam,      // first message parameter
    LPARAM lParam       // second message parameter
   )
{
    LRESULT result;


    UINT wNotifyCode;       // notification code
    UINT wID;               // item, control, or accelerator identifier
    HWND hwndCtl;           // handle of control

    AnsiString Msg;
    int File;
    switch (uMsg)
    {
        case WM_COMMAND:

                wNotifyCode = HIWORD(wParam); // notification code
                wID = LOWORD(wParam);         // item, control, or accelerator 
identifier
                hwndCtl = (HWND) lParam;      // handle of control

                switch(wID)
                {
                    case 500: MessageBox(NULL, "MenuItem 1", "TB-Plugin", 
MB_OK); break;
                    case 501: MessageBox(NULL, "MenuItem 2", "TB-Plugin", 
MB_OK); break;
                    case 502: MessageBox(NULL, "MenuItem 3", "TB-Plugin", 
MB_OK); break;
                }

                break;
    }

    //call original proc:
    return CallWindowProc(lpPrevMainWndProc, hwnd, uMsg, wParam, lParam);
}

[...]



-- 
Best regards, Jacek Szumigaj
The Bat! 3.0.2.10/Windows XP 5.1

Attachment: TBMenuPlugin.png
Description: PNG image

________________________________________________
http://www.silverstones.com/thebat/TBUDLInfo.html

Reply via email to