小编Ten*_*ere的帖子

如何更改RichTextBox中某一行的背景颜色?

我想改变整行的颜色,无论文本是否存在.这是一些解释图像:

http://img131.imageshack.us/img131/1802/highlightlineqt2.png.

我在这里找到了一些解决方案,但我希望有一个更简单的解决方案.

.net winforms c#-4.0

6
推荐指数
1
解决办法
5159
查看次数

通用的奇怪行为

我遇到了泛型的奇怪行为.下面是我用于测试的代码.

public static class Program
{
    public static void Main()
    {
        Type listClassType = typeof(List<int>).GetGenericTypeDefinition();
        Type listInterfaceType = listClassType.GetInterfaces()[0];

        Console.WriteLine(listClassType.GetGenericArguments()[0].DeclaringType);
        Console.WriteLine(listInterfaceType.GetGenericArguments()[0].DeclaringType);
    }
}
Run Code Online (Sandbox Code Playgroud)

输出:

System.Collections.Generic.List`1[T]
System.Collections.Generic.List`1[T]
Run Code Online (Sandbox Code Playgroud)

我发现第二个Console.WriteLine调用显示一个类而不是一个接口是非常奇怪的,因为我使用泛型类型定义.这是正确的行为吗?

我正在尝试在我的编译器中实现泛型类型推断.假设我有以下代码.

public static class GenericClass
{
    public static void GenericMethod<TMethodParam>(IList<TMethodParam> list) { }
}
Run Code Online (Sandbox Code Playgroud)

我想将此方法称为如下:

GenericClass.GenericMethod(new List<int>());
Run Code Online (Sandbox Code Playgroud)

为了检查推理的可能性,我必须比较方法签名中的类型和传递的参数类型.但是下面的代码返回false.

typeof(GenericClass).GetMethods()[0].GetParameters()[0].ParameterType == listInterfaceType;
Run Code Online (Sandbox Code Playgroud)

我是否应该始终使用Type.GetGenericTypeDefinition进行此类比较?

c#

6
推荐指数
1
解决办法
255
查看次数

如何使用互斥锁严格交替使用两个线程?

我需要创建两个严格交替的线程.这是我使用的示例代码:

#include <Windows.h>
#include <iostream>
using std::cout;
using std::endl;

HANDLE g_hMutex1;
HANDLE g_hMutex2;

DWORD WINAPI ThreadFunc1(LPVOID lpParam);
DWORD WINAPI ThreadFunc2(LPVOID lpParam);

int main(void)
{
    int nCalcNumber = 10;
    DWORD dwThreadId;
    HANDLE pThreadHandles[2];

    g_hMutex1 = CreateMutex(NULL, FALSE, NULL);
    g_hMutex1 = CreateMutex(NULL, FALSE, NULL);

    pThreadHandles[0] = CreateThread(
        NULL,
        0,
        ThreadFunc1,
        static_cast<void*>(&nCalcNumber),
        0,
        &dwThreadId);

    pThreadHandles[1] = CreateThread(
        NULL,
        0,
        ThreadFunc2,
        static_cast<void*>(&nCalcNumber),
        0,
        &dwThreadId);

    WaitForMultipleObjects(2, pThreadHandles, TRUE, INFINITE);

    CloseHandle(pThreadHandles[0]);
    CloseHandle(pThreadHandles[1]);
    CloseHandle(g_hMutex1);
    CloseHandle(g_hMutex2);

    return 0;
}

DWORD WINAPI ThreadFunc1(LPVOID lpParam)
{
    int* nCalcNumber = static_cast<int*>(lpParam); …
Run Code Online (Sandbox Code Playgroud)

c++ winapi multithreading

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

OpenOffice.org API 还是 LibreOffice API?

我应该使用哪个 API?哪一个更有前途?我的主要目标是生成 ODF 文档。支持 ODF 1.2 对我来说很重要。我想使用 C++ 和 CLI。

openoffice.org odf uno libreoffice

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

标签 统计

.net ×1

c# ×1

c#-4.0 ×1

c++ ×1

libreoffice ×1

multithreading ×1

odf ×1

openoffice.org ×1

uno ×1

winapi ×1

winforms ×1