Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Thu Oct 01, 2020 12:05 am Post subject: Add Image or Icon to Button |
|
|
As the title says, of course I can use panel or image as a button, but a panel or image don't have 'Down or Up State' to control. Others choice is use toggle box or checkbox to control 'Down or Up State' or 'Check or Uncheck' control, except I made custom function to control the color of the panels via event handlers.
Example:
| Code: | If UDF1.CEToggleBox1.State == 'cbChecked' then
do sometihing
UDF1.CEToggleBox1.Caption = 'Toggle is down'
else
do sometihing
UDF1.CEToggleBox1.Caption = 'Toggle is up'
end |
Anyhow, seems not possible to 'watch' the state change by visual control, i.e by change the color of the toggle box face, except I am using a panel as a toggle box or create a custom button by draw it,
And seems not possible too, to place an image or icon to the toggle box, since the toggle box doesn't have a canvas.
So, is there any trick to place an image or icon to a toggle box or to a button?.
Or, is any chance to create new class such as TBitBtn or TSpeedButton and also NumericUpDown Components without editing the CE pas file and recompile the CE source?.
Alternatively, I can use native win API 'createWindowEx' to add new class component, example:
| Code: | function CreateWindow(oControl, oClass, oName, oHwnd, oDWStyle, nleft, ntop, nwidth, nheight)
return executeCodeLocalEx("user32.CreateWindowExA", 0, oClass, oName, oDWStyle, nleft, ntop, nwidth, nheight, oHwnd, 0, 0, 0)
end
function LoadIcon(hInstance, lpIconName)
return executeCodeLocalEx("user32.LoadIcon", lpIconName)
end
function _SendMessage(hWnd, Msg, wParam, lParam)
return executeCodeLocalEx("user32.SendMessage",hWnd, Msg, wParam, lParam)
end
function LoadImage(hInst, lpszName, uType, cxDesired, cyDesired, fuLoad)
return executeCodeLocalEx("user32.LoadImage", hInst, lpszName, uType, cxDesired, cyDesired, fuLoad)
end
function SetWindowLong(hWnd, nIndex, dwNewLong)
return executeCodeLocalEx("user32.SetWindowLongPtrA", hWnd, nIndex, dwNewLong)
end
function GetWindowLong(prmlngWindowHandle, prmlngIndex)
return executeCodeLocalEx("user32.GetWindowLongA", prmlngWindowHandle, prmlngIndex)
end
function CallWindowProc(lpPrevWndFunc, hWnd, Msg, wParam, lParam)
return executeCodeLocalEx("user32.CallWindowProcA", lpPrevWndFunc, hWnd, Msg, wParam, lParam)
end
--MainForm.Handle
WS_VISIBLE = 0x10000000
WS_BORDER = 0x00800000
WS_CHILD = 0x40000000
BS_TEXT = 0x00000000
BS_BOTTOM = 0x00000800
GWL_WNDPROC = -4
local icc = {}
icc.osize = 0
icc.oicc = 0
local t = icc
t.osize = 8
t.oicc = 2
if f then f.destroy() end
f = createForm()
f.Position = 'poSceenCenter'
f.Show()
|
The script will create buttons on the form, but I am still don't know how to add image on the button created since the script to add an image as above doesn't work.
Also, event success to create button and add an image on the button, then still need another function to handle click events on the button created.
So, I think maybe the best way is to create new class component TBitBtn or TSpeedButton and also NumericUpDown Components without editing the CE pas file and recompile the CE source, but how?.
EDIT:
Something like this (The result image is using winapi createWindowEX)
| Code: | -- Save Button
local openbutton = CreateWindow(t, "BUTTON", "The Button", f.Handle, WS_VISIBLE + WS_BORDER + WS_CHILD | BS_BITMAP, 10, 10, 50, 50)
hImg = LoadImage(0, "d:\\open.bmp", IMAGE_BITMAP, 25, 25, LR_LOADFROMFILE)
_SendMessage(openbutton, BM_SETIMAGE, IMAGE_BITMAP, hImg)
local savebutton = CreateWindow(t, "BUTTON", "The Button", f.Handle, WS_VISIBLE + WS_BORDER + WS_CHILD | BS_BITMAP, 70, 10, 50, 50)
hImg = LoadImage(0, "d:\\save.bmp", IMAGE_BITMAP, 25, 25, LR_LOADFROMFILE)
_SendMessage(savebutton, BM_SETIMAGE, IMAGE_BITMAP, hImg)
local pastebutton = CreateWindow(t, "BUTTON", "The Button", f.Handle, WS_VISIBLE + WS_BORDER + WS_CHILD | BS_BITMAP, 130, 10, 50, 50)
hImg = LoadImage(0, "d:\\paste.bmp", IMAGE_BITMAP, 25, 25, LR_LOADFROMFILE)
_SendMessage(pastebutton, BM_SETIMAGE, IMAGE_BITMAP, hImg) |
EDIT 2:
How to add event handler such as OnClick or OnMouseDown to the created button.
I try using call window procedure, example:
| Code: | function CallWindowProc(hWnd, Msg, wParam, lParam)
return executeCodeLocalEx("user32.CallWindowProcA", lpPrevWndFunc, hWnd, Msg, wParam, lParam)
end
function test()
CallWindowProc(f.Handle, 0, WM_LBUTTONDOWN, hButton1)
showMessage('Button "Open" has been Clicked')
end
test()
|
But the code suddenly work without wait for clicking on the button.
| Description: |
| Button with image using winapi |
|
| Filesize: |
22.89 KB |
| Viewed: |
1431 Time(s) |

|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|