|
Using Visual C++ 6.0 MFC
I would like to setup a program where the user can use a menu item to display either of two views (say one view displays a square and if the other view is selected a circle is displayed). In addition I would like certain mouse events to cause the view to switch between these same two views. Say a left mouse click causes the square view to be displayed and a right mouse click causes the circle view to be displayed.
What is the best way to set something like this up? I can try to fill in the details, just looking for the best way to set things up initially.
|
|
|
|
|
|
I have an exception handling problem that I don't understand. My thread function is throwing an unhandled exception which is being caught by my catch(...) handler but not completely handled. This causes my thread to be prematurely terminated so that my cleanup logic is not executed. How can I change my handler so as to completely handle the exception and execute my cleanup logic? My code is below.
UINT CVarFileEvent::MultiFileProcessThread( LPVOID lpParam )
{
CVarFileEvent* pEvent = (CVarFileEvent*)lpParam;
TRACE( "> > > > Entering CVarFileEvent::MultiFileProcessThread()\n" );
HRESULT hRes = ::CoInitialize(NULL);
try
{
vector<cstring> vecVarFiles = UtilK::findAllFiles( "*.var",
pDataMovement->getInboxPath(),
false );
TRACE( "> > > > > Beginning processing of %d VAR files\n",
(int)vecVarFiles.size() );
CDataMovement* pDataMovement = pEvent->getDataMovementParent();
CFlightDataHandler FlightDataHandler( pDataMovement->getLogWriter() );
for( vector<cstring>::iterator iterFile = vecVarFiles.begin();
iterFile != vecVarFiles.end() && m_bIsThreadRunning;
iterFile++ )
{
FlightDataHandler.importVARFile( *iterFile );
::DeleteFile( *iterFile );
pDataMovement->deleteFileEvent( *iterFile );
}
}
catch(...)
{
CString strMsg( "importVARFile() failed with unexpected exception" );
TRACE( "> > > > CVarFileEvent::MultiFileProcessThread() exception < %s >\n", strMsg );
CLogWriter* pLogWriter = pDataMovement->getLogWriter();
pLogWriter->writeEntry( "CVarFileEvent", CLogWriter::LE_OPERATION_FAILED, strMsg );
}
::CoUninitialize();
pDataMovement->setInboxProcessEndEvent();
m_bIsThreadRunning = false;
return 1;
}</cstring></cstring>
Thanks
|
|
|
|
|
All the code in the exception handler should be able to execute outside the scope of the try block. One glaringly obvious potential you have is the use of pDataMovement pointer which is initialized in the try block. So if the exception is thrown before then or if the pointer is null your catch block will just throw another exception.
Wait, looking again I see that pointer used before it is even declared so I don't know how you get that to compile at all.
led mike
|
|
|
|
|
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. I've scoured the many examples on the site but all of them are for MSVS/VC++, and use many of the MFC components brought in from precompiled headers such as stdafx.h and afxtempl.h.
I'm hoping an experienced coder can make a recommendation for me. Is there a way for me to "import" these headers and components into my minGW dev env? I do have a copy of Visual Studio 8 installed. Is there some sort of front-end IDE for minGW that can emulate this? (I've read inklings that DevC++ can do this while googling.) Or am I better off trying to rebuild the classes and structures entirely myself?
Thanks in advance for the advice.
~g
|
|
|
|
|
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.
|
|
|
|