 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 541 Location: Galil, Israel
|
Posted: Mon Nov 26, 2007 12:56 am Post subject: |
|
|
not will shatter earth, but anyhow, if helpsful | Code: |
; also makes graphic PUSH STATE button
; adds param for SECOND image (imgPath2), and function to toggle between original and secondary image (of same type) GraphicButton_Swap(VariableName)
; global var %VariableName%_imgSTATE CONTAINS button state
GraphicButton(VariableName, ImgPath, Options="", bHeight=32, bWidth=32, ImgPath2 = "" )
{
Global
Local ImgType, ImgType1
; *******************************************************************
; based on Version: 2.0 Updated: March 28, 2007 by corrupt
; tiny mod by J2DW v.07235
; *******************************************************************
; VariableName = variable name for the button
; ImgPath = Path to the image to be displayed
; Options = AutoHotkey button options (g label, button size, etc...)
; bHeight = Image height (default = 32)
; bWidth = Image width (default = 32)
; *******************************************************************
; BS_BITMAP := 128, IMAGE_BITMAP := 0, BS_ICON := 64, IMAGE_ICON := 1
static BM_SETIMAGE := 247
static LR_LOADFROMFILE := 16
static NULL:= ""
SplitPath, ImgPath,,, ImgType1
ImgTYpe := (ImgType1 = "bmp") ? 128 : 64
Gui, Add, Button, v%VariableName% hwnd%VariableName%_hwnd +%ImgTYpe% %Options%
%VariableName%_imgType := ImgType := (ImgType1 = "bmp") ? 0 : 1
%VariableName%_img := DllCall("LoadImage", "UInt", NULL, "Str", ImgPath, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt", LR_LOADFROMFILE, "UInt")
if ImgPath2
%VariableName%_img2 := DllCall("LoadImage", "UInt", NULL, "Str", ImgPath2, "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
}
GraphicButton_Swap(VariableName) {
global
local state
static BM_SETIMAGE := 247
;tooltip here
if !%VariableName%_img2
return
;tooltip and here
%VariableName%_imgSTATE := state := %VariableName%_imgSTATE ? "" : 2
DllCall("SendMessage", "UInt", %VariableName%_hwnd, "UInt", BM_SETIMAGE, "UInt", %VariableName%_imgType, "UInt", %VariableName%_img%state%)
}
|
_________________ Joyce Jamce
Last edited by Joy2DWorld on Sun Dec 09, 2007 6:46 am; edited 1 time in total |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 766
|
Posted: Sun Dec 02, 2007 7:05 pm Post subject: |
|
|
On Windows XP on my laptop, when I use this function to overlay images over my buttons (creating them both as the same size) the edges around the buttons are all visible, so it just looks like a regular button with my image on it rather than text.
On my main PC with Windows Vista is looks like it should, completely replacing the button with my image so that the button edges are not visible.
Any ideas what could cause this behavior on XP?
If needed for clarification I can make some screenshots of both versions.
Thanks, and nice function! _________________ Ben
My Trac projects
My Wiki
[Broken] - My music |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2446
|
Posted: Sun Dec 09, 2007 5:46 am Post subject: |
|
|
screenshots and a sample to play with might be useful  |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4472 Location: Qld, Australia
|
Posted: Tue Dec 11, 2007 7:28 am Post subject: |
|
|
I'd like to point out that it is possible to have a bitmap and text at the same: simply omit the button style (BS_ICON or BS_BITMAP).
| bmcclure wrote: | | On Windows XP on my laptop, when I use this function to overlay images over my buttons (creating them both as the same size) the edges around the buttons are all visible, so it just looks like a regular button with my image on it rather than text. | If you want only the image to be displayed, why not use a Picture control (with a g label for when you click it, of course)? |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 766
|
Posted: Tue Dec 11, 2007 7:36 am Post subject: |
|
|
Maybe that is the best way for me to go. But I have spent some time setting up nice rollover effects on the buttons (which I suppose could be converted to picture controls with a little work), and the screenshots on the first post don't show the button behind the image at all. I still don't understand why I get different results with my buttons, even though they work fine in Vista. _________________ Ben
My Trac projects
My Wiki
[Broken] - My music |
|
| Back to top |
|
 |
jetpilot86
Joined: 23 May 2007 Posts: 17
|
Posted: Thu Jan 31, 2008 3:19 pm Post subject: |
|
|
Any way to change the color of buttons and the text within them without making a picture file?
TIA
Jet |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 766
|
Posted: Sat Feb 09, 2008 6:51 am Post subject: |
|
|
jetpilot86,
You can easily change the text of a button with GuiControl, but I believe a button's color is set by the operating system. So I think you'd need to make a button graphic in that case, or change the system colors.
Or perhaps check MSDN for a possible API call you can make to set it, but I don't know if that's valid or not. _________________ Ben
My Trac projects
My Wiki
[Broken] - My music |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4472 Location: Qld, Australia
|
Posted: Sat Feb 09, 2008 8:26 am Post subject: |
|
|
I think that would require owner-drawn buttons.
| Windows SDK: Buttons Overview wrote: | Unlike radio buttons, an owner-drawn button is painted by the application, not by the system, and has no predefined appearance or usage. Its purpose is to provide a button whose appearance and behavior are defined by the application alone. There is only one owner-drawn button style: BS_OWNERDRAW.
| Unfortunately, all of the links I find on MSDN like "owner-drawn buttons", "Using Owner Drawn Buttons", etc. link to Using Buttons, which has nothing about owner-drawn buttons. The "Using Buttons" page in the Windows SDK documentation is completely different:
| Windows SDK: Using Buttons wrote: | Using Owner-Drawn Buttons
The parent window of an owner-drawn button typically responds to at least three messages for the button:
- WM_INITDIALOG
- WM_COMMAND
- WM_DRAWITEM
When you must paint an owner-drawn button, the system sends the parent window a WM_DRAWITEM message whose lParam parameter is a pointer to a DRAWITEMSTRUCT structure. Use this structure with all owner-drawn controls to provide the application with the information it requires to paint the control. The itemAction and itemState members of the DRAWITEMSTRUCT structure define how to paint an owner-drawn button.
The following example shows how to process WM_INITDIALOG, WM_DRAWITEM, and WM_COMMAND messages for owner-drawn buttons. This example demonstrates how to draw one of two bitmaps for a control, depending on whether the control is selected. You would typically use the wParam parameter of the WM_DRAWITEM message to identify the control; in this example, only one control is assumed.
| Code: | BOOL CALLBACK OwnDrawProc(HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam)
{
HDC hdcMem;
LPDRAWITEMSTRUCT lpdis;
switch (message)
{
case WM_INITDIALOG:
// hinst, hbm1 and hbm2 are defined globally.
hbm1 = LoadBitmap((HANDLE) hinst, "OwnBit1");
hbm2 = LoadBitmap((HANDLE) hinst, "OwnBit2");
return TRUE;
case WM_DRAWITEM:
lpdis = (LPDRAWITEMSTRUCT) lParam;
hdcMem = CreateCompatibleDC(lpdis->hDC);
if (lpdis->itemState & ODS_SELECTED) // if selected
SelectObject(hdcMem, hbm2);
else
SelectObject(hdcMem, hbm1);
// Destination
StretchBlt(
lpdis->hDC, // destination DC
lpdis->rcItem.left, // x upper left
lpdis->rcItem.top, // y upper left
// The next two lines specify the width and
// height.
lpdis->rcItem.right - lpdis->rcItem.left,
lpdis->rcItem.bottom - lpdis->rcItem.top,
hdcMem, // source device context
0, 0, // x and y upper left
32, // source bitmap width
32, // source bitmap height
SRCCOPY); // raster operation
DeleteDC(hdcMem);
return TRUE;
case WM_COMMAND:
if (wParam == IDOK
|| wParam == IDCANCEL)
{
EndDialog(hDlg, TRUE);
return TRUE;
}
if (HIWORD(wParam) == BN_CLICKED)
{
switch (LOWORD(wParam))
{
case IDC_OWNERDRAW:
// application-defined processing
break;
}
}
break;
case WM_DESTROY:
DeleteObject(hbm1); // delete bitmaps
DeleteObject(hbm2);
break;
}
return FALSE;
UNREFERENCED_PARAMETER(lParam);
}
|
|
All in all, it's probably easier to use graphic buttons. |
|
| Back to top |
|
 |
jetpilot86
Joined: 23 May 2007 Posts: 17
|
Posted: Sat Feb 09, 2008 7:13 pm Post subject: Ok thanks!!!! |
|
|
| oh well, thanks |
|
| Back to top |
|
 |
skwire
Joined: 18 Jan 2006 Posts: 267 Location: Conway, Arkansas
|
Posted: Sat Jun 21, 2008 10:24 pm Post subject: |
|
|
| Corrupt, I use your function extensively in my apps but would it be possible for you to add loading of images via DLLs? Many thanks. |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2446
|
Posted: Sun Jun 22, 2008 4:52 am Post subject: |
|
|
| skwire wrote: | | Corrupt, I use your function extensively in my apps but would it be possible for you to add loading of images via DLLs? Many thanks. | Could you please try to clarify a bit? |
|
| Back to top |
|
 |
skwire
Joined: 18 Jan 2006 Posts: 267 Location: Conway, Arkansas
|
Posted: Sun Jun 22, 2008 6:49 am Post subject: |
|
|
| corrupt wrote: | | Could you please try to clarify a bit? |
http://www.autohotkey.com/docs/commands/ListView.htm#IL
You can build an ImageList from resources (icons, usually) found within DLLs. I would like to be able to load an icon for a button in the same manner. This would enable one to create graphic buttons using icons within, say, shell32.dll, for instance. Or, like me, I create my own "resource.dll" for listview icons in my own apps. Does that clarify things? |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2446
|
Posted: Sun Jun 22, 2008 11:39 am Post subject: |
|
|
ahh.... so you'd like to try the unreleased version...
It's probably still a bit of a mess but here's an example that will likely do what you're asking (and maybe a bit more). Please provide feedback if you give it a try .
Example script: | Code: | ; ********************************
; Demo Script
; ********************************
; Download sample images if necessary
IfNotExist %A_WorkingDir%\bmps.dll
{
SplashTextOn, 300, 30, !, Downloading images. Please wait...
URLDownloadToFile http://www.autohotkey.net/~corr/bmps.dll, bmps.dll
SplashTextOff
}
; Preload images for rollover
AGB_LoadImagedll(sb1, A_WorkingDir . "\bmps.dll", "testimage", 30, 140)
AGB_LoadImagedll(sb1_ro, A_WorkingDir . "\bmps.dll", 601, 80, 140)
AGB_LoadImagedll(sb2, A_WorkingDir . "\bmps.dll", 602, 30, 140)
; AGB_LoadImagedll(sb3, A_WorkingDir . "\bmps.dll", 602, 20, 130)
; Load an icon instead for SampleButton3
AGB_LoadIconDll(sb3, A_WorkingDir . "\bmps.dll", 0)
; Create the buttons
Gui, Add, Button, h30 w140 gNbutton, Normal Button
AddGraphicButton("SampleButton1", sb1, "h30 w140 gMyButton")
AddGraphicButton("SampleButton2", sb2, "h30 w140 gMyButton")
Gui, Add, Button, h30 w140 gNbutton, Another Normal Button
AddGraphicButton("SampleButton3", sb3, "h30 w140 gMyButton")
; Show the window
Gui, Show,, Bitmap Buttons
; Image rollover for SampleButton1
OnMessage(0x200, "MouseMove")
OnMessage(0x2A3, "MouseLeave")
OnMessage(0x202, "MouseLeave") ; Restore image on LBUTTONUP
Return
MouseLeave(wParam, lParam, msg, hwnd)
{
Global
If (hwnd = SampleButton1_hwnd)
AddGraphicButton("SampleButton1", sb1, "h30 w140 gMyButton", 30, 140)
Return
}
MouseMove(wParam, lParam, msg, hwnd)
{
Global
Static _LastButtonData = true
If (hwnd = SampleButton1_hwnd)
If (_LastButtonData != SampleButton1_hwnd)
AddGraphicButton("SampleButton1", sb1_ro, "h30 w140 gMyButton", 60, 120)
_LastButtonData := hwnd
Return
}
MyButton:
MsgBox, Graphic button clicked :)
return
Nbutton:
MsgBox, Normal button Clicked :)
Return
GuiClose:
ExitApp |
Add the following to the script above or save them to your stdlib directory
| Code: | ; *******************************************************************
; AddGraphicButton.ahk
; *******************************************************************
; Version: 2.2 Updated: May 20, 2007
; by corrupt
; *******************************************************************
; VariableName = variable name for the button
; ImgPath = Path to the image to be displayed
; Options = AutoHotkey button options (g label, button size, etc...)
; bHeight = Image height (default = 32)
; bWidth = Image width (default = 32)
; *******************************************************************
; note:
; - calling the function again with the same variable name will
; modify the image on the button
; *******************************************************************
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
}
|
| Code: | ; *******************************************************************
;
; AGB.ahk
; updated: June 22, 2008
; by corrupt
;
; *******************************************************************
;
; *******************************************************************
; Preload images for use with the AddGraphicButton() function
; Version: 2.2 Updated: May 20, 2007
; by corrupt
; *******************************************************************
; VariableName = variable name for the loaded image resource
; ImgPath = Path to the image to be displayed
; bHeight = Image height (default = 32)
; bWidth = Image width (default = 32)
; *******************************************************************
; - this function can optionally be used to pre-load
; images to avoid loading them from file each time (useful for
; creating image rollovers). Specify the variable used in the
; function as ImgPath instead (note: an existing
; image object will not get deleted when a path is not specified. Use
; DllCall("DeleteObject", VariableName_img) manually first before
; using a pre-loaded image if an image path was used previously to
; free memory used by loading the image from file previously.
; *******************************************************************
AGB_LoadImage(ByRef VariableName, ImgPath, bHeight=32, bWidth=32) {
Global
Local ImgType, ImgType1, LR_LOADFROMFILE, NULL
Static LR_LOADFROMFILE := 16
Static NULL
SplitPath, ImgPath,,, ImgType1
ImgType := (ImgType1 = "bmp") ? 0 : 1
If (VariableName != "")
DllCall("DeleteObject", "UInt", VariableName)
VariableName := ImgType . "." . DllCall("LoadImage", "UInt", NULL, "Str", ImgPath, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt", LR_LOADFROMFILE,
"UInt")
Return ErrorLevel
}
; *******************************************************************
; Preload bitmaps from a dll for use with the AddGraphicButton() function
; Version: 2.2 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)
; resID = the name or ID of the bitmap (or icon? - not currently tested)
; bHeight = Image height (default = 32)
; bWidth = Image width (default = 32)
; ImgType1 = "bmp" for bitmaps, "ico" for icons
; *******************************************************************
; - this function can optionally be used to pre-load
; images to avoid loading them from file each time (useful for
; creating image rollovers). Specify the variable used in the
; function as ImgPath instead (note: an existing
; image object will not get deleted when a path is not specified. Use
; DllCall("DeleteObject", VariableName_img) manually first before
; using a pre-loaded image if an image path was used previously to
; free memory used by loading the image from file previously.
; *******************************************************************
AGB_LoadImageDll(ByRef VariableName, dllfile, resID, bHeight=32, bWidth=32, ImgType1="bmp") {
Global
Local ImgType,LR_SHARED, NULL, bmps, IDtype
Static LR_SHARED := 32768
Static NULL
If resID is integer
IDtype = 1
bmps := DllCall("LoadLibrary", "Str", dllfile)
ImgType := (ImgType1 = "bmp") ? 0 : 1 ; future use?
If (VariableName != "")
DllCall("DeleteObject", "UInt", VariableName)
VariableName := ImgType . "." . DllCall("LoadImage", "UInt", bmps, (IDtype ? "UInt" : "Str"), resID, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt",
LR_SHARED, "UInt")
DllCall("FreeLibrary", "Uint", bmps)
Return ErrorLevel
}
; *******************************************************************
; Preload icons from a dll for use with the AddGraphicButton() function
; Version: 2.2 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
; *******************************************************************
; - this function can optionally be used to pre-load
; images to avoid loading them from file each time (useful for
; creating image rollovers). Specify the variable used in the
; function as ImgPath instead (note: an existing
; image object will not get deleted when a path is not specified. Use
; DllCall("DeleteObject", VariableName_img) manually first before
; using a pre-loaded image if an image path was used previously to
; free memory used by loading the image from file previously.
; *******************************************************************
AGB_LoadIconDll(ByRef VariableName, dllfile, nindex) {
Global
Local spid
spid := DllCall("GetCurrentProcessId")
If (VariableName != "")
DllCall("DeleteObject", "UInt", VariableName)
VariableName := "1." . DllCall("shell32.dll\ExtractIconA", "UInt", spid, "Str", dllfile, "UInt", nindex)
Return ErrorLevel
}
|
|
|
| Back to top |
|
 |
skwire
Joined: 18 Jan 2006 Posts: 267 Location: Conway, Arkansas
|
Posted: Sun Jun 22, 2008 6:29 pm Post subject: |
|
|
| corrupt wrote: | ahh.... so you'd like to try the unreleased version...
It's probably still a bit of a mess but here's an example that will likely do what you're asking (and maybe a bit more). Please provide feedback if you give it a try . |
Nice, thank you. I did notice two things:
1) The chosen icon doesn't appear to be sized properly e.g. 16x16 icons get resized to 32x32 on the button. I did not test other sizes.
2) The icon index is off by one. I fixed this by:
| Code: | AGB_LoadIconDll(ByRef VariableName, dllfile, nindex) {
Global
Local spid
spid := DllCall("GetCurrentProcessId")
If (VariableName != "")
DllCall("DeleteObject", "UInt", VariableName)
VariableName := "1." . DllCall("shell32.dll\ExtractIconA", "UInt", spid, "Str", dllfile, "UInt", nindex-1)
Return ErrorLevel
} |
|
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2446
|
Posted: Mon Jun 23, 2008 4:56 am Post subject: |
|
|
Thanks for the feedback . The Icon index is zero based AFAIK so that would explain why it would be off by 1. I'll look into selecting a different size for icons. I made a few updates that may or may not have made it any better and started experimenting with having a function inside the dll file for extracting the images. Although it adds size to the dll file (13.5k before adding images) it might be a cleaner method... ? I also added the ability to use BMP, GIF, JPG, WMF & EMF files with this method (WMF & EMF files not currently tested) A copy of the dll file can be downloaded <here>. Images can then be added to the dll file using Resource Hacker. I'll likely provide the source to the dll once I clean it up a bit - there's not much to it so far.
Here is an updated version of the AGB.ahk file and another demo script for fun. The demo script uses .bmp, .ico, .gif and jpg images from the dll.
| Code: | ; ********************************
; Demo Script - 3.3
; ********************************
; Download sample images if necessary
IfNotExist %A_WorkingDir%\bmps.dll
{
SplashTextOn, 300, 30, !, Downloading images. Please wait...
URLDownloadToFile http://www.autohotkey.net/~corr/bmps3.dll, bmps3.dll
SplashTextOff
}
; Preload images for rollover
AGB_LoadBmpDll(sb1, A_WorkingDir . "\bmps3.dll", 601, 30, 140)
AGB_LoadBmpDll(sb1_ro, A_WorkingDir . "\bmps3.dll", 602, 80, 140)
; Load an icon instead for SampleButton2
AGB_LoadIconDll(sb2, A_WorkingDir . "\bmps3.dll", 0)
AGB_LoadImgDll(sb3, A_WorkingDir . "\bmps3.dll", 603, 30, 150)
AGB_LoadImgDll(sb4, A_WorkingDir . "\bmps3.dll", 604, 30, 150)
AGB_LoadImgDll(sb5, A_WorkingDir . "\bmps3.dll", 605)
; Create the buttons
Gui, Add, Button, h30 w140 gNbutton, Normal Button
AddGraphicButton("SampleButton1", sb1, "h30 w140 gMyButton")
AddGraphicButton("SampleButton2", sb2, "h30 w140 gMyButton")
Gui, Add, Button, h30 w140 gNbutton, Another Normal Button
AddGraphicButton("SampleButton3", sb3, "h30 w140 gMyButton")
AddGraphicButton("SampleButton4", sb4, "h30 w140 gMyButton")
AddGraphicButton("SampleButton5", sb5, "h30 w140 gMyButton")
; Show the window
Gui, Show,, Bitmap Buttons
; Image rollover for SampleButton1
OnMessage(0x200, "MouseMove")
OnMessage(0x2A3, "MouseLeave")
OnMessage(0x202, "MouseLeave") ; Restore image on LBUTTONUP
Return
MouseLeave(wParam, lParam, msg, hwnd)
{
Global
If (hwnd = SampleButton1_hwnd)
AddGraphicButton("SampleButton1", sb1, "h30 w140 gMyButton", 30, 140)
Return
}
MouseMove(wParam, lParam, msg, hwnd)
{
Global
Static _LastButtonData = true
If (hwnd = SampleButton1_hwnd)
If (_LastButtonData != SampleButton1_hwnd)
AddGraphicButton("SampleButton1", sb1_ro, "h30 w140 gMyButton", 60, 120)
_LastButtonData := hwnd
Return
}
MyButton:
MsgBox, Graphic button clicked :)
return
Nbutton:
MsgBox, Normal button Clicked :)
Return
GuiClose:
ExitApp
| As before, either add these to the code above or save in your stdlib directory  | Code: | ; *******************************************************************
; AddGraphicButton.ahk
; *******************************************************************
; Version: 2.2 Updated: May 20, 2007
; by corrupt
; *******************************************************************
; VariableName = variable name for the button
; ImgPath = Path to the image to be displayed
; Options = AutoHotkey button options (g label, button size, etc...)
; bHeight = Image height (default = 32)
; bWidth = Image width (default = 32)
; *******************************************************************
; note:
; - calling the function again with the same variable name will
; modify the image on the button
; *******************************************************************
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
}
|
| Code: | ; *******************************************************************
; AGB.ahk
; updated: June 22, 2008
; by corrupt
; *******************************************************************
; - these functions can optionally be used to pre-load
; images to avoid loading them from file each time (useful for
; creating image rollovers). Specify the variable used in the
; function as ImgPath instead (note: an existing image object will
; not get deleted when a path is not specified. Use
; DllCall("DeleteObject", VariableName_img) manually first before
; using a pre-loaded image if an image path was used previously to
; free memory used by loading the image (or use the AGB_DelImage()
; function.
; *******************************************************************
;
; *******************************************************************
; Preload images for use with the AddGraphicButton() function
; Version: 2.21 Updated: June 22, 2008
; by corrupt
; *******************************************************************
; VariableName = variable name for the loaded image resource
; ImgPath = Path to the image to be displayed
; bHeight = Image height (default = 32)
; bWidth = Image width (default = 32)
; *******************************************************************
AGB_LoadImage(ByRef VariableName, ImgPath, bHeight=32, bWidth=32) {
Global
Local ImgType, ImgType1, LR_LOADFROMFILE, NULL
Static LR_LOADFROMFILE := 16
Static NULL
SplitPath, ImgPath,,, ImgType1
ImgType := (ImgType1 = "bmp") ? 0 : 1
If (%VariableName%_img != "")
DllCall("DeleteObject", "UInt", %VariableName%_img)
VariableName := ImgType . "." . DllCall("LoadImage", "UInt", NULL, "Str", ImgPath, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt", LR_LOADFROMFILE,
"UInt")
Return ErrorLevel
}
; *******************************************************************
; Preload bitmaps 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)
; resID = the name or ID of the bitmap (or icon? - not currently tested)
; bHeight = Image height (default = 32)
; bWidth = Image width (default = 32)
; ImgType1 = "bmp" for bitmaps, "ico" for icons
; *******************************************************************
AGB_LoadBmpDll(ByRef VariableName, dllfile, resID, bHeight=32, bWidth=32, ImgType1="bmp") {
Global
Local ImgType,LR_SHARED, NULL, bmps, IDtype
Static LR_SHARED := 32768
Static NULL
If resID is integer
IDtype = 1
bmps := DllCall("LoadLibrary", "Str", dllfile)
ImgType := (ImgType1 = "bmp") ? 0 : 1 ; future use?
If (%VariableName%_img != "")
DllCall("DeleteObject", "UInt", %VariableName%_img)
VariableName := ImgType . "." . DllCall("LoadImage", "UInt", bmps, (IDtype ? "UInt" : "Str"), resID, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt",
LR_SHARED, "UInt")
DllCall("FreeLibrary", "Uint", bmps)
Return ErrorLevel
}
; *******************************************************************
; 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
}
; *******************************************************************
; Preload icons from a dll for use with the AddGraphicButton() function
; uses a function in the dll to extract the images
; likely supports: BMP, GIF, JPG, WMF, EMF (does not seem to support
; .ICO at the moment for some reason)
; note: add the images using resource type: RCDATA
; 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)
; resID = the ID# of the
; nHeight = Image height (default = 32)
; nWidth = Image width (default = 32)
; *******************************************************************
AGB_LoadImgDll(ByRef VariableName, dllfile, resID, nheight=0, nwidth=0) {
Global
Local hModule
If (%VariableName%_img != "")
DllCall("DeleteObject", "UInt", %VariableName%_img)
hModule := DllCall("LoadLibrary", "Str", dllfile)
variablename := "0." . DllCall(dllfile . "\LoadDllImage", "UInt", resID, "UInt", nwidth, "UInt", nheight, "UInt")
DllCall("FreeLibrary", "UInt", hModule)
Return ErrorLevel
}
; *******************************************************************
; Destroy loaded images
; Version: 2.21 Updated: June 22, 2008
; by corrupt
; *******************************************************************
; VariableName = variable name for the loaded image resource
; *******************************************************************
AGB_DelImage(ByRef VariableName) {
Global
Local ImgPath0, ImgPath1, ImgPath2
If (%VariableName%_img != "")
DllCall("DeleteObject", "UInt", %VariableName%_img)
Else
{
StringSplit, ImgPath, ImgPath,`.
%VariableName%_img := ImgPath2
DllCall("DeleteObject", "UInt", %VariableName%_img)
}
variablename=
Return ErrorLevel
}
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|