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

📄 mainunit.pas

📁 三层的通用架构
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  end
  else
    Result := CallNextHookEx(MessageHook, Code, wParam, lParam);
end;

procedure TSetSelectOpenThread.Execute;
var
  i, j: Integer;
  Node: TTreeNode;
  aMenuItem, cMenuItem: TMenuItem;
  IndexArray: array of Integer;
begin
  FreeOnTerminate := True;
  with TheMainForm do
  begin
    N27.Visible := False;
    L5.Visible := False;
    SetAllTreeView(TreeView2);
    L5.Clear;
    for i := 0 to TreeView2.Items.Count - 1 do
    begin
      if FSetSelectOpening then
        Break;
      Node := TreeView2.Items[i];
      aMenuItem := TMenuItem.Create(nil);
      aMenuItem.Caption := Node.Text;
      if Node.Level = 0 then
        aMenuItem.Hint := '|' + Node.Text
      else begin
        aMenuItem.Hint := '|' + FIniFile.ReadString(FAllList[Integer(Node.Data)], 'Hint', '');
        aMenuItem.Tag := Integer(Node.Data);
      end;
      aMenuItem.ImageIndex := Node.ImageIndex;
      aMenuItem.SubMenuImages := ImageList1;
      aMenuItem.Enabled := (Node.Level > 0) and (FIniFile.ReadString(FAllList[Integer(Node.Data)], 'Type', '') = '功能项');
      aMenuItem.OnClick := DefaultSelectOpenClick;
      cMenuItem := L5;
      if Node.Level > 0 then
      begin
        SetLength(IndexArray, Node.Level);
        while Node.Level > 0 do
        begin
          Node := Node.Parent;
          IndexArray[Node.Level] := Node.Index;
        end;
        for j := 0 to Length(IndexArray) - 1 do
          cMenuItem := cMenuItem.Items[IndexArray[j]];
        cMenuItem.Enabled := True;
        cMenuItem.OnClick := nil;
      end;
      cMenuItem.Add(aMenuItem);
    end;
    if not FSetSelectOpening then
    begin
      N27.Visible := True;
      L5.Visible := True;
    end;
    FThread := nil;
  end;
end;

procedure TTheMainForm.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.WndParent := 0;
end;

procedure TTheMainForm.WmSysCommand(var Msg: TMessage);
var
  i: Integer;
