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

📄 unttool.pas

📁 半透明顯示在窗體上
💻 PAS
📖 第 1 页 / 共 3 页
字号:
*   Purpose:
*       To get whether window Show transparent is set
*   Date:
*       New Develop   :   2001-1-11
*       Modified      :   2001-1-11
*****************************************************************************}
function GetRegTransparent(var bTrans:Boolean):BOOL;
begin
  result := true;
  if not GetRegData(APP_KEY_SUBTRANSPARENT,@bTrans,SizeOf(bTrans)) then
  begin
    bTrans := true;
    SetRegTransparent(bTrans);
  end;
end;

{*****************************************************************************
*   Function GetRegShowTray
*   Purpose:
*       To get whether window Show in Tran Area is set
*   Date:
*       New Develop   :   2001-1-11
*       Modified      :   2001-1-11
*****************************************************************************}
function GetRegShowTray(var bOnTray:Boolean):BOOL;
begin
  result := true;
  if not GetRegData(APP_KEY_SUBSHOWTRAY,@bOnTray,SizeOf(bOnTray)) then
  begin
    bOnTray := true;
    SetRegShowTray(bOnTray);
  end;
end;

function GetRegClockStyle(var option:integer):BOOL;
begin
  result := true;
  if not GetRegData(APP_KEY_SUBCLOCKSTYLE,@option,SizeOf(option)) then
  begin
    option := IDM_CIRCLK;
    SetRegClockStyle(option);
  end;
end;

function GetRegShowOnTaskBar(var bShown : boolean):BOOL;
begin
  result := true;
  if not GetRegData(APP_KEY_SUBSHOWONTASKBAR,@bShown,SizeOf(bShown)) then
  begin
    bShown := false;
    SetRegShowOnTaskBar(bShown);
  end;
end;

function GetCheckBitmaps(fuCheck:UINT; menuID:integer):HBITMAP;
var
  crBackground : COLORREF;
  hbrBackground : HBRUSH;
  hbrTargetOld : HBRUSH;
  hdcSource, hdcTarget : HDC;
  bmCheckBox : BITMAP;
  hbmpCheckBoxes,
  hbmpSourceOld,
  hbmpTargetOld,
  hbmpCheck : HBITMAP;
  rc : TRECT;
  wBitmapX,wBitmapY : WORD;
begin
  // Get the Menu background color and crate a solid brush with this color
  crBackground := GetSysColor(COLOR_MENU);
  hbrBackground := CreateSolidBrush(crBackground);

  // Create memory device contexts for the source and destination bitmaps

  hdcSource := CreateCompatibleDC(0);
  hdcTarget := CreateCompatibleDC(hdcSource);

  // Get the size of the system defalt check-mark bitmap and
  // create a compatible bitmap of the same size
  wBitmapX := GetSystemMetrics(SM_CXMENUCHECK);
  wBitmapY := GetSystemMetrics(SM_CYMENUCHECK);
  hbmpCheck := CreateCompatibleBitmap(hdcSource,wBitmapX,wBitmapY);

  // select the background bursh and bitmap into the target DC
  hbrTargetOld := SelectObject(hdcTarget, hbrBackground);
  hbmpTargetOld := SelectObject(hdcTarget, hbmpCheck);

  // use the selected brush to initialize the background color
  // of the bitmap in the target device context

  PatBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, PATCOPY);

  // load the predefined check box bitmaps and select it
  // into the source DC
  hbmpCheckBoxes := //LoadImage(hInstance,'ICON_MENUCLKSET',IMAGE_ICON,0,0,
      //LR_DEFAULTSIZE);
      LoadBitmap(hInstance,'BITMAP_MENUCLKSET');
  hbmpSourceOld := SelectObject(hdcSource, hbmpCheckBoxes);

  // fill a BITMAP structrure with information about the
  // check box bitmaps and then find the upper-left corner of
  // the unchecked check box or the checked check box

  GetObject(hbmpCheckBoxes, sizeof(bmCheckBox), @bmCheckBox);
  if fuCheck = MF_CHECKED then begin
    rc.left := 0;
    rc.right := bmCheckBox.bmWidth;
  end
  else begin
    rc.Left := 0;
    rc.Right := bmCheckBox.bmWidth;
  end;
  rc.Top := 0;
  rc.Bottom := bmCheckBox.bmHeight ;

  // copy the appropriate bitmap into the target DC. if the
  // check-box bitmap is larger than the default check-mark
  // bitmap, use StrechBlt to make it fit; otherwise , just
  // Copy it

  if ( rc.Right - rc.Left > wBitmapX) or
     ( rc.Bottom - rc.Top > wBitmapY) then
  begin
    StretchBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY,
        hdcSource, rc.left, rc.top, rc.right - rc.left,
        rc.bottom - rc.top, SRCCOPY);
  end
  else begin
    BitBlt(hdcTarget, 0, 0, rc.right - rc.left,
        rc.bottom - rc.top,
        hdcSource, rc.left, rc.top, SRCCOPY);
  end;

  // select the old source and destination bitmaps into the
  // source and destination DCs and then delete the DCs and
  // the background brush

  SelectObject(hdcSource, hbmpSourceOld);
  SelectObject(hdcTarget, hbrTargetOld);
  hbmpCheck := SelectObject(hdcTarget, hbmpTargetOld);

  DeleteObject(hbrBackground);
  DeleteObject(hdcSource);
  DeleteObject(hdcTarget);

  // return a handle to the new check-mark bitmap

  result := hbmpCheck;
