PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Petrus Vorster on May 02, 2019, 08:12:05 AM

Title: Notification Icon
Post by: Petrus Vorster on May 02, 2019, 08:12:05 AM
Hi all

I know there is not much support anymore for Pb and FF.
It's ok, but if you have a thought on this one I will appreciate it.

I had to rebuild a project after a devastating drive crash.
I thought that while i was doing it, i could just as well make a few improvements.

I seldom(never) really used a toolbar control, but then decided to just get one with it and finish what i need to do quickly.
(see the image)
I have a button the person can click to view a form if the tool generates a system notice the user must look at.
(Expiration dates, unpaid accounts etc...)

Those of you that uses tools like Telegram and WhatsApp will know that the Program icon will show a little red circle on top of the button with the number of messages,  if there are any.
I was wondering if one could copy that kind of behavior using the toolbar?

I know at some point you showed me how to find the measurements and location of the toolbar buttons( long forgotten examples) and i thought it could be cool to "float" a small font label perhaps on the right corner if there is any messages.

Anyone still in the mood to try something like that?

-Much Appreciated. -Peter
Title: Re: Notification Icon
Post by: Eros Olmi on May 02, 2019, 09:01:29 AM
Quick and dirty ...
If you just need to add a sign and not the exact number of messages, you can have a normal image and disabled image alternance.
When no messages ... disable the button and disabled image is the standard one
When some messages ... activate the button and normal image will have a kind of sign on the button image (*) for example

Use ToolBar_EnableButton(...)/ToolBar_DisableButton(...) to alternate.

Title: Re: Notification Icon
Post by: Petrus Vorster on May 02, 2019, 02:15:23 PM
Hi Eros

Thanks,  that's a thought I haven't considered....
I would however like to also look into that "floating" number too as it will haunt my thoughts for weeks on end....

But that image thing may just do the trick for now...

Thanks, that's why i ask here!

-Peter
Title: Re: Notification Icon
Post by: Petrus Vorster on May 02, 2019, 02:28:48 PM
Eros, you genius!

Thanks a million. This was so simple and it will work just fine.

-Peter
Title: Re: Notification Icon
Post by: Marc Pons on May 02, 2019, 02:32:57 PM
a work_arround
why not have prepared different images from 1 to  ... what you need and according the number of incomming message you replace the image "message" by the one with the number on it.
Title: Re: Notification Icon
Post by: Eros Olmi on May 02, 2019, 02:50:15 PM
Quote from: Marc Pons on May 02, 2019, 02:32:57 PM
a work_arround
why not have prepared different images from 1 to  ... what you need and according the number of incomming message you replace the image "message" by the one with the number on it.
I too thought at that but problem is you cannot know how many icons you will need. If number is too high ... too many icons.

I found this stackoverflow on how to create/paint an icon in memory.
https://stackoverflow.com/questions/16472538/changing-taskbar-icon-programatically-win32-c
It can be a start for PB porting. With some TextOut it could be possible to start from a base icon and paint some text

Title: Re: Notification Icon
Post by: Petrus Vorster on May 02, 2019, 02:58:27 PM
Hi guys

Thanks for the advice.
No, i have decided that this will do just fine.
One will never know how many notices could be generated, hence the thought for a floating label.

But this is fine, it draws the attention immediately without being too annoying.

Simple trick, but it works.

-Peter
Title: Re: Notification Icon
Post by: Marc Pons on May 02, 2019, 03:10:41 PM
hi Eros
it was also my idea to create an icon in memory, based on an existing one. thank's for the link

i'm sure i will use it one day... but for freebasic no more for powerbasic.



Title: Re: Notification Icon
Post by: Petrus Vorster on May 02, 2019, 03:35:00 PM
Sorry for being such a moron sometimes.

But should this not work to enable or disable the button:
htoolbar = GetDlgItem( HWND_FORM1, IDC_FORM1_TOOLBAR1)
   SendMessage hToolBar, %TB_SETSTATE, IDC_FORM1_TOOLBAR1_BUTTON5, %TBSTATE_DISABLED 


From what i read on the forum this is how you call a button on a toolbar to disable it, but it has absolutely no effect.
Probably why i never bothered with the Toolbars in the past.

-Peter
Title: Re: Notification Icon
Post by: Eros Olmi on May 02, 2019, 04:03:59 PM
I use something like:
gfrmMainToolBarHandle = GetDlgItem(HWND_FRMMAIN, IDC_FRMMAIN_REBAR)
...
ToolBar_EnableButton(gfrmMainToolBarHandle, IDC_FRMMAIN_TOOLBAR_BUNDLE_BUTTON_BUNDLE)
ToolBar_DisableButton(gfrmMainToolBarHandle, IDC_FRMMAIN_TOOLBAR_BUNDLE_BUTTON_BUNDLE)

Where:
HWND_FRMMAIN is the handle of the main window
IDC_FRMMAIN_REBAR is the ControlId of the toolbar
gfrmMainToolBarHandle is the handle of the toolbar
IDC_FRMMAIN_TOOLBAR_BUNDLE_BUTTON_BUNDLE is the ControlId of the button
Title: Re: Notification Icon
Post by: Eros Olmi on May 02, 2019, 04:05:08 PM
Quote from: Marc Pons on May 02, 2019, 03:10:41 PM
i'm sure i will use it one day... but for freebasic no more for powerbasic.
I'm trying to make the switch too.
Title: Re: Notification Icon
Post by: Eros Olmi on May 02, 2019, 04:56:27 PM
Put together something to test and modify from PB sources.

Dynamic icon drawing:
https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/11906-dynamic-icon-in-task-bar

Test program:
https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/776881-change-icon-colors-on-the-fly?p=776902#post776902

Final result with executable and source code (PB10.4) attached, press button to increment number inside icon
Title: Re: Notification Icon
Post by: Petrus Vorster on May 02, 2019, 05:07:21 PM
Cool.

Something like this?

Toolbarhandle = GetDlgItem(HWND_Form1, IDC_FORM1_REBAR)
  ToolBar_DisableButton(Toolbarhandle, IDC_FORM1_TOOLBAR1_BUTTON5)


Ok, still no success.
I am still working through the other examples.

Thanks again

Peter
Title: Re: Notification Icon
Post by: Petrus Vorster on May 02, 2019, 05:15:16 PM
I see, the person had exactly the same idea as i had.
Well, its bed-time now, and i will give this a good crack over the weekend.

Much appreciated for all the help!

-Peter
Title: Re: Notification Icon
Post by: Petrus Vorster on May 02, 2019, 05:47:17 PM
Hi all

Just had to figure it out myself.
Now it seem obvious.

First a handle to the toolbar.
Then use the handle to get the Rebar handle.
Then use that to get the button.

Dim rebarhandle As Dword
  Dim toolbarhandle As Dword
  Rebarhandle = GetDlgItem(HWND_FORM1,IDC_FORM1_REBAR)
  Toolbarhandle = GetDlgItem(Rebarhandle,IDC_FORM1_TOOLBAR1)
  ToolBar_DisableButton(Toolbarhandle, IDC_FORM1_TOOLBAR1_BUTTON5)   


I appreciate your patience and help.

Regards, Peter