Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 27, 2021 16:54:48 GMT -5
I want to show my icon in the window titlebar of my programs i.e., I want to replace the LB "torch" in my programs.
There is a function to do so out of the Icon Editor but I already have an icon which the Icon Editor does not load.
Is there another way of replacing the default "torch"? I looked at the OPEN statement but it only allows you to show a caption.
I am sure there must be some command or other that allows it to be replaced. Will I have to use an API and if so, does someone have code for doing it?
Regards
|
|
|
Post by Brandon Parker on Aug 27, 2021 23:47:10 GMT -5
You will have to use the Windows API to accomplish this. Below is an example of how you would do it. You will need to replace the string that states "Full Path to you icon file here" with the full path to your icon file.
NoMainWin
Global hNewIcon
Open "Test" For Window As #Test #Test "TrapClose quit"
hNewIcon = loadIcon(_NULL, "Full Path to you icon file here", _NULL, _NULL, _LR_LOADFROMFILE Or _LR_DEFAULTSIZE) result = SetIcon(Hwnd(#Test), hNewIcon) Wait
'_______________________________________________________________________________________________________________________________________ '_______________________________________________________________________________________________________________________________________
Sub quit handle$ result = destroyIcon(hIcon) Close #handle$ End End Sub
'_______________________________________________________________________________________________________________________________________ '_______________________________________________________________________________________________________________________________________
Function setIcon(hWnd, hIcon) ICON.SMALL = _NULL CallDLL #user32, "SendMessageA" , hWnd As ulong, _ _WM_SETICON As long, _ ICON.SMALL As long, _ hIcon As ulong, _ setIcon As long End Function
'_______________________________________________________________________________________________________________________________________ '_______________________________________________________________________________________________________________________________________
Function loadIcon(hInst, file$, sizeX, sizeY, fuLoad) file$ = file$ + chr$(0) CallDLL #user32, "LoadImageA", hInst As ulong, _ file$ As ptr, _ _IMAGE_ICON As ulong, _ sizeX As long, _ sizeY As long, _ fuLoad As ulong, _ loadIcon As ulong End Function
'_______________________________________________________________________________________________________________________________________ '_______________________________________________________________________________________________________________________________________
Function destroyIcon(hIcon) CallDLL #user32, "DestroyIcon", hIcon As ulong, _ destroyIcon As long End Function
{:0)
Brandon Parker
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 28, 2021 3:06:04 GMT -5
Thanks Brandon! Thought that I would need to use the Windows API. I was hoping there was another way. Thanks for the code! Regards
|
|
|
Post by Walt Decker on Aug 28, 2021 10:04:32 GMT -5
hIcon = loadIcon(_NULL, "Full Path to you icon file here", _NULL, _NULL, _LR_LOADFROMFILE Or _LR_DEFAULTSIZE) result = SendMessage(Hwnd(#Test), _WM_SETICON, ICON.SMALL, hIcon)
Replace the above with this:
OPEN "User32.dll" FOR DLL AS #USER
PRINT #USER, "loadIcon", _NULL AS LONG, "Full Path to you icon file here" AS PTR, _NULL AS LONG, _NULL AS LONG, _LR_LOADFROMFILE Or _LR_DEFAULTSIZE AS ULONG, hIcon AS ULONG
PRINT #USER, "SendMessage", Hwnd(#Test) AS ULONG, _WM_SETICON AS ULONG, ICON.SMALL AS LONG, hIcon AS ULONG, RetVal AS VOID
ps: There is a statement in the help about setting your own icon for a .tkn, but I do not remember exactly where it is located.
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 28, 2021 15:40:43 GMT -5
Thanks Walt. I looked through the entire hHelp and all that I cound find was a reference to it in the Icon Editor instructions but that was how to chage it in an EXE and also only with an icon developed using the editor. I will search again to see if I can find your elusive .tkn set up. I got Brandon's code nicely working in my application but I will also try your take on it.
|
|
|
Post by Walt Decker on Aug 28, 2021 16:55:37 GMT -5
If Mr. Parker's code works, do not bother. I was unaware that his syntax would work in LB.
That is where I found the reference. You should be able to load a 16-color icon into the editor then follow the instructions from there.
|
|
|
Post by metro on Aug 28, 2021 19:30:04 GMT -5
|
|
|
Post by Brandon Parker on Aug 28, 2021 22:48:37 GMT -5
Dennis, Take a look at the example I provided above. I made a few changes to make it a little more direct and to correct a mistake I made in the SendMessageA function call; the hIcon should have been a ulong.
I changed the SendMessage() user function to setIcon() since the actual SendMessageA DLL function call can take several forms with respect to data types. I changed the Global variable hIcon to hNewIcon since hIcon is now local to the setIcon() function. I moved the ICON.SMALL variable to be local to the setIcon() function, but you could remove this altogether if you wanted to and just set that parameter to _NULL in the actual SendMessageA DLL call.
{:0)
Brandon Parker
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 29, 2021 0:30:34 GMT -5
Thanks Brandon. What you sent works but I will tweak it :-)
|
|