1 (изменено: cahtbap1, 2016-12-12 13:34:53)

Тема: AHK: Мигает картинка gui при ее изменении

Вот кусок скрипта:


gui, gui20:show ,x0 y400 w300 h300 Noactivate
gui,gui20:add,picture,vp2 x0 y0 w300 h300 +BackgroundTrans,фон0.png
Gui, gui20:Color, EEAA99
Gui, gui20:+Lastfound +AlwaysOnTop -Border -Caption +ToolWindow
WinSet, TransColor, EEAA99 200
settimer , circle , 100
return
circle:
gosub get
if f = 0
    GuiControl,gui20:,p2,фон0.png
if f = 10
    GuiControl,gui20:,p2,фон1.png
if f = 12
    GuiControl,gui20:,p2,фон2.png
if f = 2
    GuiControl,gui20:,p2,фон3.png
if f = 22
    GuiControl,gui20:,p2,фон4.png
if f = 20
    GuiControl,gui20:,p2,фон5.png
if f = 21
    GuiControl,gui20:,p2,фон6.png
if f = 1
    GuiControl,gui20:,p2,фон7.png
if f = 11
    GuiControl,gui20:,p2,фон8.png
return

get:
f=0
GetKeyState, joyx, JoyX
GetKeyState, joyy, JoyY
if joyx < 47
    EnvAdd,f,1
if joyx > 53
    EnvAdd,f,2
if joyy < 47
    EnvAdd,f,10
if joyy > 53
    EnvAdd,f,20
return

Изменять картинку изменяет , но  картинка начинает хаотично мигать .
Помогите избавиться от этого мигания.

2

Re: AHK: Мигает картинка gui при ее изменении

cahtbap1, эта часть кода не позволяет ответить на вопрос. Давайте что ли весь скрипт.

3

Re: AHK: Мигает картинка gui при ее изменении

ypppu
Обновил код выше.
Целый код 800+ строк не думаю что он чем то поможет.

4 (изменено: cahtbap1, 2016-12-12 13:37:47)

Re: AHK: Мигает картинка gui при ее изменении

Попробовал так , не помогло ,но мигания стало меньше. Мигает видимо не только при смене картинки саму на себя а и при простой смене.



gui,gui20:add,picture,vp2 x0 y0 w300 h300 +BackgroundTrans,фон0.png
Gui, gui20:Color, EEAA99
Gui, gui20:+Lastfound +AlwaysOnTop -Border -Caption +ToolWindow
WinSet, TransColor, EEAA99 200
settimer , circle , 100
gui, gui20:show ,x0 y400 w300 h300 Noactivate
return
circle:
gosub get
if f=%ff%
	return
if f = 0
    GuiControl,gui20:,p2,фон0.png
if f = 10
    GuiControl,gui20:,p2,фон1.png
if f = 12
    GuiControl,gui20:,p2,фон2.png
if f = 2
    GuiControl,gui20:,p2,фон3.png
if f = 22
    GuiControl,gui20:,p2,фон4.png
if f = 20
    GuiControl,gui20:,p2,фон5.png
if f = 21
    GuiControl,gui20:,p2,фон6.png
if f = 1
    GuiControl,gui20:,p2,фон7.png
if f = 11
    GuiControl,gui20:,p2,фон8.png
return

get:
ff=%f%
f=0
GetKeyState, joyx, JoyX
GetKeyState, joyy, JoyY
if joyx < 47
    EnvAdd,f,1
if joyx > 53
    EnvAdd,f,2
if joyy < 47
    EnvAdd,f,10
if joyy > 53
    EnvAdd,f,20
return

5

Re: AHK: Мигает картинка gui при ее изменении

Вроде всё просто. Вы по 10 раз в секунду проверяете значение переменной f. При выполнении одного из условий фон изменяется. Соответственно картинка может изменяться по 10 раз в секунду. Вы это называете мельканием?

Для лучшего понимания выложите файлы фон0.png ... фон8.png.
P. S.: Можете прикрепить к сообщению архив ZIP без сжатия.

6 (изменено: cahtbap1, 2016-12-12 14:16:47)

Re: AHK: Мигает картинка gui при ее изменении

ypppu пишет:

Для лучшего понимания выложите файлы фон0.png ... фон8.png.

Вот фон и 2 скрина.

Post's attachments

4gui.rar 1.17 mb, 4 downloads since 2016-12-12 

You don't have the permssions to download the attachments of this post.

