|
greghint wrote: I'm developing a win32 application in C++ using minGW and Notepad++ as my development environment. I'm at the point where I'd like to create an owner-drawn menu with icons for my app
you can easily create owner -draw menu in win32 no need of MFC. you need to modify the style of menu items to MF_OWNERDRAW, then handle WM_MEASUREITEM Notification and WM_DRAWITEM message. You can easily map MFC code (you have now) to Win32 code.
see this [ MingW The Old FAQ^] "Theoretically, if you own the MFC source code you could build MFC libraries for MinGW"
|
|
|
|
|
I've been using Microsoft's MSDN example[^] as a starting point for my menu. This has been a bit frustrating, since some of the code simply doesn't work: SetMenuItemInfo() fails in their example until you set the cbSize of the MENUITEMINFO structure, which is explained in a different MSDN article.
Rather than using the MYITEM structure they do, I have created a class for my menu objects. Since my menu is created dynamically, I don't populate the menu structure when receiving the WM_CREATE message as they do in the example, but I am backpacking a pointer to a class item onto the MENUITEMINFO structure when menu items are created, like so:
MenuItem * myItem = &item;
MENUITEMINFO mii;
mii.fMask = MIIM_FTYPE | MIIM_DATA;
mii.fType = MFT_OWNERDRAW;
mii.dwItemData = (ULONG_PTR) myItem;
mii.cbSize = sizeof(mii);
SetMenuItemInfo(menu, item.itemID, FALSE, &mii);
In my function to handle the WM_MEASUREITEM message, I can access all of the class data from the pointer contained in the itemData member of the LPMEASUREITEMSTRUCT:
MenuItem *myItem = (MenuItem *) lpmis->itemData;
HDC hdc = GetDC(hwnd);
HFONT hfntOld = (HFONT)SelectObject(hdc, myItem->itemFont);
Microsoft use this exact same strategy when handling the WM_DRAWITEM message: they access the application-specific info from the itemData member of LPDRAWITEMSTRUCT. My implementation is the exact same as the example:
MenuItem *myItem = (MenuItem *) lpdis->itemData;
...
ExtTextOut(lpdis->lpdis->hDC,
x,
y,
ETO_OPAQUE,
&lpdis->rcItem,
myItem->itemLabel,
myItem->itemLabelLen,
NULL)
Sadly this strategy doesn't seem to work: any attempt to access the class items results in a crash. Is there some other sort of initialization I need to do that is missing from the example to ensure the pointer is passed along to the LPDRAWITEMSTRUCT?
Thanks in advance for any help or suggestions.
~g
|
|
|
|
|
I'm using Visual C++ 6.0 MFC in SDI application
I have a dialog box that comes up when the mouse is clicked. I don't understand how to control where in the client window this dialog box is displayed. I tried using something called SetWindowPos() but I did not understand what the first paramenter of the function call should be. Here's the routine that gets called
void GetMyPopBoxInfo(CMPopUpBox dlgPopUpBox)
{
// this displays my pop up dialog box
// but how do I set the position where this box is displayed?
dlgPopUpBox.DoModal();
}
|
|
|
|
|
You can control the position from within CMPopUpBox::OnInitDialog() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Take a look to SetWindowPos () and code it where David Crow told you
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Hello World,
I have a simple class
class CData
{
public:
CData () {}
CData (CObj obj, unsigned short a) {m_obj = obj ; m_a = a ; }
private:
unsigned short m_a ;
CObj m_obj ;
};
and a list of this type of object
typedef CList < CData, CData& > CDataList ;
Something odd happens when
CObj Obj ;
unsigned short a = 10 ;
CDataList TheList ;
TheList.AddTail(CData(Obj, a)) ;
TheList has one more element, and the data in m_obj is perfect. However, the value in m_a is not correct! It gets a random value.
If I change the default constructor to
CData(unsigned short a = 5) { m_a = a ; }
and do the same thing TheList.AddTail(CData(Obj, a)) ; m_a equals 5 (that is, the default value in the default constructor) and not the value passed when constructing the object...
I've tried to reproduce this problem in a different project and I can't. I guess there is something wrong with one of the classes I've defined. Any idea??
|
|
|
|
|
Do you have a copy constructor and are you copying all the members inside of it as well?
1. I will develop myself to the maximum of my potential in all ways
2. I will look for the good in all people and make them feel worthwhile.
3. If I have nothing good to say about a person, I will say nothing.
4. I will always be as enthusiastic about the success of others as I am about my own.
5. I will always remain loyal to God, my country, family and my friends - Chuck Norris
Ernest Laurentin
|
|
|
|
|
piul wrote: However, the value in m_a is not correct! It gets a random value.
Where/how are you verifying this?
I tried your code, and the CData object in the list did indeed contain the value 10 for the m_a member variable.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am able to display a bitmap using bltblit() function.
Now i have a raw image buffer. I want to display this data to my window using the device context.
I have the current HDC.
should i have to create a bitmap from this raw buffer.
Please help me.
|
|
|
|
|
I guess it depends on the raw image buffer format.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
What is the solution for this problem?
|
|
|
|
|
As I've already pointed out, knowledge of the raw image data format maybe a good start.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I am not getting your point.I have a 800 x 600 x 4 RGBA raw image buffer.
I want to display this on current HDC.
My question is should i have to create a bitmap for this buffer and then should i use bltblit () function.
Curently i am able to display a bitmap on current HDC.
Please elaborate your idea in little details.
Thanks,
Soumyadipta De
|
|
|
|
|
Soumyadipta wrote: My question is should i have to create a bitmap for this buffer and then should i use bltblit () function.
Yes.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Is there is any other alternative other than creating a bitmap?
Thanks,
Soumyadipta De
|
|
|
|
|
IMHO nope. But there are a lot of tutorials about.
Have a look at GDI articles here at CP .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks for you help.But i am not understanding one thing that, if it's not possible to do this in any other way then what you are suggesting to find me in the GDI tutorials?
Thanks,
Soumyadipta De
|
|
|
|
|
How to build a bitmap.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Is there any freeware tool to find out only GDI leaks in a project.
Can anyone tell me the occurances of GDI leaks.
modified on Tuesday, May 20, 2008 1:30 PM
|
|
|
|
|
Well you can use of Task Manager it displays GDI resources for each process.
|
|
|
|
|
|
Using Visual C++ 6.0 MFC in SDI application
I'm relatively new to C++ (from C). In an application using Visual C++ MFC, I setup a menu item. When that menu item is selected, my code calls the following routine that was setup by Visual C++
CMainFrame::ShowTheCircle()
{
// has my code here...
}
I want to perform this identical operation from another place in my code, which is in a separate .cpp file. I don't understand how to call the ShowTheCircle function from this other place.
void MyCode(void)
{
// call the ShowTheCircle function just as if the menu item was
// selected
// thanks for your help!
}
|
|
|
|
|
One way would be to make ShowTheCircle() a static method. Another would be to make it not part of the CMainFrame class.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
void MyCode(void)
{
CMainFrame *pWndMainFrame = dynamic_cast<CMainFrame *>(AfxGetMainWnd());
pWndMainFrame->ShowTheCircle();
}
provided CMainFrame is the class for the main frame window of the application.
|
|
|
|
|
ShowTheCircle is a method of CMainFrame class, therefore to call it you must have a reference (or a pointer) to a CMainFrame object, for instance
CMainFrame * pMainFrame = (CMainFrame *) AfxGetMainWindow();
CMainFrame * pMainFrame = (CMainFrame *) AfxGetMainWnd();
pMainFrame->ShowTheCircle();
Note that ShowTheCircle must also be declared public .
BTW what about a good C++ tutorial?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
modified on Tuesday, May 20, 2008 2:58 PM
|
|
|
|