C 跨程序 設定視窗owner

2022-02-13 07:23:26 字數 2644 閱讀 8781

1

public

const

int wm_insertchart_completed = 0x00aa;2

3//查詢視窗

4 [dllimport("

user32.dll

", entrypoint = "

findwindow")]

5public

static

extern intptr findwindow(string lpclassname, string

lpwindowname);67

//傳送資訊

8 [dllimport("

user32.dll

", entrypoint = "

sendmessage")]

9public

static

extern

int sendmessage(intptr hwnd, int

msg, intptr wparam, intptr lparam);

1011

private

void

postmessage()

1219 }

還有乙個postmessage方法,和sendmessage類似。

在winform中,不同程序間視窗通訊

1

protected

override

void defwndproc(ref

message m)

2

在wpf中,如何在倆個不同程序的視窗之間通訊.

1

protected

override

void

onsourceinitialized(eventargs e)27

public

const

int wm_insertchart_completed = 0x00aa;8

public

static intptr wndproc(intptr hwnd, int msg, intptr wparam, intptr lparam, ref

bool

handled)914

15return

hwnd;

16 }

傳遞具體的資料,可參考:

此跨程序案例中,以子視窗a與父視窗b為例

windowb的控制代碼inptr,可以通過應用程式的名稱或者執行緒id,獲取視窗的控制代碼。具體可參考 c# 通過程序名/程序id 操作視窗

注:客戶端之間如果有跨執行緒通訊機制(區域網等),可以直接將父視窗b的控制代碼傳給另一程序的子視窗a

var helper = new windowinterophelper(windowa);

helper.owner = windowbinptr;

設定後,僅僅是顯示在父視窗b的上層。禁用父視窗見下~

子視窗a彈出後,向父視窗b傳送禁用視窗訊息:

其中,訊息值的定義,不能視窗自帶的訊息值。視窗自帶的訊息列表,可參考 

1

public

const

int msg_setwindowunenabled = 100000;2

public

const

int msg_setwindowenabled = 100001;3

4public

static

void

setwindowunenabled(intptr windowintptr)58

9public

static

void

setwindowenabled(intptr windowintptr)

1013

14//

傳送資訊

15 [dllimport("

user32.dll

", entrypoint = "

sendmessage")]

16public

static

extern

int sendmessage(intptr hwnd, int msg, intptr wparam, intptr lparam);

父視窗監聽訊息,並處理子視窗a傳送的視窗禁用訊息

1

protected

override

void

onsourceinitialized(eventargs e)27

8public intptr wndproc(intptr hwnd, int msg, intptr wparam, intptr lparam, ref

bool

handled)914

else

if (msg ==windowhandlehelper.msg_setwindowenabled)

1518

19return

hwnd;

20 }

以上設定將視窗a置於另一程序的視窗b上層,並將視窗b設定為禁用。

如果視窗a需要視窗反饋動畫(反饋動畫可以是模態,也可以是陰影,見我之前的水文《wpf window 子視窗反饋效果(抖動/陰影漸變)》)

C 跨程序 設定視窗owner

1 public const int wm insertchart completed 0x00aa 2 3 查詢視窗 4 dllimport user32.dll entrypoint findwindow 5public static extern intptr findwindow strin...

C 關閉其他程式視窗 程序

下面介紹我所知的兩種方法,應該對大家有幫助,如果有朋友知道其他的方法,謝謝共享一下。方法1procname 需要關閉的程序名稱 private bool closeproc string procname return result 上面程式裡定義了乙個arraylist,當不知道所要關閉的程序的具...

C 獲取視窗控制代碼,給視窗設定全域性熱鍵

最近沒事學習了下c 用mfc做了乙個小程式 點選應用程式視窗獲取程式控制程式碼,給應用程式設定全域性熱鍵,隱藏程式。思路 1.截獲滑鼠點選事件。2.獲取點選的視窗控制代碼。3.設定全域性熱鍵。4.響應熱鍵的事件。實現 1.截獲滑鼠點選事件。使用setcapture 將所有的滑鼠訊息據為己有。在捕獲過...