August 18, 2019, 03:50:53 pm

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Onmenupick problem

Started by ExMember001, December 13, 2007, 08:15:53 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ExMember001

Hi,
i have a problem with my menu...
the contextmenu show itself but the menu item doesnt do as expected...
its been 2 days i try to find out... with no result...

when you open the program you see a window... if you right click on it the menu show
normally when you click on close a message box should open ... but nothing happen...

anyone can help me please.

heres the main src file:

Code Select

//////////////////////////////////////////////////////////////
//  MyGUI v2.0
//  Copyright, 2007, Martin Laflamme, all rights reserved
//////////////////////////////////////////////////////////////
//  MyGUI Class implementation
//////////////////////////////////////////////////////////////

#include "WinAPI.inc"
#include "MyGUI.inc"
//////////////////////////////////////////////////////////////

//Constructor
MyGUI::MyGUI()
{
Title = "MyGUI vX.X";
}

//Start the application
MyGUI::StartMyGUI()
{
//Create our window
Create(0,0,160,160,AWS_SYSMENU|AWS_CENTERED|AWS_SIZE,AWS_EX_TOPMOST,Title,0);
ModifyStyle(0,AWS_CAPTION); //remove caption
RedrawFrame();

//Load the BackGround Image
string filename = GETSTARTPATH() + "Images" + "\\" + "DEFAULT.jpg";
BackGroundImage.LoadFromFile(filename);
ShowBackGroundImage();

//Load the window caption icon
MainIco.LoadFromFile(getstartpath()+"images\\mygui.ico");
//keep the icon handle into HSysIcon
HSysIcon = MainIco.Detach();
seticon(HSysIcon);
   
SetSystrayIcon();

ShowWindow(SWSHOW);
return;
}

//Display the background image
MyGUI::ShowBackGroundImage()
{
RECT size;
    size = GetClientRect();
    BackGroundImage.Render(this,0,0,size.right-size.left,size.bottom-size.top);
return;
}

//window receive close message
MyGUI::OnClose(),int
{
Shell_NotifyIconA(NIM_DELETE, nid);
    Destroy();
return false;
}

//Window get redraw
MyGUI::OnPaint(),INT
{
ShowBackGroundImage();
return true;
}

//Window get resized
MyGUI::OnSize(int  nType, int  cx, int  cy),int
{
ShowBackGroundImage();
return true;
}

//Right mouse button event
MyGUI::OnRButtonUp(int  x, int  y, int  flags),int
{
CreateDropMenu();
ShowContextMenu(DropMenu.m_hMenu,x,y);
return true;
}

//Create the drop box context menu
MyGUI::CreateDropMenu()
{
    DropMenu.BeginContextMenu();
DropMenu.MenuItem("Close",0,10);
DropMenu.EndMenu();
return;
}

//Menu item selected
MyGUI::OnMenuPick(INT nID),INT
{
Select nID
    {
//close
case 10:
    messagebox(this,"yeepee!","");
    //OnClose();
}
return true;
}

//Left mouse button press down
MyGUI::OnLButtonDown(int  x, int  y, int  flags),int
{
RECT rc;
rc = GetClientRect();
if (y>rc.top) & (y<rc.bottom)
{
    if (x>rc.left) & (x<rc.right)
    {
//fool the window and set full surface titlebar
            SENDMESSAGE(this->m_hwnd,0xA1,2,0);
}
}
return true;
}

//Window Procedure method
MyGUI::WndProc(unsigned int  message, unsigned int  wparam, unsigned int  lparam),int
{
select message
{
//Track Window size
case WM_GETMINMAXINFO:
    MINMAXINFO MinMax;
//Retrieve default MinMax settings
RtlMoveMemory(&MinMax, lParam, Len(MinMax));

//Specify new minimum size for window
            MinMax.ptMinTrackSize.x = 160;
            MinMax.ptMinTrackSize.y = 160;

//Copy local structure back
            RtlMoveMemory(lParam, &MinMax, Len(MinMax));
}
return CWindow!!WndProc(message,wParam,lParam);
}

//Add application icon to systray
MyGUI::SetSystrayIcon()
{
nid.cbSize = Len(nid);
    nid.hwnd = this->m_hwnd;
    nid.uId = Null;
    nid.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE;
    nid.uCallBackMessage = WM_MOUSEMOVE;
    nid.hIcon = HSysIcon;  // use icon handle
nid.szTip = Title;

    Shell_NotifyIconA(NIM_ADD, nid);
return;
}


//////////////////////////////////////////////////////////////
// Main program function
Global sub main()
{
MyGUI mg;
mg.StartMyGUI();
do {wait(); }until !mg.IsValid();
return;
}



and a compilable version in attachment if needed.

Ionic Wind Support Team

Took me about 12 seconds ;)

This is why I stress using m_ when defining class variables.   When in a subroutine a class member variable takes precedence over a local variable.  You have a class member variables named 'nid'

Here are the corrected files.

Code Select

//////////////////////////////////////////////////////////////
//  MyGUI v2.0
//  Copyright, 2007, Martin Laflamme, all rights reserved
//////////////////////////////////////////////////////////////
//  MyGUI Class implementation
//////////////////////////////////////////////////////////////

