Solved

Show program only at startbar as an icon

Posted on 1998-11-06
7
171 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
ID: 1177108
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
ID: 1177109
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
ID: 1177110
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 10

Expert Comment

by:viktornet
ID: 1177111
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
ID: 1177112
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
ID: 1177113
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
ID: 1177114
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

821 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