 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bob Byers Guest
|
Posted: Sat Mar 26, 2005 8:49 pm Post subject: Taskbar Button |
|
|
I'd like to have my program not have a taskbar button and show an icon
in the notification area instead. I know this can be done, but haven't
any idea as to how to even search for how to do it. Can anyone point me
to a source of info on how to do it.
TIA
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
|
| Back to top |
|
 |
Bob Byers Guest
|
Posted: Sun Mar 27, 2005 1:03 am Post subject: Re: Taskbar Button |
|
|
Remy
Thanks for the referrels. I have it ALMOST working. In fact, I'm down
to one problem. The icon for the notification window doesn't display.
I downloaded the program Tray from the archive and copied all of the
code. I even took the res files from the tray program and used them in
my own program.
An area in the Taskbar notification area clears when the program loads,
moving the mouse to this blank area lets me see the program hint, and
clicking on this blank area gets me a popup that I can use to display
the main window, or to close and exit. All works except NO ICON. Any
ideas?
TIA
Bob Byers wrote:
| Quote: | I'd like to have my program not have a taskbar button and show an icon
in the notification area instead. I know this can be done, but haven't
any idea as to how to even search for how to do it. Can anyone point me
to a source of info on how to do it.
TIA
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sun Mar 27, 2005 8:54 am Post subject: Re: Taskbar Button |
|
|
"Bob Byers" <rbyers (AT) marshallelectronics (DOT) net> wrote
| Quote: | The icon for the notification window doesn't display.
|
You did not show your code.
| Quote: | An area in the Taskbar notification area clears when the program
loads, moving the mouse to this blank area lets me see the program
hint, and clicking on this blank area gets me a popup that I can use
to display the main window, or to close and exit. All works except
NO ICON.
|
You probably did not provide a valid icon when calling Shell_NotifyIcon().
Gambit
|
|
| Back to top |
|
 |
