• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

System tray?

How do I have my program minimize to the Windows 95 System tray (I think that is what it is called, it holds the volume control and a few other apps) anyway.  How do I do it??  I am very new to C++ so if you have Borland C++ Builder, please show it to me visually (have my use their visual option instead of typing a bunch of codes.)

thanks
0
stevenc317
Asked:
stevenc317
  • 6
  • 3
  • 2
  • +1
1 Solution
 
jhanceCommented:
You can't do this "visually", you must write a "bunch of codes".  Here, however, is how you do it:

First you must define the NOTITYICONDATA structure with information about your application and what message to send it when the user does something to it in the tray (i.e. TRAY_MSG)

#define TRAY_MSG WM_USER+1

    NOTIFYICONDATA nid;
    nid.cbSize = sizeof(NOTIFYICONDATA);
    nid.hWnd = m_hWnd;
    nid.uID = 8376;
    nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    nid.uCallbackMessage = TRAY_MSG;
    nid.hIcon = hIcon;
    strcpy(nid.szTip, "My Application");

Then you call Shell_NotifyIcon() to tell the shell to add it to the tray:

    if(!Shell_NotifyIcon(NIM_ADD, &nid)){
        AfxMessageBox("Shell_NotifyIcon() returned FALSE", MB_OK, 0);
    }

Now when the user clicks on the tray icon, Windows will send a TRAY_MSG message to your application.  You might deal with it like this:

    const MSG *mp = GetCurrentMessage();
    if(mp->lParam == WM_LBUTTONDBLCLK){
        if(WasIconic){
            WasIconic = FALSE;
            ShowWindow(SW_RESTORE);
            BringWindowToTop();
        }
        else{
            WasIconic = TRUE;
            ShowWindow(SW_HIDE);
        }
    }

When you app ends, be sure to remove it from the tray:

    nid.uFlags = 0;

    if(!Shell_NotifyIcon(NIM_DELETE, &nid)){
        AfxMessageBox("Shell_NotifyIcon() returned FALSE", MB_OK, 0);
    }
0
 
stevenc317Author Commented:
sorry I can't find out where to put it..  Here is my source code for the main window..

