Announcement

Collapse
No announcement yet.

My modifications of Peter's 2/28/03 code didn't work as expected

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

  • My modifications of Peter's 2/28/03 code didn't work as expected

    I read the code Peter posted to solve Oliver's problem and it seemed to be a perfect answer to a problem I had. Thhe code is below:
    ----------------------------------------------
    #Compile Exe
    #Include "win32api.inc"
    Global hThread As Long, hDlg As Long, hCons As Long, lTI As NOTIFYICONDATA, hIcon As Long
    %WM_TRAYICON = %WM_USER + 1001
    CallBack Function MainCB () As Long
    Select Case CbMsg
    Case %WM_INITDIALOG
    lTI.cbSize = SizeOf (lTI)
    lTI.hWnd = hDlg
    lTI.uID = GetmoduleHandle(ByVal 0)
    lTI.uFlags = %NIF_ICON Or %NIF_MESSAGE Or %NIF_TIP
    lTI.uCallBackMessage = %WM_TRAYICON
    lTI.hIcon = hIcon
    lTI.szTip = "Hit me please!"
    Case %WM_TRAYICON
    Select Case LoWrd(CbLParam)
    Case %WM_LBUTTONUP
    ShowWindow hDlg, %SW_RESTORE
    Shell_NotifyIcon %NIM_DELETE, lTI
    End Select
    Case %WM_SIZE
    If CbWParam = %SIZE_MINIMIZED Then
    ShowWindow hDlg, %SW_HIDE
    Shell_NotifyIcon %NIM_ADD, lTI
    End If
    End Select
    End Function
    Function PbMain () As Long
    Dialog New 0, "Testing...",,,100,100, %WS_SYSMENU Or %WS_CAPTION Or %WS_MINIMIZEBOX, %WS_EX_TOPMOST To hDlg
    hIcon = LoadIcon(0, ByVal %IDI_QUESTION)
    Dialog Show Modal hDlg, Call MainCB
    End Function
    ---------------------------------------------------
    When I modified it, as follows, everything worked except the icon in the tray was the default application icon, not mine.
    #COMPILE EXE
    #INCLUDE "win32api.inc"
    GLOBAL hThread AS LONG, hDlg AS LONG, hCons AS LONG, lTI AS NOTIFYICONDATA, hIcon AS LONG
    %WM_TRAYICON = %WM_USER + 1001
    #RESOURCE ICON, 1000, "C:\USERS\JEFF\Documents\PowerBasic Projects\Notify Icon\Notify.ICO"
    CALLBACK FUNCTION MainCB () AS LONG
    SELECT CASE CBMSG
    CASE %WM_INITDIALOG
    lTI.cbSize = SIZEOF (lTI)
    lTI.hWnd = hDlg
    lTI.uID = GetmoduleHandle(BYVAL 0)
    lTI.uFlags = %NIF_ICON OR %NIF_MESSAGE OR %NIF_TIP
    lTI.uCallBackMessage = %WM_TRAYICON
    lTI.hIcon = hIcon
    lTI.szTip = "Hit me please!"
    CASE %WM_TRAYICON
    SELECT CASE LOWRD(CBLPARAM)
    CASE %WM_LBUTTONUP
    ShowWindow hDlg, %SW_RESTORE
    Shell_NotifyIcon %NIM_DELETE, lTI
    END SELECT
    CASE %WM_SIZE
    IF CBWPARAM = %SIZE_MINIMIZED THEN
    ShowWindow hDlg, %SW_HIDE
    Shell_NotifyIcon %NIM_ADD, lTI
    END IF
    END SELECT
    END FUNCTION
    FUNCTION PBMAIN () AS LONG
    DIALOG NEW 0, "Testing...",,,100,100, %WS_SYSMENU OR %WS_CAPTION OR %WS_MINIMIZEBOX, %WS_EX_TOPMOST TO hDlg
    DIALOG SET ICON hDlg, "#1000"
    hIcon = LoadIcon(0, BYVAL %IDI_APPLICATION)
    DIALOG SHOW MODAL hDlg, CALL MainCB
    END FUNCTION
    Any advice? For the life of me I cannot figure it out.

  • #2
    try the code tags or paste as BBCode in the ide.

    Code:
      hIcon = LoadIcon(GetModuleHandle(ByVal 0 ), ByVal MAKEINTRESOURCE(1000))

    test9.bas
    Code:
    #Compile Exe
    #Include "win32api.inc"
    Global hThread As Long, hDlg As Long, hCons As Long, lTI As NOTIFYICONDATA, hIcon As Long
    %WM_TRAYICON = %WM_User + 1001
    #Resource Icon, 1000, "Sad.ICO"
     
    CallBack Function MainCB () As Long
      Select Case CbMsg
        Case %WM_InitDialog
          lTI.cbSize = SizeOf (lTI)
          lTI.hWnd = hDlg
          lTI.uID = GetmoduleHandle(ByVal 0)
          lTI.uFlags = %NIF_ICON Or %NIF_MESSAGE Or %NIF_TIP
          lTI.uCallBackMessage = %WM_TRAYICON
          lTI.hIcon = hIcon
          lTI.szTip = "Hit me please!"
        Case %WM_TRAYICON
          Select Case LoWrd(CbLParam)
            Case %WM_LButtonUp
              ShowWindow hDlg, %SW_Restore
              Shell_NotifyIcon %NIM_DELETE, lTI
          End Select
        Case %WM_Size
          If CbWParam = %SIZE_MINIMIZED Then
            ShowWindow hDlg, %SW_Hide
            Shell_NotifyIcon %NIM_ADD, lTI
          End If
      End Select
    End Function
     
    Function PBMain () As Long
      Dialog New 0, "Testing...",,,100,100, %WS_SysMenu Or %WS_Caption Or %WS_MinimizeBox, %WS_Ex_Topmost To hDlg
      Dialog Set Icon hDlg, "#1000"
      hIcon = LoadIcon(GetModuleHandle(ByVal 0 ), ByVal MAKEINTRESOURCE(1000))
    Dialog Show Modal hDlg, Call MainCB
    End Function
    LarryC
    Website
    Sometimes life's a dream, sometimes it's a scream

    Comment


    • #3
      Larry,

      Works like a charm! I've got a lot to learn about this powerful language even though I've been programming since the late 70s. I'm enjoying the process. The great thing about PB is that there is a lot mor suppor than with VB, Delphi ets.

      Thanks again,

      Jeff

      Comment

      Working...
      X