Solved

Show program only at startbar as an icon

Posted on 1998-11-06
7
167 Views
Last Modified: 2010-04-02
Hi.
How do I make my Borland C++ Builder program
(one Form) show up only at the same place where the
time is shown at Win95.
0
Comment
Question by:boel
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
Comment Utility
This is quite simple:
1. Don't call 'ShowWindow()'
2. Use the following code to add an icon:
BOOL TaskBarAddIcon     (   HWND    hwnd,
                            UINT    uID,
                            HICON   hicon,
                            LPSTR   lpszTip
                        )
{
    BOOL            bRC;
    NOTIFYICONDATA  nid;
 
    nid.cbSize              =   sizeof  (   NOTIFYICONDATA);
    nid.hWnd                =   hwnd;
    nid.uID                 =   uID;
    nid.uFlags              =   NIF_MESSAGE | NIF_ICON | NIF_TIP;
    nid.uCallbackMessage    =   WM_USER +   uID;
    nid.hIcon               =   hicon;

    if  (   lpszTip)
            lstrcpyn    (   nid.szTip,  lpszTip,    sizeof  (   nid.szTip));
    else
            nid.szTip[ 0]   =   '\0';
 
    bRC     =   Shell_NotifyIcon(   NIM_ADD,    &nid);
 
    if  (   hicon)
            DestroyIcon (   hicon);
 
    return( bRC);
}

Make sure to handle the callback messages (at least, return somethin that's non-zero), otherwise the icon will be deleted...
0
 

Author Comment

by:boel
Comment Utility
Where do I put the code, in my Unit1.cpp
---------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "Unit1.h"
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
      : TForm(Owner)
{
}
-------------------------------------------

or in my project1.cpp

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
      try
      {
            Application->Initialize();
            Application->CreateForm(__classid(TForm1),&Form1);
            Application->Run();
      }
      catch (Exception &exception)
      {
            Application->ShowException(&exception);
      }
      return 0;
}-----------------------------
BOEL

0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Well, it depends on when you want to show up the icon - in a plain Win32 program, i'd add the icons immediatly after the call to 'CreateWindow()', just before entering the main message loop.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Expert Comment

by:viktornet
Comment Utility
after Application->CreateForm() you put this one...

Application->ShowMainForm = false;

The function should be executed at OnCreate() of the form.....

Cheers,
Viktor
0
 

Author Comment

by:boel
Comment Utility
Well, it nearly work, but I dont see any icon,
just an empty space where the icon should be.
How about the parameter to TaskBarAddIcon()
The first one "hwnd", which handle shall I pass to that one
 Application->Handle or Form->Handle?
The last one "lpszTip" is the text that show up when the mouse-
-pointer is over the icon I think.
But what about the second and third paramter
"uID", "hicon" ?  
And how shall I handle the callback messages that "jkr" told me in the proposed answer??
One more question, (that maybe not included in the start question), how do I do to make the Icon response to mouseclick??
Boel
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
You need to pass the Application->Handle.... and you need to assigne something to the icon, if you want to have an icon in the emprty space...

for example...

AddICon.... (..... , Application->Icon,.........);

to have the icon of the app in the task bar...

and remember that you need to remove the taken space by the your procedure....That procedure puts it in the task bar, but it needs to realese it in OnDestroy() of your application...

Cheers,
Viktor
0
 

Expert Comment

by:zouying
Comment Utility
You can also get help about taskbar in help file. Search Win32 SDK.
As far as I know, there is no MFC support like CTaskbar, you should use Win32 SDK to implement.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now