Bob Byers Guest
|
Posted: Sun Mar 27, 2005 4:34 pm Post subject: Re: Taskbar Button |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | "Bob Byers" <rbyers (AT) marshallelectronics (DOT) net> wrote in message
news:424605db$1 (AT) newsgroups (DOT) borland.com...
The icon for the notification window doesn't display.
You did not show your code.
An area in the Taskbar notification area clears when the program
loads, moving the mouse to this blank area lets me see the program
hint, and clicking on this blank area gets me a popup that I can use
to display the main window, or to close and exit. All works except
NO ICON.
You probably did not provide a valid icon when calling Shell_NotifyIcon().
Gambit
That may be, but I copied and used the TRAYICON.RES file from the sample |
project Tray.bpr. I tried using both SMAIL.RES and TRAY.RES as the
first RES file.
//--------------------------smail.cpp
#include <vcl.h>
#pragma hdrstop
#include "loadapi.h"
//---------------------------------------------------------------------------
USERES("tray.res");
USEFORM("MainCode.cpp", Main);
// TrayIcons.res contains the icon resource for the tray.
USERES("TRAYICON.res");
USEFORM("MailStatusCode.cpp", MailStatus);
USEFORM("MailClient.cpp", MailClient);
USEFORM("TrackingCode.cpp", Tracking);
USEFORM("NotifyCode.cpp", Notify);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
//=======================================================
HANDLE hInstanceMutex = ::CreateMutex(NULL,TRUE, "SMail");
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
if(hInstanceMutex)
CloseHandle(hInstanceMutex);
// Find the HWND of the hidden application window of the previous
// instance. Note that we are not looking for the HWND of the main
// form. This code fails miserably if you pass it the main form
// HWND instead of the Application's HWND
Application->Title = "SMail";
HWND hPrevApp = ::FindWindow(NULL, "SMail");
if(hPrevApp)
PostMessage(hPrevApp, WM_SYSCOMMAND, SC_RESTORE, 0);
return 0;
}
try
{
Application->Initialize();
Application->Title = "SMail";
if (LoadAPI())
Application->Terminate();
DbInit("admin");
Application->CreateForm(__classid(TMain), &Main);
Application->CreateForm(__classid(TMailClient), &MailClient);
Application->CreateForm(__classid(TTracking), &Tracking);
Application->CreateForm(__classid(TNotify), &Notify);
// don't show the app's taskbar icon or the main form
ShowWindow(Application->Handle,SW_HIDE);
Application->MainForm->Visible = false;
Application->ShowMainForm = false;
Application->Run();
DbExit(); // Close DLL
FreeAPI();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
ReleaseMutex(hInstanceMutex);
CloseHandle(hInstanceMutex);
return 0;
}
//---------------------------------------------------------------------------
//--------------------------------maincode.cpp
#include <vcl.h>
#pragma hdrstop
// The first constant is the ID of the trayicon. The value
// is arbitrary. If your program displays more than one tray
// icon at a time, choose a unique ID for each icon.
// The char * constant is the hint text for the tray icon.
// The last constant is a user defined message that the tray
// will send to our window handle for tray mouse events.
const int IDC_TRAY1 = 1005;
const char *HINT_MESSAGE = "Guitar Center EMail";
#include <shellapi.h>
#include <Clipbrd.hpp>
#include <iostream>
using namespace std;
#include <io.h>
#include <stdlib.h>
#include <stdio.h>
#include <dir.h>
#include "loadapi.h"
#include "xbase2.h"
#include "utility.h"
#include "MainCode.h"
//#include "emailcfgcode.h"
#include "execute.h"
#include "mailclient.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMain *Main;
//---------------------------------------------------------------------------
__fastcall TMain::TMain(TComponent* Owner)
: TForm(Owner)
{
pDatabase = NULL ; // make sure database object is initialized
LoginOK = false;
// Load the icon from the EXE's resources
TrayIcon = new Graphics::TIcon;
TrayIcon->Handle=LoadImage(HInstance,
"LITTLEICON",
IMAGE_ICON,
0,0,
0);
// Add the icon to the taskbar
AddIcon();
Application->OnMinimize = AppOnMinimize;
Application->OnRestore = AppOnRestore;
}
__fastcall TMain::~TMain()
{
// Remove the icon from the tray, and delete
// the TIcon pointer that we initially created.
RemoveIcon();
delete TrayIcon;
}
//---------------------------------------------------------------------------
void __fastcall TMain::FormShow(TObject *Sender)
{
FmtInit();
pDatabase = new TB2Database ;
pDatabase->ShowErrors(false); // don't display any errors
login = "GCOrders";
password = "mei273";
popserver = "marshallelectronics.net";
smtpserver= "marshallelectronics.net";
TargetDomain = "guitarcenter.com";
BasicInterval= 600 * SECONDS;
char buffer[MAXPATH];
getcwd(buffer, MAXPATH);
String directory = AnsiString(buffer);
strcat(buffer,"\smail");
String dbname = AnsiString(buffer);
LoginOK = pDatabase->OpenDatabase(dbname,""); // try local
if (LoginOK)
{
pDatabase->OpenTable("emailattachments");
pDatabase->OpenTable("emaillink");
pDatabase->OpenTable("EMailHeader");
pDatabase->OpenTable("email");
Caption = "MEI";
// WindowState = wsMinimized;
Timer1->Interval = BasicInterval;
Timer2->Enabled = true;
}
else
{
ExecuteTool("wrepair smail",directory.c_str());
BobMessage("Database Repaired - Restart the program");
Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::AppOnMinimize(TObject *Sender)
{
ShowWindow(Application->Handle, SW_HIDE);
Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TMain::AppOnRestore(TObject *Sender)
{
ShowWindow(Application->Handle, SW_SHOW);
Visible = true;
SetForegroundWindow(Handle);
}
//---------------------------------------------------------------------------
void __fastcall TMain::FormClose(TObject *Sender, TCloseAction &Action)
{
while (!Timer1->Enabled) // mail check may be in progress
::Sleep(200);
Timer1->Enabled = false;
delete pDatabase;
// This application closes to the system tray. When they push
// close, hide the app, but don't let the program close.
if(!Application->Terminated)
{
ShowWindow(Application->Handle, SW_HIDE);
Visible = false;
Action = caNone;
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::Timer1Timer(TObject *Sender)
{
MailClient->CheckMailExecute(this);
}
//---------------------------------------------------------------------------
void __fastcall TMain::Timer2Timer(TObject *Sender)
{
MailClient->LoadRcvdMail();
Timer2->Enabled = false;
Timer1->Enabled = true;
Timer1->Interval = 2000;
}
//---------------------------------------------------------------------------
void __fastcall TMain::File1Click(TObject *Sender)
{
Close();
}
//-------------------------------------------------------
void __fastcall TMain::WMTrayNotify(TMessage &Msg)
{
// The LPARAM of the message identifies the type of mouse message.
// When they right click, show the popup menu. When they double
// click with the left mouse, show the form.
switch(Msg.LParam)
{
case WM_RBUTTONUP:
// Find the mouse cursor and popup the popupmenu at that
// location. The SetForegroundWindow and PostMessage calls
// fix an OS bug that prevents the menu from closing when
// the user clicks outside the menu. KB article Q135788
POINT WinPoint;
GetCursorPos(&WinPoint);
SetForegroundWindow(Handle);
PopupMenu1->Popup(WinPoint.x,WinPoint.y);
PostMessage(Handle, WM_NULL, 0,0);
break;
case WM_LBUTTONDBLCLK:
Visible = true;
ShowWindow(Application->Handle, SW_SHOW);
break;
}
}
//-------------------------------------------------------
void __fastcall TMain::UnloadBtnClick(TObject *Sender)
{
// Terminate the app when they choose the upload option
Application->Terminate();
}
//-------------------------------------------------------
void __fastcall TMain::AddIcon()
{
// Use the Shell_NotifyIcon API function to
// add the icon to the tray.
NOTIFYICONDATA IconData;
IconData.cbSize = sizeof(NOTIFYICONDATA);
IconData.uID = IDC_TRAY1;
IconData.hWnd = Handle;
IconData.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
IconData.uCallbackMessage = WM_TRAYNOTIFY;
lstrcpy(IconData.szTip, HINT_MESSAGE);
IconData.hIcon = TrayIcon->Handle;
Shell_NotifyIcon(NIM_ADD,&IconData);
}
//-------------------------------------------------------
void __fastcall TMain::RemoveIcon()
{
NOTIFYICONDATA IconData;
IconData.cbSize = sizeof(NOTIFYICONDATA);
IconData.uID = IDC_TRAY1;
IconData.hWnd = Handle;
IconData.hIcon = TrayIcon->Handle;
Shell_NotifyIcon(NIM_DELETE,&IconData);
}
//---------------------------------------------------------------------------
void __fastcall TMain::ExitProgram1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TMain::ShowMail1Click(TObject *Sender)
{
Visible = true;
ShowWindow(Application->Handle, SW_SHOW);
}
//---------------------------------------------------------------------------
//------------maincode.h
//---------------------------------------------------------------------------
#ifndef MainCodeH
#define MainCodeH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Menus.hpp>
#include <ExtCtrls.hpp>
#define INCOMING 1
#define NEWMAIL 2
#define OUTGOING 0
#define REMINDER 1
#define HISTORY 0
#define NAMENDX 2
#define COMPANYNDX 1
//---------------------------------------------------------------
#define ONETIMEEVENT 0
#define DAILY 1
#define WEEKLY 2
#define MONTHLY 3
#define YEARLY 4
//--------------------------------- define phone codes
#define WORKPHONE 0
#define HOMEPHONE 1
#define CELLPHONE 2
#define PAGER 3
#define WORKFAX 4
#define HOMEFAX 5
#define EMAIL 6
#define WWWURL 1000
//--------------------------------- define index numbers
#define SECONDS 1000
//--------------------------------- colors
#define WHITE 0
#define RED 1
#define YELLOW 2
#define GREEN 3
#define LIME 4
#define AQUA 5
#define MAROON 6
#define SILVER 7
#define BUTTONFACE 8
#define GREY 8
#define BLUE 10
//---------------------------------navigation values
#define FIRST 0
#define NEXT 3
#define PREVIOUS 2
#define NEXTREC 4
#define PREVREC 5
#define LAST 6
#define TOP 0
#define BOTTOM 6
//---------------------------------------------------------------------------
#define WM_TRAYNOTIFY (WM_USER + 1001)
class TMain : public TForm
{
__published: // IDE-managed Components
TMainMenu *MainMenu1;
TMenuItem *File1;
TMenuItem *Edit1;
TMenuItem *Help1;
TTimer *Timer1;
TTimer *Timer2;
TPopupMenu *PopupMenu1;
TMenuItem *ShowMail1;
TMenuItem *ExitProgram1;
void __fastcall FormShow(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall Timer2Timer(TObject *Sender);
void __fastcall File1Click(TObject *Sender);
void __fastcall UnloadBtnClick(TObject *Sender);
void __fastcall ExitProgram1Click(TObject *Sender);
void __fastcall ShowMail1Click(TObject *Sender);
private: // User declarations
Graphics::TIcon *TrayIcon;
void __fastcall WMTrayNotify(TMessage &Msg);
void __fastcall RemoveIcon();
void __fastcall AddIcon();
// this is stuff from the tray program
void __fastcall AppOnMinimize(TObject *Sender);
void __fastcall AppOnRestore(TObject *Sender);
public: // User declarations
String
login,password,smtpserver,popserver,leavemailonserver,TargetDomain;
int BasicInterval;
bool LoginOK;
__fastcall TMain(TComponent* Owner);
__fastcall ~TMain();
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_TRAYNOTIFY,TMessage,WMTrayNotify)
END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TMain *Main;
//---------------------------------------------------------------------------
#endif
|
|
| Back to top |
|
 |
Bob Byers Guest
|
Posted: Tue Mar 29, 2005 5:21 am Post subject: Re: Taskbar Button |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | You probably did not provide a valid icon when calling Shell_NotifyIcon().
Gambit
You are surely right. LoadImage returns a NULL instead of a handle. |
But, I just don't see what I've done wrong. I've used the RES files
from TrayIcon.Res file from the sample Tray program and copied all of
the references exactly as you can see from the code in my last message.
I just don't know where to go from here.
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Mar 29, 2005 7:29 am Post subject: Re: Taskbar Button |
|
|
"Bob Byers" <rbyers (AT) marshallelectronics (DOT) net> wrote
| Quote: | You are surely right. LoadImage returns a NULL instead of
a handle. But, I just don't see what I've done wrong.
|
When LoadImage() fails, you can use GetLastError() to find out why it
failed.
Gambit
|
|
| Back to top |
|
 |
Andrue Cope [TeamB] Guest
|
Posted: Tue Mar 29, 2005 10:25 am Post subject: Re: Taskbar Button |
|
|
Remy Lebeau (TeamB) wrote:
Although there are a couple of gotchas that I had to resolve.
The restore function needs to call Application->Restore() or else
Minimise only works once. 'USERES' does nothing in BCB6 so a comment
needs to be added indicating how to add resources to a project.
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
|
|
| Back to top |
|
 |
Andrue Cope [TeamB] Guest
|
Posted: Tue Mar 29, 2005 11:09 am Post subject: Re: Taskbar Button |
|
|
Sigh. And a further gotcha.
If using ATL (COM applications) you need to use VCL_MESSAGE_HANDLER not
MESSAGE_HANDLER.
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
|
|
| Back to top |
|
 |
Bob Byers Guest
|
Posted: Tue Mar 29, 2005 3:13 pm Post subject: Re: Taskbar Button |
|
|
Andrue Cope [TeamB] wrote:
in the programs that I got from the bcbdev.com faq pages. But, the
exact same code doesn't work in mine. This is truly a puzzle to me.
|
|
| Back to top |
|
 |
Andrue Cope [TeamB] Guest
|
Posted: Tue Mar 29, 2005 3:55 pm Post subject: Re: Taskbar Button |
|
|
Bob Byers wrote:
| Quote: | OK, then how do I add the resource to the project?
|
The way I did it was to insert the RES as I would a CPP using the
Project Manager. This does of course put you at risk of the infamous
resource-file-stops-compilation bug but I got away with it :)
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
|
|
| Back to top |
|
 |
Bob Byers Guest
|
Posted: Tue Mar 29, 2005 4:12 pm Post subject: Re: Taskbar Button |
|
|
Andrue Cope [TeamB] wrote:
| Quote: | Bob Byers wrote:
OK, then how do I add the resource to the project?
The way I did it was to insert the RES as I would a CPP using the
Project Manager. This does of course put you at risk of the infamous
resource-file-stops-compilation bug but I got away with it :)
I think that I've found a problem here. I looked at the TrayIcon.res |
file with the Image Editor (I had never used this before) and discovered
that the program was using the wrong name for the icon. When I renamed
it, the program now puts the icon in the task window. Why the name
changed I have no Idea. I do have one question.. there doesn't seem to
be a way to copy an icon from an Ico file into the image editor. How do
you do this, or do you have to manufacture all new items by hand? The
help file doesn't address this.
|
|
| Back to top |
|
 |
Andrue Cope [TeamB] Guest
|
Posted: Tue Mar 29, 2005 4:17 pm Post subject: Re: Taskbar Button |
|
|
Bob Byers wrote:
| Quote: | I do have one question.. there doesn't seem to be a way to copy an
icon from an Ico file into the image editor.
|
I think you'll have to ask that in the .ide section, Bob :)
Follow-up set.
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|