Click here to Skip to main content
15,908,254 members
Home / Discussions / C#
   

C#

 
Questionregarding Microsoft Sync Framework Pin
Tridip Bhattacharjee9-Feb-10 2:47
professionalTridip Bhattacharjee9-Feb-10 2:47 
QuestionInsertMenuItem WinAPI problem Pin
Nematjon Rahmanov9-Feb-10 1:17
Nematjon Rahmanov9-Feb-10 1:17 
AnswerRe: InsertMenuItem WinAPI problem Pin
Luc Pattyn9-Feb-10 1:25
sitebuilderLuc Pattyn9-Feb-10 1:25 
QuestionRe: InsertMenuItem WinAPI problem Pin
Nematjon Rahmanov9-Feb-10 1:47
Nematjon Rahmanov9-Feb-10 1:47 
AnswerRe: InsertMenuItem WinAPI problem Pin
Covean9-Feb-10 2:08
Covean9-Feb-10 2:08 
GeneralRe: InsertMenuItem WinAPI problem Pin
Nematjon Rahmanov9-Feb-10 2:33
Nematjon Rahmanov9-Feb-10 2:33 
GeneralRe: InsertMenuItem WinAPI problem Pin
Covean9-Feb-10 2:49
Covean9-Feb-10 2:49 
GeneralRe: InsertMenuItem WinAPI problem Pin
Decco28-Feb-10 23:27
Decco28-Feb-10 23:27 
Thanks, I had exactly the same problem !
Here my new code, if it can help someone esle Smile | :)

[StructLayout(LayoutKind.Sequential)]
public struct MENUITEMINFO
{
    public uint cbSize;
    public uint fMask;
    public uint fType;
    public uint fState;
    public uint wID;
    public IntPtr hSubMenu;
    public IntPtr hbmpChecked;
    public IntPtr hbmpUnchecked;
    public IntPtr dwItemData;
    public string dwTypeData;
    public uint cch;
    public IntPtr hbmpItem;
}


public class DllImports
{
[DllImport("user32.dll")]
    public static extern bool InsertMenuItem(IntPtr hMenu, uint uPosition, uint uFlags, [In] ref MENUITEMINFO mii);

    [DllImport("user32")]
    public static extern UInt32 SetMenuItemBitmaps(IntPtr hMenu, uint uPosition, uint uFlags, IntPtr hBitmapUnchecked, IntPtr hBitmapChecked);
}


private void AddMenuItem(IntPtr hMenu, uint id, uint position, string text, Bitmap icon, IntPtr? hSubMenu)
{
    MENUITEMINFO mii = new MENUITEMINFO();
    mii.cbSize = (uint)Marshal.SizeOf(typeof(MENUITEMINFO)); //48;
    mii.fMask = (uint)MIIM.ID | (uint)MIIM.STRING | (uint)MIIM.SUBMENU;
    mii.wID = id;
    mii.dwTypeData = text;

    if (hSubMenu.HasValue)
    {
        mii.hSubMenu = hSubMenu.Value;
    }

    DllImports.InsertMenuItem(hMenu, position, (uint)MF.BYPOSITION, ref mii);

    if (icon != null)
    {
        DllImports.SetMenuItemBitmaps(hMenu, id, (uint)MF.BYCOMMAND, icon.GetHbitmap(), icon.GetHbitmap());
    }
}




The biggest problem was this line :

mii.cbSize = (uint)Marshal.SizeOf(typeof(MENUITEMINFO)); //48;


As in all exemples you found on web, the size is set to 48 by default and not calculate.

Thanks again.
Decco
QuestionSorting Pin
sachees1238-Feb-10 23:59
sachees1238-Feb-10 23:59 
AnswerRe: Sorting Pin
monstale9-Feb-10 0:38
monstale9-Feb-10 0:38 
GeneralRe: Sorting Pin
ThatsAlok9-Feb-10 0:57
ThatsAlok9-Feb-10 0:57 
AnswerRe: Sorting Pin
ThatsAlok9-Feb-10 0:41
ThatsAlok9-Feb-10 0:41 
AnswerRe: Sorting Pin
Luc Pattyn9-Feb-10 1:01
sitebuilderLuc Pattyn9-Feb-10 1:01 
AnswerRe: Sorting Pin
Dan Mos9-Feb-10 9:09
Dan Mos9-Feb-10 9:09 
Questionhow to retrive max value of a column by using c# Pin
inayat basha8-Feb-10 23:54
inayat basha8-Feb-10 23:54 
AnswerRe: how to retrive max value of a column by using c# Pin
ThatsAlok9-Feb-10 0:03
ThatsAlok9-Feb-10 0:03 
QuestionAuto Start programms Pin
Masterhame8-Feb-10 22:59
Masterhame8-Feb-10 22:59 
AnswerRe: Auto Start programms Pin
Gaurav Dudeja India8-Feb-10 23:05
Gaurav Dudeja India8-Feb-10 23:05 
AnswerRe: Auto Start programms Pin
Luc Pattyn8-Feb-10 23:58
sitebuilderLuc Pattyn8-Feb-10 23:58 
AnswerRe: Auto Start programms Pin
ThatsAlok9-Feb-10 0:07
ThatsAlok9-Feb-10 0:07 
AnswerRe: Auto Start programms Pin
PIEBALDconsult9-Feb-10 3:17
mvePIEBALDconsult9-Feb-10 3:17 
QuestionBackup Sql query Pin
Sivaooty8-Feb-10 22:33
Sivaooty8-Feb-10 22:33 
QuestionChart not working Pin
Wamuti8-Feb-10 22:16
Wamuti8-Feb-10 22:16 
AnswerRe: Chart not working Pin
Luc Pattyn9-Feb-10 0:01
sitebuilderLuc Pattyn9-Feb-10 0:01 
QuestionCasting Pin
jojoba20108-Feb-10 20:37
jojoba20108-Feb-10 20:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.