end;

function SetMenuOwnerDraw(menu : HMENU; cmdID : integer):BOOL;
var
  menuInfo : TMENUITEMINFO;
begin
  result := false;
  if menu = 0 then exit;
  //if not GetMenuItemInfo(menu, cmdID, FALSE, menuInfo) then exit;
  menuInfo.cbSize := SizeOf(menuInfo);
  menuInfo.fMask := MIIM_CHECKMARKS or MIIM_DATA or MIIM_ID or
        MIIM_STATE or MIIM_SUBMENU or MIIM_TYPE;
  menuInfo.fType := MFT_OWNERDRAW;
  menuInfo.wID := cmdID;
  menuInfo.fState := MFS_DEFAULT;
  menuInfo.hSubMenu := 0;
  menuInfo.hbmpChecked := 0;
  menuInfo.hbmpUnchecked := 0;
  menuInfo.hbmpItem := 0;
  menuInfo.dwItemData := 0;
  menuInfo.dwTypeData := 'Hello';
  SetMenuItemInfo(menu, cmdID, FALSE, menuInfo);
end;

function DrawBmpMenu(itemMenu : DRAWITEMSTRUCT):BOOL;
var
  orgrect, rG, rect: TRect;
  p : TPoint;
  DC : HDC;
  bmpDC : HDC;
  lb : LOGBRUSH;
  oldBrush,Brush : HBRUSH;
  oldbmp,bmp,bufBmp : HBITMAP;
  BKcolor,txtColor : DWORD;
  oldRight : integer;
  i : integer;
begin
  rect := itemMenu.rcItem;
  //DC := CreateCompatibleDC(itemMenu.hDC);
  DC := itemMenu.hDC;
  {
  bufBmp := CreateCompatibleBitmap(DC,
      rect.right - rect.left,rect.bottom-rect.top);
  SelectObject(DC,bufBmp);
  }
  //Brush := CreateSolidBrush(GetSysColor(COLOR_MENU));
  //SelectObject(DC,brush);
  //DeleteObject(brush);
  //DC := itemMenu.hDC;
  orgrect := rect;
  {
  rect.Bottom := rect.Bottom -rect.Top;
  rect.Right := rect.Right - rect.left;
  rect.top := 0;
  rect.left := 0;
  }
  bmpDC := CreateCompatibleDC(DC);
  if  (itemMenu.itemAction = ODA_DRAWENTIRE) then  begin
    BKcolor := GetSysColor(COLOR_MENU);
    txtColor := GetSysColor(COLOR_MENUTEXT);
  end
  else if itemMenu.itemAction = ODA_SELECT then begin
    if not BOOL(itemMenu.itemState and ODS_SELECTED) then begin
      BKcolor := GetSysColor(COLOR_MENU);
      txtColor := GetSysColor(COLOR_MENUTEXT);
    end
    else begin
      BKcolor := GetSysColor(COLOR_HIGHLIGHT);
      txtColor := GetSysColor(COLOR_HIGHLIGHTTEXT);
    end;
  end;

  {
  rG := rect;
  Inc(rG.Left, 20);
  if BKColor = GetSysColor(COLOR_HIGHLIGHT) then begin
    for i:= 1 to 120 do begin
      Brush := CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT) +
        i*(Abs(GetSysColor(COLOR_HIGHLIGHT)-GetSysColor(COLOR_MENU)) div 120));
      rG.Left := rg.Left +(rect.right-rect.left-20) div 120;
      rG.right := rG.Left + (rect.right - rect.left - 20) div 120;
      FillRect(DC,rG,Brush);
      DeleteObject(Brush);
    end;
  end else begin }
    Brush := CreateSolidBrush(DWORD(BKcolor));
    FillRect(DC,rect,Brush);
    DeleteObject(Brush);
 { end; }
  rG := rect;
  rG.Right := rect.Left +19;
  Brush := CreateSolidBrush(GetSysColor(COLOR_MENU));
  FillRect(DC,rG,Brush);
  DeleteObject(Brush);
  bmp := LoadBitmap(hInstance,'BITMAP_MENUCLKSET');
  oldbmp := SelectObject(bmpDC,bmp);
  Bitblt(DC,rect.left+3,rect.top+4,12,12,bmpDC,0,0,SRCCOPY);
  SetBkColor(DC,BKcolor);
  SetTextColor(DC,txtColor);
  TextOut(DC,rect.left + 22,rect.top+2,'Clock setting',13);
  if BKColor = GetSysColor(COLOR_HIGHLIGHT) then
  begin
    Brush := CreateSolidBrush(RGB(255,0,0));
    Inc(rect.Left,18);
    FrameRect(DC,rect,Brush);
    DeleteObject(Brush);
    Dec(rect.Left,18);
    OldRight := rect.Right;
    rect.Right := rect.Left + 17;
    DrawEdge(DC,rect,EDGE_RAISED,BF_RECT);
    rect.Right := OldRight;
  end;
  {
  BitBlt(itemMenu.hDC,orgrect.Left,orgrect.Top,
          orgrect.Right - orgrect.Left,
          orgrect.Bottom - orgrect.top,
          DC,rect.Left,rect.top,SRCCOPY);
  }
  SelectObject(bmpDC,oldbmp);
  DeleteDC(bmpDC);
  {DeleteDC(DC);}
  {DeleteObject(bufBmp);}
  DeleteObject(bmp);

