c++ - 在 Carbon App 中将焦点设置到 Cocoa 窗口

标签 c++ objective-c cocoa macos-carbon nswindow

我正在尝试在其他 Carbon 应用程序中创建一个 Cocoa 窗口(它是一个使用 AGL 的 OpenGL API。无法更改它所以不要对此发表评论)。

这是一个代码片段:

WindowRef winref = static_cast<eq::AGLWindow*>(getOSWindow())->getCarbonWindow();
vc = [[SFAttachedViewController alloc] initWithConfig:config]; //loads from view nib
NSPoint buttonPoint = NSMakePoint(event.pointerButtonPress.x + [cocoaWrap frame].origin.x, [cocoaWrap frame].size.height - event.pointerButtonPress.y + [cocoaWrap frame].origin.y);
MAAttachedWindow *attachedWindow = [[MAAttachedWindow alloc] initWithView:[vc view] attachedToPoint:buttonPoint onSide:side atDistance:0.0f]; // some Matt Gemmell goodness!

我尝试用以下行之一来展示它:

// A)
[NSApp runModalForWindow:[attachedWindow retain]]; // makes a white box
// B)
NSWindow *cocoaWrap = [[NSWindow alloc] initWithWindowRef:winref];
[cocoaWrap addChildWindow:attachedWindow ordered:NSWindowAbove];
// C)
[attachedWindow makeKeyAndOrderFront:NSApp];

窗口显示,但从未给出焦点。我无法编辑任何控件,所有内容都是灰色的。

帮忙!?

我试过了

HIViewRef viewRef;
HICocoaViewCreate([vc view], 0, &viewRef);
WindowRef attachedRef = (WindowRef)[attachedWindow windowRef];
SetKeyboardFocus(attachedRef, viewRef, kControlNoPart);

认为这可能是 Carbon/Cocoa 的问题,但无济于事。

最佳答案

在调用 Cocoa 方法之前是否调用了 NSApplicationLoad()

关于c++ - 在 Carbon App 中将焦点设置到 Cocoa 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3237228/

相关文章:

c++ - 枚举类默认整数值

c++ - 将 Boost.Spirit.Qi 与自定义词法分析器结合使用

cocoa - 如何在设置其字符串值后居中对齐 NSTextField

iphone - 从子类调用 UIPanGestureRecognizer touchesBegan 的警告

ios - 如何在后退按钮上重新加载以前的 View Controller ?

swift - NSImage 到 Base64 字符串丢失质量

objective-c - 从其他已经初始化的类中调用NSView

c++ - 我的问题是关于 C++ 中数字和序列的重复以及如何打印它们?

java - 在 Haxe 中检测目标语言

objective-c - 如何以编程方式获取使用大量能量的应用程序,例如 MacBook 的电池图标