小编cdy*_*yer的帖子

翻转NSView鼠标坐标

我有一个NSView的子类,它重新实现了许多鼠标事件功能.例如在mouseDown中从NSEvent获取点我使用:

NSEvent *theEvent; // <- argument to function

NSPoint p = [theEvent locationInWindow];
p = [self convertPoint:p fromView:nil];
Run Code Online (Sandbox Code Playgroud)

但是坐标似乎被翻转,(0,0)位于窗口的左下角?

编辑:我已经重写了isFlipped方法以返回TRUE,但它只影响了绘图.对不起,简直不敢相信我忘了把它直接放了.

macos cocoa

4
推荐指数
1
解决办法
2729
查看次数

ICU字节订单标记(BOM)

我正在使用ICU的ustdio函数将UnicodeString对象写入一系列编码中的文件,但它似乎不会添加BOM.

我的代码:

void write_file(const char* filename, UnicodeString &str) {

    UFILE* f = u_fopen(filename, "w", NULL, "UTF-16 LE");
    u_file_write(str.getTerminatedBuffer(), str.length() + 1, f);
    u_fclose(f);
}

int _tmain(int argc, _TCHAR* argv[])
{
    UnicodeString str(L"?????????");

    write_file("test.txt", str);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我将LE更改为BE时,文件编码会进行交换,但是没有BOM,十六进制编辑器中的输出文件是:

A0 03 B1 03  C1 03 B8 03  AD 03 BD 03  C9 03 BD 03  97 03 00 00
Run Code Online (Sandbox Code Playgroud)

注意:如果我将代码页设置为"UTF-16",则会有一个BOM,但是一旦我手动指定了字节序,它就会消失.

或者有没有办法将UnicodeString写入带有BOM的文件?

c++ unicode byte-order-mark endianness icu

3
推荐指数
1
解决办法
1104
查看次数

没有CDC的MFC字符串宽度

有没有办法在不使用CDC或使用未与显示器链接的CDC的情况下获取字符串的宽度(以像素为单位).需要检索字符串宽度的类不会从CWnd继承以使用CWnd :: GetDC(),并且无法将现有CDC传递给该函数.

我试图创建一个未与显示器链接的虚拟CDC,但这会导致MFC崩溃.理想情况如下:

m_font = new CFont();
m_font->CreatePointFont(size * 10, _T("Arial"));

m_tempCDC = new CDC();
m_tempCDC->SelectObject(m_font);

return m_tempCDC->GetOutputTextExtent(_T("Test")).cx;
Run Code Online (Sandbox Code Playgroud)

编辑:应该替换字符串文字的字体名称变量.

c++ mfc fontmetrics

3
推荐指数
1
解决办法
1729
查看次数

类类型范围

我在Xcode中有一个Objective-C++项目,它在正常的构建方案上编译得很好,但是当我为Archive,Analyze或Profile编译时,我得到了编译错误:

必须使用'class'标记来引用此范围中的'Line'类型

这是我的代码的一个非常简化的版本:

class Document;

class Line
{
public:
    Line();

private:
    friend class Document;
};

class Document
{
public:
    Document();

private:
    friend class Line;
};
Run Code Online (Sandbox Code Playgroud)

错误发生在我尝试使用Line类型的任何地方.例如.

Line *l = new Line();
Run Code Online (Sandbox Code Playgroud)

你知道如何解决这个错误信息以及为什么它只在编译上面列出的一个方案时出现?

c++ xcode objective-c++

3
推荐指数
1
解决办法
8888
查看次数