Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winapi TreeView项目在最小化后失去了浅色_Winapi_Treeview - Fatal编程技术网

Winapi TreeView项目在最小化后失去了浅色

Winapi TreeView项目在最小化后失去了浅色,winapi,treeview,Winapi,Treeview,我有一个简单的win32应用程序(不是对话框),这个应用程序中有treeview。 所有这些都可以工作,但如果我在树状视图中选择了项目,并且最小化并恢复了应用程序,则所选项目将从蓝色变为灰色。 如何在不使用自定义绘图的情况下更正此问题? 如果对话框中有treeview,则所选项目始终为蓝色 代码: 当窗口最小化时,树视图控件似乎失去了焦点。您可以尝试处理并使用手动设置树状视图控件的焦点。谢谢,这很有效。你能解释一下为什么在对话框中看不到这种行为吗?@Xerarinox:我不能马上说,但它可能与常

我有一个简单的win32应用程序(不是对话框),这个应用程序中有treeview。 所有这些都可以工作,但如果我在树状视图中选择了项目,并且最小化并恢复了应用程序,则所选项目将从蓝色变为灰色。 如何在不使用自定义绘图的情况下更正此问题? 如果对话框中有treeview,则所选项目始终为蓝色

代码:


当窗口最小化时,树视图控件似乎失去了焦点。您可以尝试处理并使用手动设置树状视图控件的焦点。

谢谢,这很有效。你能解释一下为什么在对话框中看不到这种行为吗?@Xerarinox:我不能马上说,但它可能与常规窗口与对话框的窗口激活/焦点分配规则有关。因为对话框包含激活时设置焦点的代码。因为您没有使用对话框,所以需要自己编写代码。
HWND g_hTree;

// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);

HINSTANCE hInst;

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.
    MSG Msg;

    MyRegisterClass(hInstance);

    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    return (int) Msg.wParam;
}


ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TREEVIEWTEST));
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_TREEVIEWTEST);
    wcex.lpszClassName  = L"TreeViewTestClass";
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   InitCommonControls();

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(L"TreeViewTestClass", L"Tree View Test", WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

void AddItems();

#define TVS_STYLES  (TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_INFOTIP | TVS_TRACKSELECT | WS_VSCROLL | WS_TABSTOP)
#define ID_TREEVIEW 505

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_CREATE:
        {
            g_hTree = CreateWindowEx(0, WC_TREEVIEWW, L"Test_Tree_View", WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_STYLES, 10, 10, 240, 480, hWnd, (HMENU)ID_TREEVIEW, NULL, NULL);
            AddItems();
        }
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // TODO: Add any drawing code here...
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

void AddItems()
{
    TVITEM tvi;
    HTREEITEM htSelected;
    TVINSERTSTRUCT tvinsert;   // struct to config out tree control
    HTREEITEM htParent;           // Tree item handle
    HTREEITEM htBefore;           // .......
    HTREEITEM htRoot;  

    tvinsert.hParent=NULL;          // top most level no need handle
    tvinsert.hInsertAfter=TVI_ROOT; // work as root level
    tvinsert.item.mask=TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
    tvinsert.item.pszText=L"Parent1";
    tvinsert.item.iImage=0;
    tvinsert.item.iSelectedImage=1;

    htParent = TreeView_InsertItem(g_hTree, &tvinsert);

    htRoot = htParent;
    htBefore = htParent;

    tvinsert.hParent=htParent;         // handle of the above data
    tvinsert.hInsertAfter=TVI_LAST;  // below parent
    tvinsert.item.pszText=L"Child 1";

    htParent = TreeView_InsertItem(g_hTree, &tvinsert);

    tvinsert.hParent=htParent;
    tvinsert.item.pszText=L"Child Of Child 1";

    htParent = TreeView_InsertItem(g_hTree, &tvinsert);

    tvinsert.hParent=htBefore;         // handle of the above data
    tvinsert.hInsertAfter=TVI_LAST;  // below parent
    tvinsert.item.pszText=L"Child 2";

    htParent = TreeView_InsertItem(g_hTree, &tvinsert);

    tvinsert.hParent=NULL;          // top most level no need handle
    tvinsert.hInsertAfter=TVI_LAST; // work as root level
    tvinsert.item.pszText=L"Parent2";

    htParent = TreeView_InsertItem(g_hTree, &tvinsert);

}