7

Re: AHK: Мигает картинка gui при ее изменении

ypppu пишет:

Соответственно картинка может изменяться по 10 раз в секунду. Вы это называете мельканием?

Картинка как будто перерисовывается сверху вниз настолько долго , что глаз успевает уловить ее отсутствие или ее часть не в полном размере.

8

Re: AHK: Мигает картинка gui при ее изменении

Сейчас попробовал. Да, мелькает чересчур быстро. Пока проблему не понял, приду попозже - посмотрю.

9

Re: AHK: Мигает картинка gui при ее изменении

Поискал на оф. форуме, попробовал разные варианты. От мельканий избавиться не удаётся.

10

Re: AHK: Мигает картинка gui при ее изменении

Через GDI+ можно.
https://autohotkey.com/board/topic/2944 … 45-by-tic/

11 (изменено: cahtbap1, 2016-12-12 22:07:28)

Re: AHK: Мигает картинка gui при ее изменении

Malcev пишет:

Через GDI+ можно.

Что оно такое и как его использовать?

12

Re: AHK: Мигает картинка gui при ее изменении

Есть какой то гайдик толковый? Я не против научиться чему то новому.
Попробовал скрипты по ссылке , с виду не очень понятно , а английские коментарии только запутывают.
Копировал все что вижу , запускал в разной последовательности и разными комбинациями , ничего не получилось).

13

Re: AHK: Мигает картинка gui при ее изменении

Только тот, что по ссылке:

; Requires Gdip.ahk either in your Lib folder as standard library or using #Include

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
;#Include, Gdip.ahk

; Start gdi+
If !pToken := Gdip_Startup()
{
	MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
	ExitApp
}
OnExit, Exit

; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs

; Show the window
Gui, 1: Show, NA

; Get a handle to this window we have created in order to update it later
hwnd1 := WinExist()

loop
{
   loop 9
   {
      pBitmap := Gdip_CreateBitmapFromFile("фон" A_Index-1 ".png")
      GoSub gdi
      sleep 100
   }
}
return


gdi:
; Check to ensure we actually got a bitmap from the file, in case the file was corrupt or some other error occured
If !pBitmap
{
	MsgBox, 48, File loading error!, Could not load the image specified
	ExitApp
}

; Get the width and height of the bitmap we have just created from the file
; This will be the dimensions that the file is
Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)

; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
; We are creating this "canvas" at half the size of the actual image
; We are halving it because we want the image to show in a gui on the screen at half its dimensions
hbm := CreateDIBSection(Width//2, Height//2)

; Get a device context compatible with the screen
hdc := CreateCompatibleDC()

; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)

; We do not need SmoothingMode as we did in previous examples for drawing an image
; Instead we must set InterpolationMode. This specifies how a file will be resized (the quality of the resize)
; Interpolation mode has been set to HighQualityBicubic = 7
Gdip_SetInterpolationMode(G, 7)

; DrawImage will draw the bitmap we took from the file into the graphics of the bitmap we created
; We are wanting to draw the entire image, but at half its size
; Coordinates are therefore taken from (0,0) of the source bitmap and also into the destination bitmap
; The source height and width are specified, and also the destination width and height (half the original)
; Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh, Matrix)
; d is for destination and s is for source. We will not talk about the matrix yet (this is for changing colours when drawing)
Gdip_DrawImage(G, pBitmap, 0, 0, Width//2, Height//2, 0, 0, Width, Height)

; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier (half of the original image)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width//2, Height//2)


; Select the object back into the hdc
SelectObject(hdc, obm)

; Now the bitmap may be deleted
DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)

; The bitmap we made from the image may be deleted
Gdip_DisposeImage(pBitmap)
Return

;#######################################################################

Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return

14

Re: AHK: Мигает картинка gui при ее изменении

Malcev
Я не знаю как этим пользоваться , этот скрипт у меня не работает . Может это библиотека какая то  и ее устанавливать нужно?Давай лучше по порядку что и как мне делать?

15

Re: AHK: Мигает картинка gui при ее изменении

https://www.dropbox.com/s/0e9gdfetbfa8v0o/Gdip_All.ahk

16

Re: AHK: Мигает картинка gui при ее изменении

Попробовал тот скрипт в теме отдельно сохранить как gdip.ahk и убрать ; перед #Include, Gdip.ahk , с виду прогресс двинулся и скрипт остается включенным , но ничего не показывает.

17

