第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

來(lái)自 Windows 服務(wù)的 PostMessage

來(lái)自 Windows 服務(wù)的 PostMessage

C#
慕哥6287543 2021-07-06 13:53:43
我的問(wèn)題是 PostMessage Windows API 工作不正常,因?yàn)樗趶目刂婆_(tái)應(yīng)用程序運(yùn)行時(shí)工作。工作代碼:我有 2 個(gè)應(yīng)用程序 [1] 是控制臺(tái)應(yīng)用程序 [2] Windows 窗體應(yīng)用程序。要求是我想向所有正在運(yùn)行的應(yīng)用程序?qū)嵗l(fā)送消息??刂婆_(tái)應(yīng)用程序代碼:class Program{    #region Dll Imports    public const int HWND_BROADCAST = 0xFFFF;    [DllImport("user32.dll")]    public static extern bool SetForegroundWindow(IntPtr hWnd);    [DllImport("user32")]    public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);    [DllImport("user32")]    public static extern int RegisterWindowMessage(string message);    #endregion Dll Imports    public static readonly int WM_ACTIVATEAPP = RegisterWindowMessage("CLOSE");    static void Main(string[] args)    {            //we tried to create a mutex, but there's already one (createdNew = false - another app created it before)            //so there's another instance of this application running        Process currentProcess = Process.GetCurrentProcess();        //get the process that has the same name as the current one but a different ID        foreach (Process process in Process.GetProcessesByName("ClientApp1"))        {            if (process.Id != currentProcess.Id)            {                IntPtr handle = process.MainWindowHandle;                //if the handle is non-zero then the main window is visible (but maybe somewhere in the background, that's the reason the user started a new instance)                //so just bring the window to front                //if (handle != IntPtr.Zero)                 }        }    }}上面的代碼按預(yù)期工作。我的問(wèn)題從這里開(kāi)始。我想從 Windows 服務(wù)而不是控制臺(tái)應(yīng)用程序運(yùn)行相同的代碼。需要立即指導(dǎo)。似乎當(dāng)我從 Windows 服務(wù)運(yùn)行此代碼時(shí),它沒(méi)有掌握進(jìn)程或服務(wù)在不同的帳戶中運(yùn)行,因此沒(méi)有傳遞消息。
查看完整描述

1 回答

?
胡說(shuō)叔叔

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊

很可能您在會(huì)話 0 中以本地系統(tǒng)帳戶的身份運(yùn)行您的服務(wù),并且出于充分的理由,它相當(dāng)孤立。例如,您無(wú)權(quán)訪問(wèn)其他桌面/會(huì)話。

您必須實(shí)現(xiàn)不同的 IPC 方法,例如管道或內(nèi)存映射文件。


查看完整回答
反對(duì) 回復(fù) 2021-07-10
  • 1 回答
  • 0 關(guān)注
  • 240 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)