[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
Go Back  Xtreme Visual Basic Talk > > > [C/C++11 - win32] - how get the 'this' value?


Reply
 
Thread Tools Display Modes
  #1  
Old 11-21-2014, 01:51 PM
Cambalinho_83's Avatar
Cambalinho_83 Cambalinho_83 is offline
Senior Contributor
 
Join Date: Feb 2008
Location: somewhere in space
Posts: 1,293
Default [C/C++11 - win32] - how get the 'this' value?


i'm creating a class Menu. i can't subclass the menus, because i don't have the HWND, so i came with another ideia. when i create the menu item i send the 'this' to the MENUITEMINFO structure, using the dwItemData structure member.

Code:
//put the this on dwItemData
            MENUITEMINFO  s;
            GetMenuItemInfo (hMenu,intID, true, &s);
            s.cbSize=sizeof(MENUITEMINFO );
            s.fMask=MIIM_DATA;
            s.dwItemData=(ULONG_PTR)this;
            SetMenuItemInfo (hMenu,intID, true, &s);

            //change the menu for use the WM_MENUCOMMAND
            MENUINFO mnInfo;
            GetMenuInfo(hMenu,&mnInfo);
            mnInfo.cbSize=sizeof(MENUINFO);
            mnInfo.fMask=MIM_STYLE;
            mnInfo.dwStyle=MNS_NOTIFYBYPOS;
            SetMenuInfo(hMenu,&mnInfo);
the WM_MENUCOMMAND is called without a problem, but problem is when i try getting the 'this' value
Code:
case WM_MENUCOMMAND:
                {
                    BOOL fResult = FALSE;
                    MENUITEMINFO menuInfo = { 0 };

                    menuInfo.cbSize = sizeof(MENUITEMINFO);
                    menuInfo.fMask = MIIM_ID | MIIM_DATA;

                    fResult = GetMenuItemInfo((HMENU)lParam,(UINT) wParam, TRUE, &menuInfo );

                    if (fResult)
                    {
                        UINT myId = menuInfo.wID; // this is item ID
                        ULONG_PTR myData = menuInfo.dwItemData; // item data ('this' pointer')
                        Menu *mMenu = (Menu*)(((LPCREATESTRUCT)myData)->lpCreateParams);
                        mMenu->MenuClick() ;
                    }
                }
                break;
what i'm doing wrong for don't get the correct value?
(theres no error message. i execute it and the OS tells me that the program stops responding and then close it)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value? [C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
 
[C/C++11 - win32] - how get the 'this' value?
[C/C++11 - win32] - how get the 'this' value?
 
-->