Re: AHK: Мигает картинка gui при ее изменении

Переименовал gdip_all.ahk в gdip.ahk все заработало.Спасибо , буду разбираться :-)

18

Re: AHK: Мигает картинка gui при ее изменении

А куда можно этот gdip.ahk закинуть чтоб все время его по папкам не таскать , и длинные пути не прописывать?

19

Re: AHK: Мигает картинка gui при ее изменении

C:\Program Files\AutoHotkey\lib

20 (изменено: cahtbap1, 2016-12-13 14:55:50)

Re: AHK: Мигает картинка gui при ее изменении

Malcev
Все работает , вот такой код получился.


#SingleInstance, Force
#NoEnv
SetBatchLines, -1
#Include, C:\Program Files\AutoHotkey\lib\Gdip.ahk
If !pToken := Gdip_Startup()
{
	MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
	ExitApp
}
OnExit, Exit
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()
SetTimer,circle,100
return

gdi:
If !pBitmap
{
	MsgBox, 48, File loading error!, Could not load the image specified
	ExitApp
}

Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
hbm := CreateDIBSection(Width//2, Height//2)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetInterpolationMode(G, 7)
Gdip_DrawImage(G, pBitmap, 0, 0, Width//2, Height//2, 0, 0, Width, Height)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width//2, Height//2)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_DisposeImage(pBitmap)
Return

Exit:
Gdip_Shutdown(pToken)
ExitApp
Return

circle:
gosub get
if f=%ff%
	return
if f = 0
    pBitmap := Gdip_CreateBitmapFromFile("фон0.png")
if f = 10
    pBitmap := Gdip_CreateBitmapFromFile("фон1.png")
if f = 12
    pBitmap := Gdip_CreateBitmapFromFile("фон2.png")
if f = 2
    pBitmap := Gdip_CreateBitmapFromFile("фон3.png")
if f = 22
    pBitmap := Gdip_CreateBitmapFromFile("фон4.png")
if f = 20
    pBitmap := Gdip_CreateBitmapFromFile("фон5.png")
if f = 21
    pBitmap := Gdip_CreateBitmapFromFile("фон6.png")
if f = 1
    pBitmap := Gdip_CreateBitmapFromFile("фон7.png")
if f = 11
    pBitmap := Gdip_CreateBitmapFromFile("фон8.png")
goto gdi
return
get:
ff=%f%
f=0
GetKeyState, joyx, JoyX
GetKeyState, joyy, JoyY
if joyx < 47
    EnvAdd,f,1
if joyx > 53
    EnvAdd,f,2
if joyy < 47
    EnvAdd,f,10
if joyy > 53
    EnvAdd,f,20
return

Только вот где я могу прописать координаты картинки?Масштабирование и т.д.
И еще как мне тут задать те 200 полупрозрачности?


WinSet, TransColor, EEAA99 200

21

Re: AHK: Мигает картинка gui при ее изменении

Только вот где я могу прописать координаты картинки?Масштабирование и т.д.

; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier (half of the original image)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width//2, Height//2)

И еще как мне тут задать те 200 полупрозрачности?

Не знаю. Наверное копать матрицу.
Либо сразу создавать полупрозрачные png.

; DrawImage will draw the bitmap we took from the file into the graphics of the bitmap we created
; We are wanting to draw the entire image, but at half its size
; Coordinates are therefore taken from (0,0) of the source bitmap and also into the destination bitmap
; The source height and width are specified, and also the destination width and height (half the original)
; Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh, Matrix)
; d is for destination and s is for source. We will not talk about the matrix yet (this is for changing colours when drawing)
Gdip_DrawImage(G, pBitmap, 0, 0, Width//2, Height//2, 0, 0, Width, Height)

22

Re: AHK: Мигает картинка gui при ее изменении

Malcev
Худо бедно разобрался , а как насчет слоев?
Без gdi+ я сделал несколько окон gui одно на одном .
Во всех них было прописано AlwaysOnTop, и друг на друга они налаживались в порядке их вызова.
Однако теперь фон который я сделал с gdi+ всегда находиться поверх других gui.

23

Re: AHK: Мигает картинка gui при ее изменении

Если в 13 код добавить:

f11::
Gui,2:  +AlwaysOnTop
Gui,2: Add, Text,, Please enter your name:
Gui,2: Add, Button, Default, OK
Gui,2:  Show
return

То при нажатии f11 новый гуи будет поверх старого.