找回密码
 加入
搜索
查看: 3666|回复: 3

[图形处理] 【已解决】图片浏览器中如何编写“上一张”按钮的消息响应代码

[复制链接]
发表于 2013-4-26 17:31:33 | 显示全部楼层 |阅读模式
本帖最后由 silvay22 于 2013-4-26 20:31 编辑

本人是参照原帖http://www.autoitx.com/forum.php ... hlight=%CD%BC%C6%AC基础之上修改的图片浏览器程序,但是遇到了问题,本人写的“上一张”按钮代码总是将图片显示顺序打乱,所以请大家帮忙。代码如下:
#include <file.au3>
#include <array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

Global $path=@WindowsDir&"\Web\Wallpaper"
Global $jpg=_FileListToArray($path,"*.jpg")
Global $number =2


 Dim $w_picctrl = 698, $h_picctrl = 528
$Form1 = GUICreate('图片浏览器', 800, 630, -1, -1, -1, 0x00000010)
GUICtrlCreateGraphic(50, 10, $w_picctrl + 2, $h_picctrl + 2)
GUICtrlSetGraphic(-1, 10, 0, 0, $w_picctrl + 2, $h_picctrl + 2)
$pic = GUICtrlCreatePic('', 11, 11, 1, 1)
$Button_forward = GUICtrlCreateButton("上一张", 269, 560, 97, 33)
$Button_next = GUICtrlCreateButton("下一张", 409, 560, 97, 33)

GUICtrlCreateLabel('图片原始像素:', 50, 550, 90, 17)
$ts_size = GUICtrlCreateLabel('', 140, 550, 100, 17)
GUISetState()

While 1
        Sleep(1)
        $SeeImageNmsg = GUIGetMsg()
        Select
                Case $SeeImageNmsg = $Button_next;点击下一张按钮响应的消息
                        If $number > $jpg[0] Then $number = 1
                        show($path & "" & $jpg[$number])
                        $number += 1
                        
                Case $SeeImageNmsg = $Button_forward;点击上一张按钮响应的消息
                        
                        
                Case $SeeImageNmsg = $GUI_EVENT_CLOSE ; Close Window关闭窗体
                        GUIDelete($Form1)
                        _GDIPlus_Shutdown(); 关闭 GDI+ 库
                        Exit
        EndSelect
WEnd




Func Show($jpg_name)
        Local $imgfile = $jpg_name, $hImage, $h_img
        _GDIPlus_Startup()
        $hImage = _GDIPlus_ImageLoadFromFile($imgfile)
        $w_img = _GDIPlus_ImageGetWidth($hImage)
        $h_img = _GDIPlus_ImageGetHeight($hImage)
        If $w_img * $h_img = 0 Then
                _GDIPlus_Shutdown()
                Return MsgBox(48, @error, '非图片格式', '', $Form1)
        EndIf

        GUICtrlSetData($ts_size, $w_img & ' x ' & $h_img);显示图片原始像素
                
        Local $kgb = $h_picctrl / $w_picctrl
        Local $kgb1 = $h_img / $w_img
        Local $x_py = 0, $y_py = 0, $hBMP, $hObject
        If $w_img > $w_picctrl Or $h_img > $h_picctrl Then
                If $kgb1 > $kgb Then
                        $h_img = $h_picctrl
                        $w_img = Round(1 / $kgb1 * $h_img)
                        $x_py = ($w_picctrl - $w_img) / 2
                Else
                        $w_img = $w_picctrl
                        $h_img = Round($kgb1 * $w_img)
                        $y_py = ($h_picctrl - $h_img) / 2
                EndIf
        Else
                $x_py = ($w_picctrl - $w_img) / 2
                $y_py = ($h_picctrl - $h_img) / 2
        EndIf
        $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $hObject = GUICtrlSendMsg($pic, 0x0172, 0, $hBMP)
        _WinAPI_DeleteObject($hObject)
        _GDIPlus_ImageDispose($hImage)
        _WinAPI_DeleteObject($hBMP)
        _GDIPlus_Shutdown()
        GUICtrlSetPos($pic, 51 + $x_py - 1, 11 + $y_py - 1, $w_img, $h_img)
        GUICtrlSetPos($pic, 51 + $x_py, 11 + $y_py)
EndFunc   ;==>Show
有好人能帮我完善Case $SeeImageNmsg = $Button_forward这里的代码么?也就是点击这个按钮回到上一张图片处。我自己写的总是乱图片顺序。先谢谢了
发表于 2013-4-26 20:11:46 | 显示全部楼层
瞎凑得,期待更好的算法~~
#include <file.au3>
#include <array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

