AutoHotkey Community

It is currently May 27th, 2012, 12:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 111 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8
Author Message
 Post subject:
PostPosted: July 16th, 2010, 7:56 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
badmojo wrote:
[Thanks for the code, it works well.. however for multiple buttons, can you help me to understand a bit? this is the code i'm referring to.

Code:
...
  If (hwnd = SampleButton1_hwnd)
    If (_LastButtonData1 != SampleButton1_hwnd)
      ToolTip, Timed ToolTip`nThis will be displayed for 5 seconds.
      SetTimer, RemoveToolTip, 5000
  _LastButtonData1 := hwnd

  If (hwnd = SampleButton2_hwnd)
    If (_LastButtonData1 != SampleButton1_hwnd)
      ToolTip, Timed ToolTip`nThis will be displayed for 5 seconds.
      SetTimer, RemoveToolTip, 5000
  _LastButtonData1 := hwnd


...


even for SampleButton2, why is the _LastButtonData1 is still SampleButton1_hwnd.

thanks again..
Thanks for testing :) . After the line with the If statement where you have If (hwnd = SampleButton2_hwnd) the next line should probably be If (_LastButtonData1 != SampleButton2_hwnd). The line _LastButtonData1 := hwnd
should be added at the end of the section otherwise _LastButtonData1 will equal SampleButton2_hwnd when your mouse is over SampleButton2 since the value of hwnd was assigned to _LastButtonData1 above. Here is one method using multiple buttons :) :
Code:
; ********************************
; Demo Script
; ********************************

; Load an icon instead for SampleButton2
AGB_LoadIconDll(sb1, "shell32.dll", 166)
AGB_LoadIconDll(sb2, "shell32.dll", 167)
AGB_LoadIconDll(sb3, "shell32.dll", 168)
AGB_LoadIconDll(sb4, "shell32.dll", 169)

; Create the buttons
AddGraphicButton("SampleButton1", sb1, "h36 w36 gMyButton")
AddGraphicButton("SampleButton2", sb2, "h36 w36 gMyButton")
AddGraphicButton("SampleButton3", sb3, "h36 w36 gMyButton")
AddGraphicButton("SampleButton4", sb4, "h36 w36 gMyButton")

; Show the window
Gui, Show, , Graphic Buttons

; events
 OnMessage(0x200, "MouseMove")
 OnMessage(0x2A3, "MouseLeave")

Return

MouseLeave(wParam, lParam, msg, hwnd)
{
  Global
  If (hwnd = SampleButton1_hwnd)
    ToolTip
  If (hwnd = SampleButton2_hwnd)
    ToolTip
  If (hwnd = SampleButton3_hwnd)
    ToolTip
  If (hwnd = SampleButton4_hwnd)
    ToolTip
  Return
}
MouseMove(wParam, lParam, msg, hwnd)
{
  Global
  Static _LastButtonData1 = true

   If (hwnd = SampleButton1_hwnd)
    If (_LastButtonData1 != SampleButton1_hwnd)
      ToolTip, Hi`, I'm button1

  If (hwnd = SampleButton2_hwnd)
    If (_LastButtonData1 != SampleButton2_hwnd)
      ToolTip, Hi`, I'm button2

  If (hwnd = SampleButton3_hwnd)
    If (_LastButtonData1 != SampleButton3_hwnd)
      ToolTip, Hi`, I'm button3

  If (hwnd = SampleButton4_hwnd)
    If (_LastButtonData1 != SampleButton4_hwnd)
      ToolTip, Hi`, I'm button4

  SetTimer, RemoveToolTip, 5000
  _LastButtonData1 := hwnd
  Return
}

MyButton:
MsgBox, Graphic button clicked :)
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

GuiClose:
ExitApp


; from the library file AGB.ahk (included in the zip file in the download)