end;

function CreateRgnFromBmp(bmp : HBITMAP):HRGN;
var
  bmpSize : BITMAP;
  oldbmp : HBITMAP;
  R , R1: HRGN;
  DC : HDC;
  transColor : COLORREF;
  iWidth, iHeight, oldHeight : integer;
begin
  GetObject(bmp,SizeOf(bmpSize),@bmpSize);
  R := CreateRectRgn(0,0,bmpSize.bmWidth, bmpSize.bmHeight);
  DC := CreateCompatibleDC(0);
  oldbmp := SelectObject(DC,bmp);
  transColor := GetPixel(DC,0,0);

  for iWidth:=0 to bmpSize.bmWidth -1 do
  begin
    iHeight := 0;
    while iHeight < bmpSize.bmHeight do
    //for iHeight := 0 to bmpSize.bmHeight -1 do
    begin
      if GetPixel(DC,iWidth,iHeight) = transColor then
      begin
        oldHeight := iHeight;
        while (iHeight<bmpSize.bmHeight) and
              (GetPixel(DC,iWidth,iHeight+1)=transColor) do
                  inc(iHeight);
        R1 := CreateRectRgn(iWidth,oldHeight,iWidth + 1,iHeight + 1);
        CombineRgn(R,R,R1,RGN_DIFF);
        DeleteObject(R1);
      end else ;
        inc(iHeight);
    end;
  end;
  SelectObject(DC,oldBmp);
  DeleteDC(DC);
  result := R;
end;

function CreateAlfaRgn(x,y,r,Alfa,halfWidth,ArrowLen:integer):HRGN;
var
  Ps : Array[1..5] of TPoint;
  deg : double;
begin
  deg := Alfa * (2*pi)/360;
  Ps[1].x := Trunc(x - HalfWidth * sin(deg));
  Ps[1].y := Trunc(y - HalfWidth * cos(deg));
  Ps[2].x := Trunc(x + (r - ArrowLen) * cos(deg) - HalfWidth * sin(deg));
  Ps[2].y := Trunc(y - (r - ArrowLen) * sin(deg) - HalfWidth * cos(deg));
  Ps[3].x := Trunc(x + r * cos(deg));
  Ps[3].y := Trunc(y - r * sin(deg));
  Ps[4].x := Trunc(x + (r - ArrowLen) * cos(deg) + HalfWidth * sin(deg));
  Ps[4].y := Trunc(y - (r - ArrowLen) * sin(deg) + HalfWidth * cos(deg));
  Ps[5].x := Trunc(x + HalfWidth * sin(deg));
  Ps[5].y := Trunc(y + HalfWidth * cos(deg));
  result := CreatePolygonRgn(Ps, 5, WINDING);
end;

function CreateHourRgn(hour,minute:integer):HRGN;
var
  d : double;
  Alfa : integer;
begin
  d := hour + minute / 60;
  if (d - 12) > 0.001 then d:= d -12;
  Alfa := Trunc(6 * (15 - d * 5));
  result :=
    CreateAlfaRgn(WIN_HALF_WIDTH, WIN_HALF_WIDTH, WIN_HALF_WIDTH - 17,
      Alfa, 3, 5);

  if BOOL(RgnCenter) then
    CombineRgn(Result,Result,RgnCenter,RGN_DIFF);

end;

function CreateMinuteRgn(minute:integer):HRGN;
var
  Alfa : integer;
begin
  Alfa := (15 - minute) * 6;
  result :=
    CreateAlfaRgn(WIN_HALF_WIDTH, WIN_HALF_WIDTH, WIN_HALF_WIDTH - 12,
      Alfa, 2, 4);

  if BOOL(RgnCenter) then
    CombineRgn(Result,Result,RgnCenter,RGN_DIFF);
  
end;

function CreateSecondRgn(second:integer):HRGN;
var
  Alfa : integer;
begin
  Alfa := ( 15 - second) * 6;
  result :=
    CreateAlfaRgn(WIN_HALF_WIDTH, WIN_HALF_WIDTH, WIN_HALF_WIDTH - 5,
      Alfa, 1, 0);

  if BOOL(RgnCenter) then
    CombineRgn(Result,Result,RgnCenter,RGN_DIFF);
  
end;

end.

⌨️ 快捷键说明

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