在桌面上显示一个窗体/图像的多个实例



我试图在桌面上的不同位置多次显示图像,但我不知道如何去做。现在我正在尝试Wxruby,但我想知道是否有另一种方法可以做到这一点,我错过了。

到目前为止,我能够在一个位置用wxruby显示一个图像,这与其中一个示例非常相似:
require 'wx'
include Wx
class Warning < Wx::App
  include Wx
  def on_init(x = 300, y = 300)
    @frame = Frame.new( nil, -1, "Application", Point.new(x,y), Size.new(50,50), FRAME_SHAPED|SIMPLE_BORDER|FRAME_NO_TASKBAR|STAY_ON_TOP)
    @frame.show
    @has_shape = false
    @delta = [0,0]
    evt_paint {on_paint}
    shape = File.join( 'pathToImage' )
    @bmp = Bitmap.new( Image.new(shape) )
    @frame.set_client_size(@bmp.width, @bmp.height)
    if PLATFORM == 'WXGTK'
      # wxGTK requires that the window be created before you can
      # set its shape, so delay the call to SetWindowShape until
      # this event.
      evt_window_create { set_window_shape }
    else
      # On wxMSW and wxMac the window has already been created, so go for it.
      set_window_shape
    end
    #@frame.paint { | dc | dc.draw_bitmap(@bmp, 0, 0, true) }
  end
  def set_window_shape
    r = Region.new(@bmp)
    @has_shape = @frame.set_shape(r)
  end
  def on_paint
    @frame.paint { | dc | dc.draw_bitmap(@bmp, 0, 0, true) }
  end
end
app = Warning.new
app.main_loop

我终于想通了!这个ruby脚本使用wx gem来显示有形状的窗口,并使用一些windows的东西来获得当前的屏幕分辨率(我假设是主显示器)。

它获得分辨率,然后是你想要在桌面上显示的图像的宽度/高度。关于图像的一个注意事项,当wx显示图像时(我不知道它是否只是用于形状窗口),图像的任何部分都是纯黑色的,而不是显示窗口后面的内容。

希望这能为以后的人省去一些麻烦,或者如果没有的话,哦,好吧。

require 'wx'
require 'dl/import'
require 'dl/struct'
include Wx
class Warning < Wx::Frame
  include Wx
    @@x = 0
    @@y = 0
  def setXY(x = 0, y = 0)
    @@x = x
    @@y = y
  end
  def initialize(parent, bmp)
    super(nil, -1, '', pos = [@@x,@@y], size = DEFAULT_SIZE, style = FRAME_SHAPED|SIMPLE_BORDER|FRAME_NO_TASKBAR|STAY_ON_TOP)
    @has_shape = false
    @delta = [0,0]
    @bmp = bmp
    evt_paint {on_paint}
    self.set_client_size(@bmp.width, @bmp.height)
    if PLATFORM == 'WXGTK'
      # wxGTK requires that the window be created before you can
      # set its shape, so delay the call to SetWindowShape until
      # this event.
      evt_window_create { set_window_shape }
    else
      # On wxMSW and wxMac the window has already been created, so go for it.
      set_window_shape
    end
    self.paint { | dc | dc.draw_bitmap(@bmp, 0, 0, true) }
  end
  def set_window_shape
    r = Region.new(@bmp)
    @has_shape = self.set_shape(r)
  end
  def on_paint
    self.paint { | dc | dc.draw_bitmap(@bmp, 0, 0, true) }
  end
end # of Warning
class WarnTest < Wx::App
  def on_init
    @frame = Frame.new()
    warnings = []
    resolution = getScreenResolution()
    shape = File.join( 'image you want' )
    @bmp = Bitmap.new( Image.new(shape) )
    imageWidth = @bmp.get_width
    imageHeight = @bmp.get_height
    imagesAcross = resolution[0] / imageWidth
    imagesDown = resolution[1] / imageHeight
    j = 0
    (1..imagesDown).each do |y|
      i = 0
      (1..imagesAcross).each do |x|
        warnings << [(imageWidth * i), (imageHeight * j)]
        i = i + 1
      end
      j = j + 1
    end
    warnings << [resolution[0], resolution[1]]
    # Create a new window for each xy in warnings array
    warnings.each do |x|
      win = Warning.new(self, @bmp)
      win.setXY(x[0], x[1])
      win.show(true)
      win.update
      sleep 0.01
    end
  end # of on_init
  def getScreenResolution
    sM_CXSCREEN =   0
    sM_CYSCREEN =   1
    user32 = DL.dlopen("user32")
    get_system_metrics = user32['GetSystemMetrics', 'ILI']
    x, tmp = get_system_metrics.call(sM_CXSCREEN,0)
    y, tmp = get_system_metrics.call(sM_CYSCREEN,0)
    res = [x, y]
    return res
  end # of getScreenResolution
end # of WarnTest
app = WarnTest.new
app.main_loop

相关内容

  • 没有找到相关文章

最新更新