; *******************************************************************
; Preload icons from a dll for use with the AddGraphicButton() function
; Version: 2.21 Updated: June 22, 2008
; by corrupt
; *******************************************************************
; VariableName = variable name for the loaded image resource
; dllfile = Path to the dll file that contains the image(s)
; nindex = the index of the icon to load
; *******************************************************************
AGB_LoadIconDll(ByRef VariableName, dllfile, nindex) {
Global
Local spid
spid := DllCall("GetCurrentProcessId")
If (%VariableName%_img != "")
  DllCall("DeleteObject", "UInt", %VariableName%_img)
VariableName := "1." . DllCall("shell32.dll\ExtractIconA", "UInt", spid, "Str", dllfile, "UInt", nindex)
Return ErrorLevel
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2010, 3:25 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Best place I know for Win9x knowledge would be MSFN. There's a section for Win9x projects here. Thank you for the interest, any help is much appreciated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2011, 3:23 pm 
Offline

Joined: December 28th, 2010, 11:59 am
Posts: 63
Location: France
Hello, thanks a lot for this work, it was exactly what I was looking for. (Will be used in next version of Unichars)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 22nd, 2011, 2:55 pm 
Offline

Joined: October 18th, 2006, 8:07 pm
Posts: 169
Hello!

Firstly, thanks to Corrupt and everyone involved in making this – it's great!

I'm trying to create one of these buttons on a GUI which is sometimes destroyed and recreated. In the case below, the picture button will only appear the first time the GUI is created:

Code:
loop
   {
   AddGraphicButton("SampleButton", A_WorkingDir . "\testbmp.bmp", "h30 w140 gMyButton", 30, 140)
   gui,add,button,x100 y100,hello
   gui,show
   gui +lastfound
   winwaitclose
   msgbox gui destroyed
   }
return

mybutton:
gui,destroy
return

;=====
;Picture / image button: AddGraphicButton.ahk - http://www.autohotkey.com/forum/topic4047.html
;=====
AddGraphicButton(VariableName, ImgPath, Options="", bHeight=32, bWidth=32){
Global
Local ImgType, ImgType1, ImgPath0, ImgPath1, ImgPath2, hwndmode
 ;BS_BITMAP := 128, IMAGE_BITMAP := 0, BS_ICON := 64, IMAGE_ICON := 1
Static LR_LOADFROMFILE := 16
Static BM_SETIMAGE := 247
Static NULL
SplitPath, ImgPath,,, ImgType1
If ImgPath is float
{
  ImgType1 := (SubStr(ImgPath, 1, 1)  = "0") ? "bmp" : "ico"
  StringSplit, ImgPath, ImgPath,`.
  %VariableName%_img := ImgPath2
  hwndmode := true
}
ImgType := (ImgType1 = "bmp") ? 128 : 64
If (%VariableName%_img != "") AND !(hwndmode)
  DllCall("DeleteObject", "UInt", %VariableName%_img)
If (%VariableName%_hwnd = "")
  Gui, Add, Button,  v%VariableName% hwnd%VariableName%_hwnd +%ImgType% %Options%
ImgType := (ImgType1 = "bmp") ? 0 : 1
If !(hwndmode)
  %VariableName%_img := DllCall("LoadImage", "UInt", NULL, "Str", ImgPath, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt", LR_LOADFROMFILE, "UInt")
DllCall("SendMessage", "UInt", %VariableName%_hwnd, "UInt", BM_SETIMAGE, "UInt", ImgType,  "UInt", %VariableName%_img)
Return %VariableName%_img ; Return the handle to the image
}



This can be resolved by either …

OPTION 1:
Removing the following line in AddGraphicButton.ahk:
Quote:
If (%VariableName%_hwnd = "")


Code:
Code:
loop
   {
   AddGraphicButton("SampleButton", A_WorkingDir . "\testbmp.bmp", "h30 w140 gMyButton", 30, 140)
   gui,add,button,x100 y100,hello
   gui,show
   gui +lastfound
   winwaitclose
   msgbox gui destroyed
   }
return

mybutton:
gui,destroy
return

;=====
;Picture / image button: AddGraphicButton.ahk - http://www.autohotkey.com/forum/topic4047.html
;=====
AddGraphicButton(VariableName, ImgPath, Options="", bHeight=32, bWidth=32){
Global
Local ImgType, ImgType1, ImgPath0, ImgPath1, ImgPath2, hwndmode
 ;BS_BITMAP := 128, IMAGE_BITMAP := 0, BS_ICON := 64, IMAGE_ICON := 1
Static LR_LOADFROMFILE := 16
Static BM_SETIMAGE := 247
Static NULL
SplitPath, ImgPath,,, ImgType1
If ImgPath is float
{
  ImgType1 := (SubStr(ImgPath, 1, 1)  = "0") ? "bmp" : "ico"
  StringSplit, ImgPath, ImgPath,`.
  %VariableName%_img := ImgPath2
  hwndmode := true
}
ImgType := (ImgType1 = "bmp") ? 128 : 64
If (%VariableName%_img != "") AND !(hwndmode)
  DllCall("DeleteObject", "UInt", %VariableName%_img)
;If (%VariableName%_hwnd = "")
  Gui, Add, Button,  v%VariableName% hwnd%VariableName%_hwnd +%ImgType% %Options%
ImgType := (ImgType1 = "bmp") ? 0 : 1
If !(hwndmode)
  %VariableName%_img := DllCall("LoadImage", "UInt", NULL, "Str", ImgPath, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt", LR_LOADFROMFILE, "UInt")
DllCall("SendMessage", "UInt", %VariableName%_hwnd, "UInt", BM_SETIMAGE, "UInt", ImgType,  "UInt", %VariableName%_img)
Return %VariableName%_img ; Return the handle to the image
}



OPTION 2:
Setting a new variable name every time:

Code:
i=0
loop
   {
   i+=1
   AddGraphicButton("SampleButton" i, A_WorkingDir . "\testbmp.bmp", "h30 w140 gMyButton", 30, 140)
   gui,add,button,x100 y100,hello
   gui,show
   gui +lastfound
   winwaitclose
   msgbox gui destroyed
   }
return

mybutton:
gui,destroy
return

;=====
;Picture / image button: AddGraphicButton.ahk - http://www.autohotkey.com/forum/topic4047.html
;=====
AddGraphicButton(VariableName, ImgPath, Options="", bHeight=32, bWidth=32){
Global
Local ImgType, ImgType1, ImgPath0, ImgPath1, ImgPath2, hwndmode
 ;BS_BITMAP := 128, IMAGE_BITMAP := 0, BS_ICON := 64, IMAGE_ICON := 1
Static LR_LOADFROMFILE := 16
Static BM_SETIMAGE := 247
Static NULL
SplitPath, ImgPath,,, ImgType1
If ImgPath is float
{
  ImgType1 := (SubStr(ImgPath, 1, 1)  = "0") ? "bmp" : "ico"
  StringSplit, ImgPath, ImgPath,`.
  %VariableName%_img := ImgPath2
  hwndmode := true
}
ImgType := (ImgType1 = "bmp") ? 128 : 64
If (%VariableName%_img != "") AND !(hwndmode)
  DllCall("DeleteObject", "UInt", %VariableName%_img)
If (%VariableName%_hwnd = "")
  Gui, Add, Button,  v%VariableName% hwnd%VariableName%_hwnd +%ImgType% %Options%
ImgType := (ImgType1 = "bmp") ? 0 : 1
If !(hwndmode)
  %VariableName%_img := DllCall("LoadImage", "UInt", NULL, "Str", ImgPath, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt", LR_LOADFROMFILE, "UInt")
DllCall("SendMessage", "UInt", %VariableName%_hwnd, "UInt", BM_SETIMAGE, "UInt", ImgType,  "UInt", %VariableName%_img)
Return %VariableName%_img ; Return the handle to the image
}


Option 1 is more desirable than Option 2, but my question is …

Will removing the line “If (%VariableName%_hwnd = "")” do anything nasty...?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 26th, 2011, 6:57 pm 
Offline

Joined: December 2nd, 2011, 4:41 pm
Posts: 57
really powerful! :D

_________________
http://www.autohotkey.net/~iBob35555VR << help me creating better graphics! :P post suggestions in "Leave a comment". Thanks


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 16th, 2012, 5:04 pm 
Offline

Joined: June 29th, 2010, 1:01 pm
Posts: 123
Ok, I'm having some trouble with controlling the graphic buttons. I was hoping for some help.

I'd like not to use the bmp3.dll, but rather just use the

ABG_LoadImage function.

I want a control panel where the user can click on a button and I change the graphic (as well as run some called function)

I've included some sample graphics. the idea is the user pushed one of the graphics, and the graphic switches from the off graphic, to the the on graphic:

Image

Ideally, I could also control other graphics as well:

Image

in the second example, as well as the graphic of the switches changing, the graphic of the LED indicators reflects the status of the respective switch.

TIA,

Jon


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 111 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, SKAN and 5 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group