begin
  with Msg do
    if WParam = CM_ABOUT then
      About.Execute
    else
      if WParam = CM_MINIMIZE then
      begin
        for i := 0 to FOpenedHandles.Count - 1 do
          try
            if IsWindowVisible(HWND(StrToInt(FOpenedHandles[i]))) then
              PostMessage(HWND(StrToInt(FOpenedHandles[i])), WM_SYSCOMMAND, SC_MINIMIZE, 0);
          except
          end;
        PostMessage(Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
      end
      else begin
        if (WindowState = wsNormal) and ((WParam = SC_MAXIMIZE) or (WParam = SC_MINIMIZE)) then
        begin
          FLeft := Left;
          FTop := Top;
          FWidth := Width;
          FHeight := Height;
        end;
        DefWindowProc(Handle, Msg, wParam, lParam);
      end;
end;

procedure TTheMainForm.CmDoSomething(var Msg: TMessage);
begin
  with Msg do
  begin
    if (wParam = 0) and (lParam = 0) then
      SetStatusBar;
    if (wParam = 1) and (lParam = 0) then
      AddViewString;
  end;
end;

function TTheMainForm.AppWindowHook(var Msg: TMessage): Boolean;
var
  TempP: ^Pointer;
begin
  Result := False;
  if Msg.Msg = FMessageID then
  begin
    Result := True;
    if (Msg.wParam < 2) and (HWND(Msg.lParam) > 0) then
    begin
      if Msg.wParam = 0 then
        FPBHandle := HWND(Msg.lParam);
      if Msg.wParam = 1 then
        FOpenedPBHandle := HWND(Msg.lParam);
    end;
    if (Msg.wParam = 2) and (Msg.lParam < 0) then
      FErrorString := PChar(@hMapView^.Data[0]);
    if (Msg.wParam = 3) and (Msg.lParam = 0) then
      FErrorString := 'Error';
    if Msg.wParam = 8 then
    begin
      if Msg.lParam = 0 then
        StrPCopy(@hMapView^.Data[0], FUserRealName);
      if Msg.lParam = 1 then
        StrPCopy(@hMapView^.Data[0], FUserAliasName);
      if Msg.lParam = 2 then
        StrPCopy(@hMapView^.Data[0], GetRegisterUser);
      if Msg.lParam = 3 then
      begin
        TempP := @hMapView^.Data[0];
        TempP^ := Pointer(FIniFile);
      end;
      if Msg.lParam = 4 then
      begin
        TempP := @hMapView^.Data[0];
        TempP^ := Pointer(FUserFile);
      end;
      if Msg.lParam = 5 then
        FIniMustSave := True;
    end;
  end;
end;

function TTheMainForm.GetColumnWidths: string;
var
  i: Integer;
begin
  Result := '';
  for i := 0 to ListView1.Columns.Count - 1 do
  begin
    if i > 0 then
      Result := Result + ',';
    Result := Result + IntToStr(ListView1.Column[i].Width);
  end;
end;

procedure TTheMainForm.ListView1DblClick(Sender: TObject);
begin
  if TListView(Sender).SeLected <> nil then
    OpenItem.Execute;
end;

procedure TTheMainForm.ListView1Edited(Sender: TObject; Item: TListItem;
  var S: String);
var
  Index: Integer;
begin
  if S = '' then
  begin
    S := Item.Caption;
    Exit;
  end;
  FIniMustSave := True;
  if Length(S) > 40 then
    S := Copy(S, 1, 40);
  Item.Caption := S;
  if Item.SubItems[1] = '功能组' then
  begin
    Index := SelectGroup(Item.SubItems[11], False, True);
    if Index > -1 then
      TreeView1.Selected.Item[Index].Text := S;
  end;
  FIniFile.WriteString(Item.SubItems[11], 'Name', S);
  if FSortNameFlag then
    SortName.Execute
  else
    SortIndex.Execute;
  Abort;
end;

function TTheMainForm.SelectGroup(const GroupName: string; SelectFlag: Boolean = True; CurrentFlag: Boolean = False): Integer;
var
  i, StartI, ToI: Integer;
  TreeNode: TTreeNode;
begin
  Result := -1;
  if (GroupName <> '') and (GroupName <> '回收站') then
  begin
    if CurrentFlag then
    begin
      StartI := 0;
      ToI := TreeView1.Selected.Count - 1;
    end
    else begin
      StartI := 1;
      ToI := TreeView1.Items.Count - 1;
    end;
    for i := StartI to ToI do
    begin
      if CurrentFlag then
        TreeNode := TreeView1.Selected.Item[i]
      else
        TreeNode := TreeView1.Items[i];
      if (TreeNode.Level > 0) and (FGroupList[Integer(TreeNode.Data)] = GroupName) then
      begin
        if SelectFlag then
        begin
          if not TreeNode.Selected then
            TreeNode.Selected := True;
          Result := 0;
        end
        else
          Result := i;
        Break;
      end;
    end;
  end
  else
    if not CurrentFlag then
    begin
      if GroupName = '' then
      begin
        if SelectFlag and not TreeView1.Items[0].Selected then
          TreeView1.Items[0].Selected := True;
        Result := 0;
      end
      else
        for i := 1 to TreeView1.Items.Count - 1 do
          if TreeView1.Items[i].Level = 0 then
          begin
            if SelectFlag then
            begin
              if not TreeView1.Items[i].Selected then
                TreeView1.Items[i].Selected := True;
              Result := 0;
            end
            else
              Result := i;
            Break;
          end;
    end;
end;

function TTheMainForm.SelectName(const Name: string; SelectFlag: Boolean = False): Integer;
var
  i: Integer;
begin
  Result := -1;
  for i := 0 to ListView1.Items.Count - 1 do
    if ListView1.Items[i].SubItems[11] = Name then
    begin
      Result := i;
      if SelectFlag then
        ListView1.Items[i].Selected := True;
    end;
end;

procedure TTheMainForm.UpdateComboBox;
var
  i: Integer;
  Node: TTreeNode;
  SelectedNodes: TStringList;
begin
  while ComboBoxEx1.ItemsEx.Count > 0 do
    ComboBoxEx1.ItemsEx.Delete(0);
  SelectedNodes := TStringList.Create;
  SelectedNodes.CaseSensitive := True;
  Node := TreeView1.Selected;
  while Node.Level > 1 do
  begin
    SelectedNodes.Add(IntToStr(Node.AbsoluteIndex));
    Node := Node.Parent;
  end;
  for i := 0 to TreeView1.Items.Count - 1 do
  begin
    Node := TreeView1.Items[i];
    if (Node.Level < 2) or (SelectedNodes.IndexOf(IntToStr(Node.AbsoluteIndex)) > -1) then
    begin
      with ComboBoxEx1.ItemsEx.Add do
      begin
        Indent := Node.Level;
        Caption := Node.Text;
        Data := Pointer(Node.AbsoluteIndex);
        ImageIndex := Node.ImageIndex;
        SelectedImageIndex := Node.SelectedIndex;
        OverlayImageIndex := -1;
      end;
      if Node.Selected then
        ComboBoxEx1.ItemIndex := ComboBoxEx1.ItemsEx.Count - 1;
    end;
  end;
  SelectedNodes.Free;
end;

procedure TTheMainForm.UpdateTreeView;
var
  ParentGroup, Value: string;
  i, ParentIndex: Integer;
begin
  FUpdateFlag := True;
  TreeView1.Tag := 1;
  TreeView1.Items.BeginUpdate;
  TreeView1.Items[0].DeleteChildren;
  TreeView1.Items[1].DeleteChildren;
  i := 0;
  while i < FGroupList.Count do
  begin
    ParentGroup := FIniFile.ReadString(FGroupList[i], 'Parent', '');
    Value := FIniFile.ReadString(FGroupList[i], 'Type', '');
    if ParentGroup = FGroupList[i] then ParentGroup := '';
    ParentIndex := FGroupList.IndexOf(ParentGroup);
    if ParentIndex < i then
    begin
      AddTreeView(ParentGroup, FGroupList[i]);
      i := i + 1;
    end
    else begin
      FGroupList.Move(i, FGroupList.Count - 1);
    end;
  end;
  if FGroupExpandList.Count > 0 then
  begin
    for i := 0 to TreeView1.Items.Count - 1 do
    begin
      if i = 0 then
        ParentGroup := ''
      else
        if TreeView1.Items[i].Level = 0 then
          ParentGroup := '回收站'
        else
          ParentGroup := FGroupList[Integer(TreeView1.Items[i].Data)];
      if FGroupExpandList.Values[ParentGroup] = '1' then
        TreeView1.Items[i].Expanded := True
      else

⌨️ 快捷键说明

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