#include "WinAPI.inc"
#include "MyGUI.inc"
//////////////////////////////////////////////////////////////

//Constructor
MyGUI::MyGUI()
{
Title = "MyGUI vX.X";
}

//Start the application
MyGUI::StartMyGUI()
{
//Create our window
Create(0,0,160,160,AWS_SYSMENU|AWS_CENTERED|AWS_SIZE,AWS_EX_TOPMOST,Title,0);
ModifyStyle(0,AWS_CAPTION); //remove caption
RedrawFrame();

//Load the BackGround Image
string filename = GETSTARTPATH() + "Images" + "\\" + "DEFAULT.jpg";
BackGroundImage.LoadFromFile(filename);
ShowBackGroundImage();

//Load the window caption icon
MainIco.LoadFromFile(getstartpath()+"images\\mygui.ico");
//keep the icon handle into HSysIcon
HSysIcon = MainIco.Detach();
seticon(HSysIcon);
   
SetSystrayIcon();
CreateDropMenu();

ShowWindow(SWSHOW);
return;
}

//Display the background image
MyGUI::ShowBackGroundImage()
{
RECT size;
    size = GetClientRect();
    BackGroundImage.Render(this,0,0,size.right-size.left,size.bottom-size.top);
return;
}

//window receive close message
MyGUI::OnClose(),int
{
Shell_NotifyIconA(NIM_DELETE, m_nid);
    Destroy();
return false;
}

//Window get redraw
MyGUI::OnPaint(),INT
{
ShowBackGroundImage();
return true;
}

//Window get resized
MyGUI::OnSize(int  nType, int  cx, int  cy),int
{
ShowBackGroundImage();
return true;
}

//Right mouse button event
MyGUI::OnRButtonUp(int  x, int  y, int  flags),int
{
ShowContextMenu(DropMenu.m_hMenu,x,y);
return true;
}

//Create the drop box context menu
MyGUI::CreateDropMenu()
{
    DropMenu.BeginContextMenu();
DropMenu.MenuItem("Close",0,10);
DropMenu.EndMenu();
return;
}

//Menu item selected
MyGUI::OnMenuPick(INT nID),INT
{
Select nID
    {
case 10:
    messagebox(this,"yeepee!","");
}
return true;
}

//Left mouse button press down
MyGUI::OnLButtonDown(int  x, int  y, int  flags),int
{
RECT rc;
rc = GetClientRect();
if (y>rc.top) & (y<rc.bottom)
{
    if (x>rc.left) & (x<rc.right)
    {
//fool the window and set full surface titlebar
            SENDMESSAGE(this->m_hwnd,0xA1,2,0);
}
}
return true;
}

//Window Procedure method
MyGUI::WndProc(unsigned int  message, unsigned int  wparam, unsigned int  lparam),int
{
select message
{
//Track Window size
case WM_GETMINMAXINFO:
    MINMAXINFO MinMax;
//Retrieve default MinMax settings
RtlMoveMemory(&MinMax, lParam, Len(MinMax));

//Specify new minimum size for window
            MinMax.ptMinTrackSize.x = 160;
            MinMax.ptMinTrackSize.y = 160;

//Copy local structure back
            RtlMoveMemory(lParam, &MinMax, Len(MinMax));
}
return CWindow!!WndProc(message,wParam,lParam);
}

//Add application icon to systray
MyGUI::SetSystrayIcon()
{
m_nid.cbSize = Len(m_nid);
    m_nid.hwnd = this->m_hwnd;
    m_nid.uId = Null;
    m_nid.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE;
    m_nid.uCallBackMessage = WM_MOUSEMOVE;
    m_nid.hIcon = HSysIcon;  // use icon handle
m_nid.szTip = Title;

    Shell_NotifyIconA(NIM_ADD, m_nid);
return;
}


//////////////////////////////////////////////////////////////
// Main program function
Global sub main()
{
MyGUI mg;
mg.StartMyGUI();
do {wait(); }until !mg.IsValid();
return;
}


Code Select

//////////////////////////////////////////////////////////////
//  MyGUI v2.0
//  Copyright, 2007, Martin Laflamme, all rights reserved
//////////////////////////////////////////////////////////////
//  MyGUI Class Definition
//////////////////////////////////////////////////////////////

class MyGUI:CWINDOW
{
declare virtual OnClose(),int;
declare virtual OnPaint(),INT;
declare virtual OnSize(int  nType, int  cx, int  cy),int;
declare virtual OnRButtonUp(int  x, int  y, int  flags),int;
declare virtual OnLButtonDown(int  x, int  y, int  flags),int;
declare virtual WndProc(unsigned int  message, unsigned int  wparam, unsigned int  lparam),int;
declare virtual OnMenuPick(INT nID),INT;

declare MyGUI();
declare StartMyGUI();
declare ShowBackGroundImage();
declare CreateDropMenu();
declare SetSystrayIcon();

CImage BackGroundImage;
CMenu  DropMenu;
CIcon  MainIco;

NOTIFYICONDATA m_nid;

String Title;
INT HSysIcon;
}
Ionic Wind Support Team

ExMember001

 :D
thanks Paul ! 
seems like i need to clean my glasses a bit  ;D