;~ Global $path = @WindowsDir & "\Web\Wallpaper"
Global $path = "C:\Documents and Settings\Administrator\My Documents\test"
Global $ts_size
Global $number = 0
Global $jpg = _FileListToArray($path, "*.jpg")

Dim $w_picctrl = 698, $h_picctrl = 528
$Form1 = GUICreate('图片浏览器', 800, 630, -1, -1, -1, 0x00000010)
GUICtrlCreateGraphic(50, 10, $w_picctrl + 2, $h_picctrl + 2)
GUICtrlSetGraphic(-1, 10, 0, 0, $w_picctrl + 2, $h_picctrl + 2)
$pic = GUICtrlCreatePic('', 11, 11, 1, 1)
If IsArray($jpg) Then show($path & "\" & $jpg[1])

$Button_forward = GUICtrlCreateButton("上一张", 269, 560, 97, 33)
$Button_next = GUICtrlCreateButton("下一张", 409, 560, 97, 33)

GUICtrlCreateLabel('图片原始像素:', 50, 550, 90, 17)
$ts_size = GUICtrlCreateLabel('', 140, 550, 100, 17)
GUISetState()

While 1
        Sleep(1)
        $SeeImageNmsg = GUIGetMsg()
        Select
                Case $SeeImageNmsg = $Button_next;点击下一张按钮响应的消息
                        If IsArray($jpg) Then
                                If $number >= $jpg[0] Then $number = 0
                                show($path & "\" & $jpg[$number + 1])
                                $number += 1
                        EndIf
                Case $SeeImageNmsg = $Button_forward;点击上一张按钮响应的消息
                        If IsArray($jpg) Then
                                If $number = 0 Or $number = 1 Then $number = $jpg[0] + 1
                                show($path & "\" & $jpg[$number - 1])
                                $number -= 1
                        EndIf
                Case $SeeImageNmsg = $GUI_EVENT_CLOSE ; Close Window关闭窗体
                        GUIDelete($Form1)
                        _GDIPlus_Shutdown(); 关闭 GDI+ 库
                        Exit
        EndSelect
WEnd




Func Show($jpg_name)
        Local $imgfile = $jpg_name, $hImage, $h_img
        _GDIPlus_Startup()
        $hImage = _GDIPlus_ImageLoadFromFile($imgfile)
        $w_img = _GDIPlus_ImageGetWidth($hImage)
        $h_img = _GDIPlus_ImageGetHeight($hImage)
        If $w_img * $h_img = 0 Then
                _GDIPlus_Shutdown()
                Return MsgBox(48, @error, '非图片格式', '', $Form1)
        EndIf

        GUICtrlSetData($ts_size, $w_img & ' x ' & $h_img);显示图片原始像素

        Local $kgb = $h_picctrl / $w_picctrl
        Local $kgb1 = $h_img / $w_img
        Local $x_py = 0, $y_py = 0, $hBMP, $hObject
        If $w_img > $w_picctrl Or $h_img > $h_picctrl Then
                If $kgb1 > $kgb Then
                        $h_img = $h_picctrl
                        $w_img = Round(1 / $kgb1 * $h_img)
                        $x_py = ($w_picctrl - $w_img) / 2
                Else
                        $w_img = $w_picctrl
                        $h_img = Round($kgb1 * $w_img)
                        $y_py = ($h_picctrl - $h_img) / 2
                EndIf
        Else
                $x_py = ($w_picctrl - $w_img) / 2
                $y_py = ($h_picctrl - $h_img) / 2
        EndIf
        $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $hObject = GUICtrlSendMsg($pic, 0x0172, 0, $hBMP)
        _WinAPI_DeleteObject($hObject)
        _GDIPlus_ImageDispose($hImage)
        _WinAPI_DeleteObject($hBMP)
        _GDIPlus_Shutdown()
        GUICtrlSetPos($pic, 51 + $x_py - 1, 11 + $y_py - 1, $w_img, $h_img)
        GUICtrlSetPos($pic, 51 + $x_py, 11 + $y_py)
EndFunc   ;==>Show

评分

参与人数 1金钱 +10 收起 理由
silvay22 + 10 很棒的见解

查看全部评分

 楼主| 发表于 2013-4-26 20:30:50 | 显示全部楼层
谢谢haijie1223的热心肠。希望天天开心!代码我测试了很棒哈哈。很开心
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-1 07:00 , Processed in 0.120973 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表