Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i want to know how can i use the createpopupmenu() with api, i write class like this:
C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace test
{
  
        [DllImport("user32.dll")]
        public static extern int DestroyIcon(IntPtr hIcon);

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public extern static bool ShowWindow(IntPtr hWnd, int nCmdShow);

        public const int GWL_EXSTYLE = -20;
        public const int WM_CLOSE = 16;
        public const int WM_COPY = 0x0301;
        public const int WM_PASTE = 0x0302;
        public const int WM_CUT = 0x0300;
        public const int WM_ERASEBKGND = 0x0014;
        public const int WM_USER = 0x400;
        public const int WM_DEVICECHANGE = 0x219;

        public const int EM_GETSCROLLPOS = (WM_USER + 221);
        public const int EM_SETSCROLLPOS = (WM_USER + 222);

        [DllImport("user32.dll")]
        public static extern IntPtr SetWindowLong(IntPtr hWnd, Int32 nIndex, IntPtr dwNewLong);

        [DllImport("user32.dll")]
        public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref POINT point);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll")]
        public static extern IntPtr CreatePopupMenu();

        [DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern bool InsertMenu(IntPtr hmenu, int position, uint flags, IntPtr item_id, [MarshalAs(UnmanagedType.LPTStr)]string item_text);

        [Flags]
        public enum MenuFlags : uint
        {
            MF_STRING = 0,
            MF_BYPOSITION = 0x400,
            MF_SEPARATOR = 0x800,
            MF_REMOVE = 0x1000,
            MF_POPUP = 0x00000010,
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct POINT
        {
            public int x;
            public int y;
        }
    }
}


but i try to use this class and createpopupmenu() method to make menu for my form but it wont work ...? can any one guid me what am i do...?
tnx
Posted
Updated 6-May-13 22:47pm
v2
Comments
Richard MacCutchan 7-May-13 4:55am    
Why make life difficult for yourself? Go the the form designer and drag a ContextMenuStrip onto your form.
mohssenvox 7-May-13 10:39am    
:) i always choos hard way...
i want to learn how to work with api and draw menu...
Richard MacCutchan 7-May-13 10:52am    
In that case you should be using C++ and not C#.
mohssenvox 7-May-13 10:55am    
step by step, first i want to learn one language then second one....
its realy important for me to learn this...
Richard MacCutchan 7-May-13 12:59pm    
Well you are really going about it the wrong way trying to use the Windows API (written in C/C++) inside a C# program. Use either C++ or C# for learning, but don't mix them, you will just end up confused.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900