我是菜鸟,怎样创建一个三角形的窗口或者是任意形状的窗口?

解决方案 »

  1.   

    下面是一个主要的函数function TFrmMain.CreateRegion(wMask: TBitmap; wColor: TColor; hControl: THandle): HRGN;
    var
      dc, dc_c: HDC;
      rgn: HRGN;
      x, y: integer;
      coord: TPoint;
      line: boolean;
      color: TColor;
    begin
      dc := GetWindowDC(hControl);
      dc_c := CreateCompatibleDC(dc);
      SelectObject(dc_c, wMask.Handle);
      BeginPath(dc);
      for x := 0 to wMask.Width - 1 do
      begin
        line := false;
        for y := 0 to wMask.Height - 1 do
        begin
          color := GetPixel(dc_c, x, y);
          if not (color = wColor) then
          begin
            if not line then
            begin
              line := true;
              coord.x := x;
              coord.y := y;
            end;
          end;
          if (color = wColor) or (y = wMask.Height - 1) then
          begin
            if line then
            begin
              line := false;
              MoveToEx(dc, coord.x, coord.y, nil);
              LineTo(dc, coord.x, y);
              LineTo(dc, coord.x + 1, y);
              LineTo(dc, coord.x + 1, coord.y);
              CloseFigure(dc);
            end;
          end;
        end;
      end;
      EndPath(dc);
      rgn := PathToRegion(dc);
      ReleaseDC(hControl, dc);
      Result := rgn;
    end;下面是调用方法procedure TFrmMain.LoadSkin;
    var
      w2:TColor;
      rgn: HRGN;
    begin
      PlayerSKIN:='skin1.bmp';
      TimeTop:=35;
      TimeLeft:=16;  Image1.Picture.LoadFromFile(PlayerSKIN);
      Bitmap := TBitmap.Create;
      Bitmap.LoadFromFile(PlayerSKIN);
      MouseDownFlag := false;
      w2 := Bitmap.Canvas.Pixels[0, 0];
      rgn := CreateRegion(Bitmap, w2, Handle);
      if rgn <> 0 then
      begin
        SetWindowRgn(Handle, rgn, true);
      end;end;