//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include <ShellApi.h>
#include "Search.h"
#include "About.h"
#include "Yahoo.h"
#include "Title.h"
#include "Header.h"
#include "Alt.h"
#include "Splash.h"
#include "Credits.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
      : TForm(Owner)
{  StatusBar1->Panels->Items[1]->Text = Time().FormatString("h:nn:ss ampm        ");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::About1Click(TObject *Sender)
{
AboutBox->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Exit1Click(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N1GethigherinYahoo1Click(TObject *Sender)
{
Yahoo1->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N2Fourtitletags1Click(TObject *Sender)
{
Title1->ShowModal();      
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N3Headertips1Click(TObject *Sender)
{
Header1->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N4Addkeywordstoalttags1Click(TObject *Sender)
{
Alt1->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SplashClick(TObject *Sender)
{
SplashScreen1->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StatusBar1Click(TObject *Sender)
{
StatusBar1->Panels->Items[1]->Text = Time().FormatString("h:nn:ss ampm        ");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StevensWebDevelopment1Click(TObject *Sender)
{
ShellExecute(NULL, "open", "http://html.tou.com/webdev/",NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StevensWebHosting1Click(TObject *Sender)
{
ShellExecute(NULL, "open", "http://html.tou.com/hosting/",NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StevensWebPage1Click(TObject *Sender)
{
ShellExecute(NULL, "open", "http://html.tou.com/",NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::HtmlGoodies1Click(TObject *Sender)
{
ShellExecute(NULL, "open", "http://htmlgoodies.com",NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BigNoseBird1Click(TObject *Sender)
{
ShellExecute(NULL, "open", "http://www.bignosebird.com",NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FreeHelpBannerNetwork1Click(TObject *Sender)
{
ShellExecute(NULL, "open", "http://free-help.com",NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Credits1Click(TObject *Sender)
{
CreditsPage1->ShowModal();
}
//---------------------------------------------------------------------------
0
 
stevenc317Author Commented:
There HAS to be a easier way!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jhanceCommented:
As far as I'm concerned, you're on you own.  The data I posted earlier IS the way you do it.  I'm sorry you feel it's too complicated, perhaps you should write a letter of complaint to Microsoft and have them simplify the process.
0
 
nigel5Commented:
TForm1 has a constructor, put the first bit of jhance' code in there. It should have destructor, put the last bit in there. put in a handle to trap the minimize command and set ShowWindow(SW_HIDE). The middle bit of code is just a handler for when the user clicks on the icon in the tray with the left button, and will bring the window you just hid to the front. Unfortunately, it is the only way to do it without trapping mouse movement, and hacking screen bits, which is a whole lot harder.

You could add a sytem menu to take care of all the buttons you seem to have, so that when the user clicks on the icon, a menu will appear instead of the window.
0
 
vmpnCommented:
I am a begginner in this also and I have a source code for it. I'll post it when I'll get home.
0
 
vmpnCommented:
----Systray.cpp
#include <windows.h>
#include "systray.h"

// MyTaskBarAddIcon - adds an icon to the taskbar notification area.  
// Returns TRUE if successful or FALSE otherwise.
// hwnd - handle of the window to receive callback messages
// uID - identifier of the icon
// hicon - handle of the icon to add
// lpszTip - tooltip text
BOOL MyTaskBarAddIcon(HWND hwnd, UINT uID, HICON hicon, LPSTR lpszTip)
{
    BOOL res;
    NOTIFYICONDATA tnid;
 
    tnid.cbSize = sizeof(NOTIFYICONDATA);
    tnid.hWnd = hwnd;
    tnid.uID = uID;
    tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    tnid.uCallbackMessage = MYWM_NOTIFYICON;
    tnid.hIcon = hicon;
    if (lpszTip)
        lstrcpyn(tnid.szTip, lpszTip, sizeof(tnid.szTip));
    else
        tnid.szTip[0] = '\0';
 
    res = Shell_NotifyIcon(NIM_ADD, &tnid);
 
    if (hicon)
        DestroyIcon(hicon);
 
    return res;
}
 
// MyTaskBarDeleteIcon - deletes an icon from the taskbar  
//     notification area.
// Returns TRUE if successful or FALSE otherwise.
// hwnd - handle of the window that added the icon
// uID - identifier of the icon to delete
BOOL MyTaskBarDeleteIcon(HWND hwnd, UINT uID)
{
      BOOL res;
      NOTIFYICONDATA tnid;
 
      tnid.cbSize = sizeof(NOTIFYICONDATA);
      tnid.hWnd = hwnd;
      tnid.uID = uID;
             
      res = Shell_NotifyIcon(NIM_DELETE, &tnid);
      return res;
}
 
// MyTaskBarAddIcon - adds an icon to the taskbar notification area.  
// Returns TRUE if successful or FALSE otherwise.
// hwnd - handle of the window to receive callback messages
// uID - identifier of the icon
// hicon - handle of the icon to add
// lpszTip - tooltip text
BOOL MyTaskBarModifyIcon(HWND hwnd, UINT uID, HICON hicon, LPSTR lpszTip)
{
    BOOL res;
    NOTIFYICONDATA tnid;
 
    tnid.cbSize = sizeof(NOTIFYICONDATA);
    tnid.hWnd = hwnd;
    tnid.uID = uID;
      tnid.uFlags = 0;
      if(hicon)
            tnid.uFlags |= NIF_ICON;
      if(lpszTip)
             tnid.uFlags |= NIF_TIP;

    tnid.uCallbackMessage = MYWM_NOTIFYICON;
    tnid.hIcon = hicon;
    if (lpszTip)
        lstrcpyn(tnid.szTip, lpszTip, sizeof(tnid.szTip));
    else
        tnid.szTip[0] = '\0';
 
    res = Shell_NotifyIcon(NIM_MODIFY, &tnid);
 
    if (hicon)
        DestroyIcon(hicon);
 
    return res;
}
-----------end
0
 
vmpnCommented:
------------systray.h
#include <windows.h>

const UINT MYWM_NOTIFYICON = WM_USER;

BOOL MyTaskBarAddIcon(HWND hwnd, UINT uID, HICON hicon, LPSTR lpszTip);
BOOL MyTaskBarDeleteIcon(HWND hwnd, UINT uID);

--------end
0
 
vmpnCommented:
Here is the main function
---------start
#include <windows.h>
#include <stdlib.h>
#include "vaolrc.h"
#include "systray.h"
#include "aol_proc.h"

void Menu_Call(HWND hwnd, WPARAM wParam, LPARAM lParam);
void Icon_Message(HWND hwnd, WPARAM wParam, LPARAM lParam);
void ShowStatus();
BOOL InitApp();
BOOL InitSysIcon();


LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);

char szWinName[] = "BAOL100C"; /* Name of windows class */

//HWND our_hwnd;
char *IconLoadTip="BAOL Loading ...";
char *wndTitle = "Log - Be Always On Line (BAOL)";
char *prgTitle = "Be Always On Line";

const int window_height = 300;
const int window_width = 370;
const UINT MYuID = 1;

HMENU our_menu;

HWND wndStatus = 0, wndMain = 0;
HWND wndStatusMsgs = 0;
HINSTANCE prgThisInst;

double waiting_period = 20000;
char aol_path;

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
                              LPSTR lpszArgs, int nWinMode)
{
//      HWND hwnd;
      MSG       msg;
      WNDCLASS wc1;

      /* Define window class */
      wc1.hInstance = hThisInst; /* handle to this instance */
      wc1.lpszClassName = szWinName; /* window class name */
      wc1.lpfnWndProc = WindowFunc; /* window function */
      wc1.style = 0; /* default style */

      wc1.hIcon = LoadIcon(hThisInst, "icon_main"); /* icon style */
      wc1.hCursor = LoadCursor(NULL, IDC_ARROW); /* cursor style */
      wc1.lpszMenuName = NULL; /* no menu */

      wc1.cbClsExtra = 0; /* no extra */
      wc1.cbWndExtra = 0; /* information needed */

      /* Make the window background white. */
      wc1.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

      /* Register the window class. */
      if(!RegisterClass (&wc1)) return 0;

      prgThisInst = hThisInst;

      if(!InitApp())
            return 0;
      if(!InitSysIcon());
            return 0;

      /* Create the message loop */
      while(GetMessage(&msg, NULL, 0, 0))
      {
            TranslateMessage(&msg); /* allow use of keyboard */
            DispatchMessage(&msg); /* return control to Windows */
      }
      MyTaskBarDeleteIcon(wndMain, MYuID);
      return msg.wParam;
}

/* This function is called by Windows 95 and is passed
      messages from the message queue.
*/
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
            

      if (wndMain ==  hwnd)      
      {
            switch(message)
            {
                  case WM_DESTROY: /* terminate the program */
                        PostQuitMessage(0);
                        break;
                  case WM_COMMAND:
                        Menu_Call(hwnd, wParam, lParam);
                        break;
                  case MYWM_NOTIFYICON:
                        Icon_Message(hwnd, wParam, lParam);
                        break;
                  default:
                  
                        /* Let Windows 95 process any messages not specified in
                              the preceding switch statement. */
                        return DefWindowProc(hwnd, message, wParam, lParam);
            }
      }
      else if(wndStatus == hwnd)
      {
//            MessageBox(hwnd, "wndStatus", "GOT IT", MB_OK);
            
            switch(message)
            {
                  case WM_DESTROY: /* terminate the program */
                  case WM_CLOSE: /* terminate the program */
                        ShowWindow(wndStatus, SW_HIDE);
                        break;
                  default:
                        /* Let Windows 95 process any messages not specified in
                              the preceding switch statement. */
                        return DefWindowProc(hwnd, message, wParam, lParam);
            }
            
      }
      else
            switch(message)
            {
                  default:
                        /* Let Windows 95 process any messages not specified in
                              the preceding switch statement. */
                        return DefWindowProc(hwnd, message, wParam, lParam);
            }
      return 0;
}
 
void Menu_Call(HWND hwnd, WPARAM wParam, LPARAM lParam)
{

      HWND control;
      control = (HWND) lParam;
      switch(LOWORD(wParam))
      {
            case MENU_ShowStatus:
                  ShowStatus();
            
                  break;
            case MENU_StopStart:
                  MessageBox(hwnd, "StopStart", "GOT IT", MB_OK);
                  break;
            case MENU_Exit:
                  PostQuitMessage(0);
                  //MessageBox(hwnd, "Exit", "GOT IT", MB_OK);
                  break;
            case MENU_About:
                  MessageBox(wndMain, "BAOL\n**********************************************\n!!!! INTERNAL DISTRIBUTION ONLY !!!!\n**********************************************\n\nCan cause serious damage to computer and its parts\n\nI WARNED YA!!!\n\n-------------------------------------------------------\nBAOL Copyright ? 1997 Vladimir Berezniker", "ABOUT ...", MB_OK | MB_ICONINFORMATION);
                  break;
            default:
                  MessageBox(hwnd, "Something unknown", "GOT IT", MB_OK);
                  break;
      }
}

void Icon_Message(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    UINT uID;
    UINT uMouseMsg;
      POINT MouseCoords;
       static BOOL MouseDown=FALSE;
      BOOL track_ret;
    uID = (UINT) wParam;
    uMouseMsg = (UINT) lParam;
//      static BOOL aval = TRUE;
 
//      if (!aval)
//            return;

      switch(uMouseMsg)
      {
      case WM_RBUTTONDOWN:
      //      MessageBox(hwnd, "RIGHT BUTTON CLICK", "MOUSE", MB_OK);
            MouseDown = TRUE;
            break;
      case WM_RBUTTONUP:
            if (MouseDown)
            {
                  MouseDown =FALSE;
                  if(GetCursorPos(&MouseCoords))
                  {

                        SetForegroundWindow(hwnd);
                        track_ret = TrackPopupMenu(GetSubMenu(our_menu,0), TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, MouseCoords.x-1, MouseCoords.y,0,hwnd, NULL);
                        PostMessage(hwnd, WM_USER, 0, 0);

                        if(!track_ret)
                              MessageBox(hwnd, "ERROR POPING UP", "MOUSE", MB_OK);
                  }      
            }
            break;
      case WM_LBUTTONDBLCLK:
//            aval = FALSE;
//            SetForegroundWindow(hwnd);
//            MessageBox(hwnd, "LEFT BUTTON DOUBLE CLICK", "MOUSE", MB_OK);
//            aval = TRUE;
            ShowStatus();
            break;
      }

    return;
 }

void ShowStatus()
{
      ShowWindow(wndStatus, SW_SHOWNORMAL);
      UpdateWindow(wndStatus);
}

BOOL LoadValues()
{
      return TRUE;
}

BOOL InitApp()
{
      BOOL ret_val = TRUE;
      /* Now that a window class has been registered, a window can be created. */
      wndMain = CreateWindow(
                  szWinName, /* name of window class */
                  "0", /* title*/
                  WS_OVERLAPPED | WS_SYSMENU | WS_DLGFRAME, /* window style - normal */
                  CW_USEDEFAULT, /* X coordinate - let Windows decide */
                  CW_USEDEFAULT, /* Y coordinate - let Windows decide */
                  window_width, /* width - let Windows decide */
                  window_height, /* height - let Windows decide */
                  HWND_DESKTOP, /* No parent window */
                  NULL, /* no menu */
                  prgThisInst, /* handle of this instance of the program */
                  NULL /* no additional arguments */
                  );

      wndStatus = CreateWindow(
                  szWinName, /* name of window class */
                  wndTitle, /* title*/
                  WS_OVERLAPPED | WS_SYSMENU | WS_DLGFRAME, /* window style - normal */
                  CW_USEDEFAULT, /* X coordinate - let Windows decide */
                  CW_USEDEFAULT, /* Y coordinate - let Windows decide */
                  window_width, /* width - let Windows decide */
                  window_height, /* height - let Windows decide */
                  HWND_DESKTOP, /* No parent window */
                  NULL, /* no menu */
                  prgThisInst, /* handle of this instance of the program */
                  NULL /* no additional arguments */
                  );


      wndStatusMsgs = CreateWindow(
                  "Edit",
                  "", /* title*/
            WS_CHILD | WS_VISIBLE | WS_BORDER
                  | ES_AUTOHSCROLL | ES_AUTOVSCROLL
                  | ES_LEFT | ES_MULTILINE | ES_READONLY
                  | WS_EX_CLIENTEDGE | DS_3DLOOK
                  | WS_VSCROLL,
                  0, /* X coordinate - let Windows decide */
                  0, /* Y coordinate - let Windows decide */
                  window_width-6, /* width - let Windows decide */
                  window_height-30, /* height - let Windows decide */
                  wndStatus, /* No parent window */
                  NULL, /* no menu */
                  prgThisInst, /* handle of this instance of the program */
                  NULL /* no additional arguments */
                  );
      /* Display the window. */
//      our_hwnd = hwnd;

      our_menu = LoadMenu(prgThisInst, "main_menu");
      ShowWindow(wndStatus, SW_HIDE);
      UpdateWindow(wndStatus);
      UpdateWindow(wndStatusMsgs);

      if(!LoadValues())
            return FALSE;

      if(!Is_AOL3())
      {
            MessageBox(wndMain, "Sorry, but AOL 3.0 is not loaded.\nPlease load it first and then try again.\nThank you.\nBAOL", prgTitle, MB_OK | MB_ICONERROR);
            ret_val = FALSE      ;
      }
      UpdateWindow(wndMain);


      return ret_val;
}

BOOL InitSysIcon()
{
      BOOL ret_val = TRUE;
      if (!MyTaskBarAddIcon(wndMain, MYuID, LoadIcon(prgThisInst, "icon_yellow"), IconLoadTip))
      {
            MessageBox(wndMain, "Unable to create icon!", "BAOL - ERROR", MB_OK | MB_ICONSTOP);
            ret_val=FALSE;
      }

// EXIT
      if (!ret_val)            // If not initialized clean up
      {
            MyTaskBarDeleteIcon(wndMain, MYuID);
      }

      return ret_val;
}
-end
0
 
vmpnCommented:
Here is the main function
---------start
#include <windows.h>
#include <stdlib.h>
#include "vaolrc.h"
#include "systray.h"
#include "???_proc.h"

void Menu_Call(HWND hwnd, WPARAM wParam, LPARAM lParam);
void Icon_Message(HWND hwnd, WPARAM wParam, LPARAM lParam);
void ShowStatus();
BOOL InitApp();
BOOL InitSysIcon();


LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);

char szWinName[] = "????????????????"; /* Name of windows class */

//HWND our_hwnd;
char *IconLoadTip="????? Loading ...";
char *wndTitle = "Log - ?????????";
char *prgTitle = "???????????";

const int window_height = 300;
const int window_width = 370;
const UINT MYuID = 1;

HMENU our_menu;

HWND wndStatus = 0, wndMain = 0;
HWND wndStatusMsgs = 0;
HINSTANCE prgThisInst;

double waiting_period = 20000;
char aol_path;

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
                              LPSTR lpszArgs, int nWinMode)
{
//      HWND hwnd;
      MSG       msg;
      WNDCLASS wc1;

      /* Define window class */
      wc1.hInstance = hThisInst; /* handle to this instance */
      wc1.lpszClassName = szWinName; /* window class name */
      wc1.lpfnWndProc = WindowFunc; /* window function */
      wc1.style = 0; /* default style */

      wc1.hIcon = LoadIcon(hThisInst, "icon_main"); /* icon style */
      wc1.hCursor = LoadCursor(NULL, IDC_ARROW); /* cursor style */
      wc1.lpszMenuName = NULL; /* no menu */

      wc1.cbClsExtra = 0; /* no extra */
      wc1.cbWndExtra = 0; /* information needed */

      /* Make the window background white. */
      wc1.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

      /* Register the window class. */
      if(!RegisterClass (&wc1)) return 0;

      prgThisInst = hThisInst;

      if(!InitApp())
            return 0;
      if(!InitSysIcon());
            return 0;

      /* Create the message loop */
      while(GetMessage(&msg, NULL, 0, 0))
      {
            TranslateMessage(&msg); /* allow use of keyboard */
            DispatchMessage(&msg); /* return control to Windows */
      }
      MyTaskBarDeleteIcon(wndMain, MYuID);
      return msg.wParam;
}

/* This function is called by Windows 95 and is passed
      messages from the message queue.
*/
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
            

      if (wndMain ==  hwnd)      
      {
            switch(message)
            {
                  case WM_DESTROY: /* terminate the program */
                        PostQuitMessage(0);
                        break;
                  case WM_COMMAND:
                        Menu_Call(hwnd, wParam, lParam);
                        break;
                  case MYWM_NOTIFYICON:
                        Icon_Message(hwnd, wParam, lParam);
                        break;
                  default:
                  
                        /* Let Windows 95 process any messages not specified in
                              the preceding switch statement. */
                        return DefWindowProc(hwnd, message, wParam, lParam);
            }
      }
      else if(wndStatus == hwnd)
      {
//            MessageBox(hwnd, "wndStatus", "GOT IT", MB_OK);
            
            switch(message)
            {
                  case WM_DESTROY: /* terminate the program */
                  case WM_CLOSE: /* terminate the program */
                        ShowWindow(wndStatus, SW_HIDE);
                        break;
                  default:
                        /* Let Windows 95 process any messages not specified in
                              the preceding switch statement. */
                        return DefWindowProc(hwnd, message, wParam, lParam);
            }
            
      }
      else
            switch(message)
            {
                  default:
                        /* Let Windows 95 process any messages not specified in
                              the preceding switch statement. */
                        return DefWindowProc(hwnd, message, wParam, lParam);
            }
      return 0;
}
 
void Menu_Call(HWND hwnd, WPARAM wParam, LPARAM lParam)
{

      HWND control;
      control = (HWND) lParam;
      switch(LOWORD(wParam))
      {
            case MENU_ShowStatus:
                  ShowStatus();
            
                  break;
            case MENU_StopStart:
                  MessageBox(hwnd, "StopStart", "GOT IT", MB_OK);
                  break;
            case MENU_Exit:
                  PostQuitMessage(0);
                  //MessageBox(hwnd, "Exit", "GOT IT", MB_OK);
                  break;
            case MENU_About:
                  MessageBox(wndMain, "?????\n**********************************************\n!!!! INTERNAL DISTRIBUTION ONLY !!!!\n**********************************************\n\nCan cause serious damage to computer and its parts\n\nI WARNED YA!!!\n\n-------------------------------------------------------\nBAOL Copyright ? 1997 Vladimir Berezniker", "ABOUT ...", MB_OK | MB_ICONINFORMATION);
                  break;
            default:
                  MessageBox(hwnd, "Something unknown", "GOT IT", MB_OK);
                  break;
      }
}

void Icon_Message(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    UINT uID;
    UINT uMouseMsg;
      POINT MouseCoords;
       static BOOL MouseDown=FALSE;
      BOOL track_ret;
    uID = (UINT) wParam;
    uMouseMsg = (UINT) lParam;
//      static BOOL aval = TRUE;
 
//      if (!aval)
//            return;

      switch(uMouseMsg)
      {
      case WM_RBUTTONDOWN:
      //      MessageBox(hwnd, "RIGHT BUTTON CLICK", "MOUSE", MB_OK);
            MouseDown = TRUE;
            break;
      case WM_RBUTTONUP:
            if (MouseDown)
            {
                  MouseDown =FALSE;
                  if(GetCursorPos(&MouseCoords))
                  {

                        SetForegroundWindow(hwnd);
                        track_ret = TrackPopupMenu(GetSubMenu(our_menu,0), TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, MouseCoords.x-1, MouseCoords.y,0,hwnd, NULL);
                        PostMessage(hwnd, WM_USER, 0, 0);

                        if(!track_ret)
                              MessageBox(hwnd, "ERROR POPING UP", "MOUSE", MB_OK);
                  }      
            }
            break;
      case WM_LBUTTONDBLCLK:
//            aval = FALSE;
//            SetForegroundWindow(hwnd);
//            MessageBox(hwnd, "LEFT BUTTON DOUBLE CLICK", "MOUSE", MB_OK);
//            aval = TRUE;
            ShowStatus();
            break;
      }

    return;
 }

void ShowStatus()
{
      ShowWindow(wndStatus, SW_SHOWNORMAL);
      UpdateWindow(wndStatus);
}

BOOL LoadValues()
{
      return TRUE;
}

BOOL InitApp()
{
      BOOL ret_val = TRUE;
      /* Now that a window class has been registered, a window can be created. */
      wndMain = CreateWindow(
                  szWinName, /* name of window class */
                  "0", /* title*/
                  WS_OVERLAPPED | WS_SYSMENU | WS_DLGFRAME, /* window style - normal */
                  CW_USEDEFAULT, /* X coordinate - let Windows decide */
                  CW_USEDEFAULT, /* Y coordinate - let Windows decide */
                  window_width, /* width - let Windows decide */
                  window_height, /* height - let Windows decide */
                  HWND_DESKTOP, /* No parent window */
                  NULL, /* no menu */
                  prgThisInst, /* handle of this instance of the program */
                  NULL /* no additional arguments */
                  );

      wndStatus = CreateWindow(
                  szWinName, /* name of window class */
                  wndTitle, /* title*/
                  WS_OVERLAPPED | WS_SYSMENU | WS_DLGFRAME, /* window style - normal */
                  CW_USEDEFAULT, /* X coordinate - let Windows decide */
                  CW_USEDEFAULT, /* Y coordinate - let Windows decide */
                  window_width, /* width - let Windows decide */
                  window_height, /* height - let Windows decide */
                  HWND_DESKTOP, /* No parent window */
                  NULL, /* no menu */
                  prgThisInst, /* handle of this instance of the program */
                  NULL /* no additional arguments */
                  );


      wndStatusMsgs = CreateWindow(
                  "Edit",
                  "", /* title*/
            WS_CHILD | WS_VISIBLE | WS_BORDER
                  | ES_AUTOHSCROLL | ES_AUTOVSCROLL
                  | ES_LEFT | ES_MULTILINE | ES_READONLY
                  | WS_EX_CLIENTEDGE | DS_3DLOOK
                  | WS_VSCROLL,
                  0, /* X coordinate - let Windows decide */
                  0, /* Y coordinate - let Windows decide */
                  window_width-6, /* width - let Windows decide */
                  window_height-30, /* height - let Windows decide */
                  wndStatus, /* No parent window */
                  NULL, /* no menu */
                  prgThisInst, /* handle of this instance of the program */
                  NULL /* no additional arguments */
                  );
      /* Display the window. */
//      our_hwnd = hwnd;

      our_menu = LoadMenu(prgThisInst, "main_menu");
      ShowWindow(wndStatus, SW_HIDE);
      UpdateWindow(wndStatus);
      UpdateWindow(wndStatusMsgs);

      if(!LoadValues())
            return FALSE;

      if(!Is_????())
      {
            MessageBox(wndMain, "Sorry, but something??? is not loaded.\nPlease load it first and then try again.\nThank you.\n????", prgTitle, MB_OK | MB_ICONERROR);
            ret_val = FALSE      ;
      }
      UpdateWindow(wndMain);


      return ret_val;
}

BOOL InitSysIcon()
{
      BOOL ret_val = TRUE;
      if (!MyTaskBarAddIcon(wndMain, MYuID, LoadIcon(prgThisInst, "icon_yellow"), IconLoadTip))
      {
            MessageBox(wndMain, "Unable to create icon!", "BAOL - ERROR", MB_OK | MB_ICONSTOP);
            ret_val=FALSE;
      }

// EXIT
      if (!ret_val)            // If not initialized clean up
      {
            MyTaskBarDeleteIcon(wndMain, MYuID);
      }

      return ret_val;
}
-end
0
 
stevenc317Author Commented:
thanks
0
 
vmpnCommented:
no problem
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now