PowerBASIC Peer Support Forums
 

Go Back   PowerBASIC Peer Support Forums > Using the Forums

Using the Forums User to user discussions about navigating and using features of the forums.

Reply
 
Thread Tools Display Modes
  #1  
Old Apr 18th, 2012, 03:31 PM
Jeff Morhous Jeff Morhous is offline
Member
 
Join Date: Jun 2011
Location: Walker (Prescott),AZ
Posts: 17
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.
Reply With Quote
  #2  
Old Apr 18th, 2012, 04:44 PM
Larry Charlton Larry Charlton is offline
Member
 
Join Date: Jan 2011
Location: North Carolina USA
Posts: 1,316
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
Reply With Quote
  #3  
Old Apr 18th, 2012, 06:26 PM
Jeff Morhous Jeff Morhous is offline
Member
 
Join Date: Jun 2011
Location: Walker (Prescott),AZ
Posts: 17
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:58 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1999-2011 PowerBASIC, Inc. All Rights Reserved.
Error in my_thread_global_end(): 1 threads didn't exit