| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 659 人关注过本帖
标题:C# 如何通过句柄操作 Excel2003 的文件菜单项中的另存为项
只看楼主 加入收藏
xxp5310776
Rank: 1
来 自:湖北武汉
等 级:新手上路
帖 子:49
专家分:1
注 册:2006-11-19
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
C# 如何通过句柄操作 Excel2003 的文件菜单项中的另存为项
如题。GetSubMenu()无法获取到对应的句柄
 
   [DllImport("user32.dll", EntryPoint = "FindWindow")]

        public static extern int FindWindow1(

        string lpClassName,

        string lpWindowName

        );

        [DllImport("user32.dll", EntryPoint = "GetMenu")]

        public static extern int GetMenu1(

        int hwnd

        );

        [DllImport("user32.dll", EntryPoint = "GetSubMenu")]

        public static extern int GetSubMenu1(

        int hMenu,

        int nPos

        );

        [DllImport("user32.dll", EntryPoint = "GetMenuItemID")]

        public static extern int GetMenuItemID1(

        int hMenu,

        int nPos

        );

        [DllImport("user32.dll", EntryPoint = "PostMessage")]

        public static extern int PostMessage1(

        int hwnd,

        int wMsg,

        int wParam,

        int lParam

        );


        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("User32.dll", EntryPoint = "SendMessage")]
        private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);

        [DllImport("User32.dll ")]
        public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childe, string strclass, string FrmText);

        // 获取当前窗口句柄:GetForegroundWindow()
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetForegroundWindow();

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

        [DllImport("user32.dll", EntryPoint = "GetSubMenu")]
        public static extern IntPtr GetSubMenu(IntPtr hMenu, int nPos);

        [DllImport("user32.dll", EntryPoint = "GetMenuItemID")]
        public static extern IntPtr GetMenuItemID(IntPtr hMenu, int nPos);
        const int WM_COMMAND = 0x0111;


//调用菜单代码  但无法执行

            Process.Start(@"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE");
            Thread.Sleep(2000);

            int NotepadHwnd = FindWindow1(null, "Microsoft Excel - Book1");
            //取得外部程式的菜单Handle

            int gm = GetMenu1(NotepadHwnd);

            //取得第一个子菜单Handle


            gm = GetSubMenu1(gm, 0); //菜单的句柄 改变后面的0,就可以得到不同菜单的句柄

            int id = GetMenuItemID1(gm, 3); //子菜单"另存新档"的ID
            PostMessage1(NotepadHwnd, WM_COMMAND, id, 0);
搜索更多相关主题的帖子: public 如何 
2014-05-29 16:18
xxp5310776
Rank: 1
来 自:湖北武汉
等 级:新手上路
帖 子:49
专家分:1
注 册:2006-11-19
收藏
得分:0 
不知道各位大虾有没有看。
自己顶吧!!!

2014-05-30 10:59
xydddaxia
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:33
帖 子:466
专家分:2307
注 册:2009-3-20
收藏
得分:7 
发送一个 F12 按键消息就行了

站在春哥的肩膀上
2014-05-30 11:40
邓士林
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:淮河河畔
等 级:贵宾
威 望:61
帖 子:2392
专家分:13384
注 册:2013-3-3
收藏
得分:7 
没用过,这两天我正想将数据导出为Excel进行打印

Maybe
2014-05-30 22:58
快速回复:C# 如何通过句柄操作 Excel2003 的文件菜单项中的另存为项
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057331 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved