簡體   English   中英

一個按鈕如何“附加”到另一個進程的窗口?

[英]How does one 'attach' a button to a window of another process?

我正在為Mac應用程序制作插件。 我希望插件易於使用,所以我想 UI元素“附加”到應用程序的窗口。 遺憾的是,該應用程序沒有一個API本身就可以支持此功能,因此我必須自己開發一種技術。

傳統上,在Windows OS上,我將SetParent()與包含控件的無邊界窗口一起使用。 但是在Mac上,我知道這種功能不存在。

但這使我陷入了兩難的境地。 有誰知道我可以使用的替代方法來實現此目標?

您可以向插件添加一個功能,該功能需要插入目標窗口,然后可以使用該插件向輸入的窗口添加對象。

- (void)addObjectToWindow:(NSWindow *)theWindow {
    if (!theWindow) {return;} // Exits if the window is nil
    NSButton *addButton = [[NSButton alloc] initWithFrame:NSMakeRect(10, 10, 30, 100)]; // modify the NSMakeRect numbers to change the size and position of the button
    [addButton setTitle:@"Button Title"]; // Sets the button text
    [[theWindow contentView] addSubview:addButton]; // Adds the button to the Windows view
}

多數民眾贊成:D,這只有在應用程序將此功能發送到插件時才有效。

希望這有幫助:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM