⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 childwnd.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 2 页
字号:
    case WM_COMMAND:
        if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
            goto def;
        }
        break;
    case WM_PAINT:
        OnPaint(hWnd);
        return 0;
    case WM_SETCURSOR:
        if (LOWORD(lParam) == HTCLIENT) {
            POINT pt;
            GetCursorPos(&pt);
            ScreenToClient(hWnd, &pt);
            if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
                SetCursor(LoadCursor(0, IDC_SIZEWE));
                return TRUE;
            }
        }
        goto def;
    case WM_DESTROY:
		DestroyTreeView();
		DestroyListView(pChildWnd->hListWnd);
		DestroyMainMenu();
        HeapFree(GetProcessHeap(), 0, pChildWnd);
        pChildWnd = NULL;
        PostQuitMessage(0);
        break;
    case WM_LBUTTONDOWN: {
            RECT rt;
            POINTS pt;
            pt = MAKEPOINTS(lParam);
            GetClientRect(hWnd, &rt);
            if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
                last_split = pChildWnd->nSplitPos;
                draw_splitbar(hWnd, last_split);
                SetCapture(hWnd);
            }
            break;
        }

    case WM_LBUTTONUP:
        if (GetCapture() == hWnd) {
            RECT rt;
            POINTS pt;
            pt = MAKEPOINTS(lParam);
            GetClientRect(hWnd, &rt);
            pt.x = (SHORT) min(max(pt.x, SPLIT_MIN), rt.right - SPLIT_MIN);
            draw_splitbar(hWnd, last_split);
            last_split = -1;
            pChildWnd->nSplitPos = pt.x;
            ResizeWnd(pChildWnd, rt.right, rt.bottom);
            ReleaseCapture();
        }
        break;

    case WM_CAPTURECHANGED:
        if (GetCapture()==hWnd && last_split>=0)
            draw_splitbar(hWnd, last_split);
        break;

    case WM_KEYDOWN:
        if (wParam == VK_ESCAPE)
            if (GetCapture() == hWnd) {
                RECT rt;
                draw_splitbar(hWnd, last_split);
                GetClientRect(hWnd, &rt);
                ResizeWnd(pChildWnd, rt.right, rt.bottom);
                last_split = -1;
                ReleaseCapture();
                SetCursor(LoadCursor(0, IDC_ARROW));
            }
        break;

    case WM_MOUSEMOVE:
        if (GetCapture() == hWnd) {
            HDC hdc;
            RECT rt;
            HGDIOBJ OldObj;
            POINTS pt;
            if(!SizingPattern)
            {
              const DWORD Pattern[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
              SizingPattern = CreateBitmap(8, 8, 1, 1, Pattern);
            }
            if(!SizingBrush)
            {
              SizingBrush = CreatePatternBrush(SizingPattern);
            }

            pt = MAKEPOINTS(lParam);
            GetClientRect(hWnd, &rt);
            pt.x = (SHORT) min(max(pt.x, SPLIT_MIN), rt.right - SPLIT_MIN);
            if(last_split != pt.x)
            {
              rt.left = last_split-SPLIT_WIDTH/2;
              rt.right = last_split+SPLIT_WIDTH/2+1;
              hdc = GetDC(hWnd);
              OldObj = SelectObject(hdc, SizingBrush);
              PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, PATINVERT);
              last_split = pt.x;
              rt.left = pt.x-SPLIT_WIDTH/2;
              rt.right = pt.x+SPLIT_WIDTH/2+1;
              PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, PATINVERT);
              SelectObject(hdc, OldObj);
              ReleaseDC(hWnd, hdc);
            }
        }
        break;

    case WM_SETFOCUS:
        if (pChildWnd != NULL) {
            SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
        }
        break;

    case WM_TIMER:
        break;

    case WM_NOTIFY:
        if ((int)wParam == TREE_WINDOW) {
            switch (((LPNMHDR)lParam)->code) {
            case TVN_ITEMEXPANDING:
                return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
            case TVN_SELCHANGED: {
                    LPCTSTR keyPath, rootName;
		    LPTSTR fullPath;
                    HKEY hRootKey;

		    keyPath = GetItemPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, &hRootKey);
		    if (keyPath) {
		        RefreshListView(pChildWnd->hListWnd, hRootKey, keyPath);
			rootName = get_root_key_name(hRootKey);
			fullPath = HeapAlloc(GetProcessHeap(), 0, (_tcslen(rootName) + 1 + _tcslen(keyPath) + 1) * sizeof(TCHAR));
			if (fullPath) {
			    _stprintf(fullPath, _T("%s\\%s"), rootName, keyPath);
			    SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath);
				SendMessage(pChildWnd->hAddressBarWnd, WM_SETTEXT, 0, (LPARAM)fullPath);
			    HeapFree(GetProcessHeap(), 0, fullPath);

			    {
			        HKEY hKey;
			        TCHAR szBuffer[MAX_PATH];			
			    	_sntprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), _T("My Computer\\%s\\%s"), rootName, keyPath);

			    	if (RegCreateKey(HKEY_CURRENT_USER,
			        	g_szGeneralRegKey,
			    	    &hKey) == ERROR_SUCCESS)
			    	{
			    	    RegSetValueEx(hKey, _T("LastKey"), 0, REG_SZ, (LPBYTE) szBuffer, (DWORD) _tcslen(szBuffer) * sizeof(szBuffer[0]));
			    	    RegCloseKey(hKey);
			    	}
			    }
			}
		    }
                }
                break;
	    case NM_SETFOCUS:
		pChildWnd->nFocusPanel = 0;
		break;
            case TVN_BEGINLABELEDIT:
            {
				LPNMTVDISPINFO ptvdi;
				/* cancel label edit for rootkeys  */
				ptvdi = (LPNMTVDISPINFO) lParam;
                if (!TreeView_GetParent(pChildWnd->hTreeWnd, ptvdi->item.hItem) ||
					!TreeView_GetParent(pChildWnd->hTreeWnd, TreeView_GetParent(pChildWnd->hTreeWnd, ptvdi->item.hItem)))
                  return TRUE;
				break;
			}
            case TVN_ENDLABELEDIT:
                {
                  LPCTSTR keyPath;
                  HKEY hRootKey;
                  HKEY hKey = NULL;
                  LPNMTVDISPINFO ptvdi;
                  LONG lResult = ERROR_SUCCESS;
                  TCHAR szBuffer[MAX_PATH];

                  ptvdi = (LPNMTVDISPINFO) lParam;
                  if (ptvdi->item.pszText)
                  {
                    keyPath = GetItemPath(pChildWnd->hTreeWnd, TreeView_GetParent(pChildWnd->hTreeWnd, ptvdi->item.hItem), &hRootKey);
                    _sntprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), _T("%s\\%s"), keyPath, ptvdi->item.pszText);
                    keyPath = GetItemPath(pChildWnd->hTreeWnd, ptvdi->item.hItem, &hRootKey);
                    if (RegOpenKeyEx(hRootKey, szBuffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
                    {
                      lResult = REG_OPENED_EXISTING_KEY;
                      RegCloseKey(hKey);
                      (void)TreeView_EditLabel(pChildWnd->hTreeWnd, ptvdi->item.hItem);
                    }
                    else
                    {
                      lResult = RegRenameKey(hRootKey, keyPath, ptvdi->item.pszText);
                    }
                    return lResult;
                  }
                }
            default:
                return 0;
            }
        } else
        {
            if ((int)wParam == LIST_WINDOW)
            {
		switch (((LPNMHDR)lParam)->code) {
		  case NM_SETFOCUS:
		  	pChildWnd->nFocusPanel = 1;
		  	break;
		  default:
                	if(!ListWndNotifyProc(pChildWnd->hListWnd, wParam, lParam, &Result))
                	{
                  		goto def;
                	}
                	return Result;
                	break;
        	}
            }
        }
        break;

    case WM_CONTEXTMENU:
    {
      POINTS pt;
      if((HWND)wParam == pChildWnd->hListWnd)
      {
        int i, cnt;
        BOOL IsDefault;
        pt = MAKEPOINTS(lParam);
        cnt = ListView_GetSelectedCount(pChildWnd->hListWnd);
        i = ListView_GetNextItem(pChildWnd->hListWnd, -1, LVNI_FOCUSED | LVNI_SELECTED);
        FixPointIfContext(&pt, pChildWnd->hListWnd);
        if(i == -1)
        {
          TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW), TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
        }
        else
        {
          HMENU mnu = GetSubMenu(hPopupMenus, PM_MODIFYVALUE);
          SetMenuDefaultItem(mnu, ID_EDIT_MODIFY, MF_BYCOMMAND);
          IsDefault = IsDefaultValue(pChildWnd->hListWnd, i);
          if(cnt == 1)
            EnableMenuItem(mnu, ID_EDIT_RENAME, MF_BYCOMMAND | (IsDefault ? MF_DISABLED | MF_GRAYED : MF_ENABLED));
          else
            EnableMenuItem(mnu, ID_EDIT_RENAME, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
          EnableMenuItem(mnu, ID_EDIT_MODIFY, MF_BYCOMMAND | (cnt == 1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED));
          EnableMenuItem(mnu, ID_EDIT_MODIFY_BIN, MF_BYCOMMAND | (cnt == 1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED));

          TrackPopupMenu(mnu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
        }
      }
      else if ((HWND)wParam == pChildWnd->hTreeWnd)
      {
        TVHITTESTINFO hti;
        HMENU hContextMenu;
        TVITEM item;
        MENUITEMINFO mii;
        TCHAR resource[256];
        TCHAR buffer[256];
        LPTSTR s;
        LPCTSTR keyPath;
        HKEY hRootKey;
        int iLastPos;
        WORD wID;

        pt = MAKEPOINTS(lParam);
        hti.pt.x = pt.x;
        hti.pt.y = pt.y;
        ScreenToClient(pChildWnd->hTreeWnd, &hti.pt);
        (void)TreeView_HitTest(pChildWnd->hTreeWnd, &hti);

        if ((hti.flags & TVHT_ONITEM) != 0 || (pt.x == -1 && pt.y == -1))
        {
          hContextMenu = GetSubMenu(hPopupMenus, PM_TREECONTEXT);
          (void)TreeView_SelectItem(pChildWnd->hTreeWnd, hti.hItem);

          memset(&item, 0, sizeof(item));
          item.mask = TVIF_STATE | TVIF_CHILDREN;
          item.hItem = hti.hItem;
          (void)TreeView_GetItem(pChildWnd->hTreeWnd, &item);

          /* Set the Expand/Collapse menu item appropriately */
          LoadString(hInst, (item.state & TVIS_EXPANDED) ? IDS_COLLAPSE : IDS_EXPAND, buffer, sizeof(buffer) / sizeof(buffer[0]));
          memset(&mii, 0, sizeof(mii));
          mii.cbSize = sizeof(mii);
          mii.fMask = MIIM_STRING | MIIM_STATE | MIIM_ID;
          mii.fState = (item.cChildren > 0) ? MFS_DEFAULT : MFS_GRAYED;
          mii.wID = (item.state & TVIS_EXPANDED) ? ID_TREE_COLLAPSEBRANCH : ID_TREE_EXPANDBRANCH;
          mii.dwTypeData = (LPTSTR) buffer;
          SetMenuItemInfo(hContextMenu, 0, TRUE, &mii);

          /* Remove any existing suggestions */
          memset(&mii, 0, sizeof(mii));
          mii.cbSize = sizeof(mii);
          mii.fMask = MIIM_ID;
          GetMenuItemInfo(hContextMenu, GetMenuItemCount(hContextMenu) - 1, TRUE, &mii);
          if ((mii.wID >= ID_TREE_SUGGESTION_MIN) && (mii.wID <= ID_TREE_SUGGESTION_MAX))
		  {
            do
			{
              iLastPos = GetMenuItemCount(hContextMenu) - 1;
              GetMenuItemInfo(hContextMenu, iLastPos, TRUE, &mii);
              RemoveMenu(hContextMenu, iLastPos, MF_BYPOSITION);
			}
			while((mii.wID >= ID_TREE_SUGGESTION_MIN) && (mii.wID <= ID_TREE_SUGGESTION_MAX));
		  }

          /* Come up with suggestions */
          keyPath = GetItemPath(pChildWnd->hTreeWnd, NULL, &hRootKey);
          SuggestKeys(hRootKey, keyPath, Suggestions, sizeof(Suggestions) / sizeof(Suggestions[0]));
          if (Suggestions[0])
		  {
            AppendMenu(hContextMenu, MF_SEPARATOR, 0, NULL);

            LoadString(hInst, IDS_GOTO_SUGGESTED_KEY, resource, sizeof(resource) / sizeof(resource[0]));

            s = Suggestions;
            wID = ID_TREE_SUGGESTION_MIN;
            while(*s && (wID <= ID_TREE_SUGGESTION_MAX))
			{
              _sntprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), resource, s);

              memset(&mii, 0, sizeof(mii));
              mii.cbSize = sizeof(mii);
              mii.fMask = MIIM_STRING | MIIM_ID;
              mii.wID = wID++;
              mii.dwTypeData = buffer;
              InsertMenuItem(hContextMenu, GetMenuItemCount(hContextMenu), TRUE, &mii);

              s += _tcslen(s) + 1;
			}
		  }
          FixPointIfContext(&pt, pChildWnd->hTreeWnd);
          TrackPopupMenu(hContextMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, pChildWnd->hWnd, NULL);
        }
      }
      break;
    }

    case WM_SIZE:
        if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
            ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
        }
        /* fall through */
default: def:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -