chr
7 天以前 43a0207d207390abdeeb3ab9155eebf03edd7b1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Runtime.InteropServices;
using System;
using System.ServiceProcess;
using System.Collections.Generic;
using SolidWorks.Interop.sldworks;
 
namespace PluginLisener
{
    public partial class PluginLisener : ServiceBase
    {
        public PluginLisener()
        {
            InitializeComponent();
        }
 
        private List<SldWorks> processIds = new List<SldWorks>();
 
        public static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
 
        protected override void OnStart(string[] args)
        {
            var SwApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
            int resp = 0;
            WTSSendMessage(
              WTS_CURRENT_SERVER_HANDLE,
              WTSGetActiveConsoleSessionId(),//获得当前显示的桌面所在的SessionID
                      "title", "title".Length,
              "message", "message".Length,
              0, 0, out resp, false);
        }
 
        public void StartScan() { 
            
        }
 
        protected override void OnStop()
        {
        }
 
        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern int WTSGetActiveConsoleSessionId();
 
        [DllImport("wtsapi32.dll", SetLastError = true)]
        public static extern bool WTSSendMessage( //一个Session中的进程可以用WTSSendMessage,让另一个Session弹出对话框
            IntPtr hServer,
      int SessionId,
      String pTitle,
      int TitleLength,
      String pMessage,
      int MessageLength,
      int Style,
      int Timeout,
      out int pResponse,
      bool bWait);
    }
}