Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

DDT Tray Loader

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DDT Tray Loader

    comments to:
    http://www.powerbasic.com/support/pb...ad.php?t=12438

    Code:
    #if 0
        ----------------------------                      powerbasic v8.1
     ---|          dasoft          |------------------------------------------
        ----------------------------         code           date: 2005-09-19
        | file name  ddt tray .bas |          by
        ----------------------------  don schullian, jr.
     
                  this code is released into the public domain
           ----------------------------------------------------------
            no guarantee as to the viability, accuracy, or safety of
             use of this code is implied, warranted, or guaranteed
           ----------------------------------------------------------
                             use at your own risk!
           ----------------------------------------------------------
                      contact author at [email protected]
                       for more code come to my web site
                            [url="http://www.dasoftvss.com/basic"]www.dasoftvss.com/basic[/url] 
     -------------------------------------------------------------------------
     
    while looking to create a program that could sit on the tray but still be do
    in ddt code i ran across some code done by dane westvik back in 2001. i've
    messed with it a bit removing some items and sprucing up others.
     
    the test code shows 3 ways to get something happening from the tray menu:
     
    1: a pre-prepared dialog  "main program"
    2: a build on-the-fly dialog "second program"
    3: a pb message from inside the tray code's callback. "about screen"
     
    i think the code is clean enough for you to drag your way through and change
    it to your individual needs.
     
    note: the icon used for the tray (yes you should have one) is pulled from
    windows' stock so you'll want to build your own and create a resource file.
     
    c'ya,
    don schullian
    don(at)dasoftvss(dot)com
    #endif
     
    #compile exe
    #compiler pbwin 8
    #debug error on
    #dim all
     
    %usemacros = 1
    #include "win32api.inc"
     
    global g_hinst  as dword
    '
    '------------------------------------------------------------------------------
    '
    callback function fsecondprogram_cb () as long
     
      select case as long cbmsg
        case %wm_command
          select case as long cbctl
            case 1000 : if cbctlmsg = %bn_clicked or cbctlmsg = 1 then
                         dialog end cbhndl, 0
                        end if
            case 1001 : if cbctlmsg = %bn_clicked or cbctlmsg = 1 then
                         dialog end cbhndl, 1
                        end if
          end select
      end select
     
    end function
    '
    '------------------------------------------------------------------------------
    '
    function fsecondprogram ( byval hparent as dword ) as long
     
      dim hdlg  as local dword
      dim lrslt as local long
     
      dialog new hparent,"second program", , , 165, 23 to hdlg
     
      control add button, hdlg, 1000, "close"      ,   5, 5,  50, 13
      control add button, hdlg, 1001, "terminate"  , 110, 5,  50, 13
     
      dialog show modal hdlg call fsecondprogram_cb to lrslt
     
      function = lrslt
     
    end function
     
    '
    '------------------------------------------------------------------------------
    '
    callback function fmainprogram_cb () as long
     
      select case as long cbmsg
        case %wm_command
          select case as long cbctl
            case 1000 : if cbctlmsg = %bn_clicked or cbctlmsg = 1 then
                          dialog show state cbhndl, %sw_hide
                        end if
          end select
      end select
     
    end function
    '
    '------------------------------------------------------------------------------
    '
    function fmainprogram ( byval hparent as dword ) as dword
     
      dim hdlg as local dword
     
      dialog new hparent,"main program", , , 165, 23 to hdlg
     
      control add label , hdlg,  100, "hello world",   5, 5, 100, 13
      control add button, hdlg, 1000, "hide me"    , 110, 5,  50, 13
     
      function = hdlg
     
    end function
    '
    '------------------------------------------------------------------------------
    '
    %wm_tray     = %wm_user +  1
    %tray_timer  = %wm_user +  2
    %tray_main   = %wm_user + 10
    %tray_2ed    = %wm_user + 11
    %tray_cancel = %wm_user + 20
    %tray_about  = %wm_user + 30
    %tray_quit   = %wm_user + 40
    '
    '------------------------------------------------------------------------------
    '
    callback function trayloader_cb () as long
     
      dim tn         as static notifyicondata
      dim lite       as static long
      dim shown      as static long
     
      dim  flags     as local long
      dim hhndl      as local dword
      dim tp         as local pointapi
     
      select case cbmsg
        case %wm_initdialog : tn.cbsize = sizeof(tn)
                              tn.hwnd   = cbhndl
                              tn.uid    = g_hinst
                              tn.uflags = %nif_icon or %nif_message or %nif_tip
                              tn.ucallbackmessage = %wm_tray
                              tn.hicon = loadicon(%null,byval maklng(%idi_question,0))
                              tn.sztip = "ddt tray menu"
                              shell_notifyicon %nim_add, tn
        case %wm_destroy    : shell_notifyicon %nim_delete, tn
        case %wm_tray       : select case cblparam
                                case %wm_rbuttondown
                                  getcursorpos tp
                                  setforegroundwindow cbhndl
                                  dialog get user cbhndl, 8 to hhndl
                                  flags = %tpm_bottomalign or %tpm_rightalign
                                  trackpopupmenu hhndl, flags, tp.x, tp.y, 0, cbhndl, byval %null
                                  postmessage cbhndl, %wm_null, 0, 0
                                case %wm_lbuttondblclk
                                  goto show_main
                              end select
        case %wm_command    : select case cbctl
                                case %tray_main  : goto show_main
                                case %tray_2ed   : dialog get user cbhndl, 8 to hhndl
                                                   menu set state hhndl, bycmd %tray_2ed, %mf_grayed
                                                   if fsecondprogram(cbhndl) then
                                                       goto kill_both
                                                     else
                                                       dialog get user cbhndl, 8 to hhndl
                                                       menu set state hhndl, bycmd %tray_2ed, %mf_enabled
                                                   end if
                                case %tray_about : msgbox "ddt tray demo", %mb_ok, "ddt tray"
                                case %tray_quit  : goto kill_both
                              end select
      end select
      exit function
      '--------------------------------------
      '----- local stuff --------------------
      '--------------------------------------
      show_main:
        dialog get user cbhndl, 8 to hhndl
        menu set state hhndl, bycmd %tray_main, %mf_grayed
        dialog get user cbhndl, 1 to hhndl
        dialog show state hhndl, %sw_show
        if not shown then
          shown = -1
          dialog show modal hhndl call fmainprogram_cb
        end if
        dialog get user cbhndl, 8 to hhndl
        menu set state hhndl, bycmd %tray_main, %mf_enabled
      exit function
     
      kill_both:
        dialog get user cbhndl, 1 to hhndl
        dialog end hhndl , 0
        dialog end cbhndl, 0
      exit function
     
    end function
    '
    '------------------------------------------------------------------------------
    '
    sub trayloader ( )
     
      dim hdlg      as local dword
      dim htraymenu as local dword
      dim  events   as local long
     
      menu new popup to htraymenu                                             ' create a pop-up menu for when
      menu add string, htraymenu, "main program", %tray_main  , %mf_enabled   ' the tray icon is clicked
      menu add string, htraymenu, "2ed program" , %tray_2ed   , %mf_enabled
      menu add string, htraymenu, "-"           , 100         , %mf_separator
      menu add string, htraymenu, "cancel"      , %tray_cancel, %mf_enabled
      menu add string, htraymenu, "-"           , 100         , %mf_separator
      menu add string, htraymenu, "about"       , %tray_about , %mf_enabled
      menu add string, htraymenu, "-"           , 100         , %mf_separator
      menu add string, htraymenu, "quit"        , %tray_quit  , %mf_enabled
     
      dialog new %hwnd_desktop, ", 0, 0, 0, 0, 0, %ws_ex_topmost or %ws_ex_toolwindow to hdlg
     
      dialog set user hdlg, 1, fmainprogram(hdlg)  ' send the 1st program's handle
      dialog set user hdlg, 8, htraymenu           ' send the pop-up menu's handle
     
      dialog show modeless hdlg call trayloader_cb ' start the tray program
      dialog show state hdlg, %sw_hide             ' hide it
     
      do                                           ' message pump
        dialog doevents to events
      loop until events = 0                        ' 'quit' was clicked
     
    end sub
    '
    '------------------------------------------------------------------------------
    '
    function fisalreadyrunning () as long
     
      dim hmutex as static dword
     
      dim zmutex as local  asciiz * %max_path
      dim  p     as local long
     
      if hmutex <> 0 then
        releasemutex hmutex
        hmutex = 0
        exit function
      end if
     
      if getmodulefilename(0,zmutex,%max_path) = 0 then
        function = -1
        exit function
      end if
     
      zmutex = parse$(zmutex, any "\:", -1 )
      hmutex = createmutex (byval %null, 0 , zmutex)
     
      function = (hmutex) and (getlasterror = %error_already_exists)
     
    end function
    '
    '------------------------------------------------------------------------------
    '
    function winmain ( byval curinst as dword     , _
                       byval prvinst as dword     , _
                       byval cmdline as asciiz ptr, _
                       byval cmdshow as long        ) as long
     
      dim hmain as local dword
     
      if fisalreadyrunning then exit function
     
      g_hinst = curinst                       ' this is required for later calls
     
      trayloader
     
      msgbox "exit program"
     
    end function
    [this message has been edited by don schullian (edited september 29, 2005).]
    C'ya
    Don

    http://www.ImagesBy.me
Working...
X