|
|
I am self-taught in C++ and this is as deep as I've ever been in messaging.
I have a modeless parent dialog maintaining a typed ptr list of modeless child dialog pointers. The children are all of the same class and hold memory and file resources (sets of parts and subassembly populations). The parent modeless supervises set operations on the children: unary transforms such as rotations, and binary operations such as set intersection, etc. So the parent is usually holding a kind of focus on one or two of the child operands.
I have been several days now, learning different ways that the parent dialog can crash via a null position pointer in the collection class operations, or crash via a pointer to a deleted child. I'm not crying about it, I needed the knowlege, anyway.
At this point my code no longer crashes but I have to perform two mouse clicks to close an inactive child; first click activates and second click closes ("close" means user clicked the X-button in the menu bar). The activation click causes the parent to lose its hold on current operands. Here are my event captures:
int CPop::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
if(nHitTest != HTSYSMENU)
{
GetParent()->PostMessageW(WMU_POP_TO_POPMAN_CHILD_M_ACTIVE, (WPARAM)0, m_ptoken);
}
return MA_ACTIVATEANDEAT;
}
void CPop::OnSysCommand(UINT nID, LPARAM lParam)
{
if((0xfff0 & nID) == SC_CLOSE)
{
OnClose();
}
else
{
GetParent()->PostMessageW(WMU_POP_TO_POPMAN_CHILD_M_ACTIVE, (WPARAM)0, m_ptoken);
}
}
I saw a #define HTCLOSE in winuser but it is not listed in the docs for OnMouseActivate(). Of course I tried it but it is unreliable.
Child acivation causes the parent to lose "currency" of previously activated children, a real pia.
I would like to know a method for one-click closing an inactive child. Just point me to an article if there is one.
Tadeusz Westawic
Sum quid sum.
|
|
|
|
|
Hi all,
I am trying to open the (jpeg)image and store it into an array(matrix) format.
I am not getting how to start,can anyone please help me in doing this.
Thanks
Raj
|
|
|
|
|
hi,
Do you have any code already? If so, it would be useful to post the details of your decoder.
If you haven't decided on a decoder yet, using the CImage[^] class could be a good one to consider.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
another option, if you can use Gdi+, is to go for Bitmap & BitmapData classes.
|
|
|
|
|
It depends what you want to achieve. Also depends how your jpeg is represented to you, i.e. do you have a file handle, etc etc.
So you if you post some more details, it'll be easy for us to help.
--
Arman
|
|
|
|
|
Basically JPEG is compressed file format.
Hope this[^] will help you a bit.
Regards,
Paresh.
|
|
|
|
|
|
I want an MFC SDI application frame window with a custom title bar, and I am using this code:
http://www.microsoft.com/msj/0197/c/c0197.aspx
It sort of works. Unfortunately the custom title bar causes the buttons in the top right (minimize, maximize and close) to shrink in width, and hence the end result is a mess.
Has anyone come across this problem, or know of an alternative? Thanks.
modified on Thursday, January 6, 2011 5:19 AM
|
|
|
|
|
Is it just me or is there something wrong with that link you provided? It doesn't seem to point at where it suposedly does.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
>Nothing is free in the universe.<
modified on Thursday, January 6, 2011 5:44 AM
|
|
|
|
|
Not it's not just you. Thanks for pointing it out. I've fixed the link.
|
|
|
|
|
I have a menu File->Exit
I need to change the menu text at run time SO I used
CMenu::ModifyMenu() funtion to do that.
I am able to set the text for "Exit" but not for "File"
Becuse for "Exit" I know the ID, but "File" no ID is specified.
How can I chnage text of "File"?
|
|
|
|
|
You can modify menu items by ID or position; see here[^] for information on modify by position.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hi,
I have created a windows service in Visual C++ 2008, and i am able to start/stop the service, the problem i am facing is in the CreateProcess which i have written in OnStart method,
My OnStart method is,
virtual void OnStart(array<String^>^ args) override
{
STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
std::ofstream o("Hello.txt");
if(CreateProcess(L"C:\\windows\\notepad.exe",
L"C:\\windows\\test.txt",
0,
0,
TRUE,
CREATE_NO_WINDOW,
0,
0,
&siStartupInfo,
&piProcessInfo) == FALSE)
{
o << "FALSE\n" << std::endl;
}
else
{
o << "TRUE \n" << std::endl;
}
}
when i install and start the service, it starts successfully and the file Hello.txt is created and result of CreateProcess is written to file as "TRUE", but the notepad is not opened, Can you please help me in getting the notepad open when i start the service,
Thanks,
|
|
|
|
|
Member 2430817 wrote: virtual void OnStart(array<string^>^ args) override
That isn't C++. Please post your question in the C++/CLI forum[^].
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
You've specified the option "CREATE_NO_WINDOW". I'd start looking at that to see if you can change the behaviour.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Regarding CArray , is it "better" to store an actual object in the collection or a pointer to an object? For the former, I'd have:
typedef CArray<CGroupInfo, CGroupInfo &> m_arrGroupInfo; and for the latter, I'd have:
typedef CArray<CGroupInfo *, CGroupInfo *> m_arrGroupInfo; At first glance, they seem analogous except I would create the object (i.e., new ) in the second instance and CArray would internally do it in the first.
Thanks.
- DC
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
It depends on your needs, I believe the former makes a copy of the passed object (hence you may have a performance penalty) whilst, the latter one delegates to you the memory handling.
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
[My articles]
|
|
|
|
|
CPallini wrote: I believe the former makes a copy of the passed object...
Which the latter would too since I would be new ing the object (and assigning values to its members). Correct?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
The latter doesn't make copies. It takes bare pointers. Object allocation is an 'external affair'.
[update]
Maybe I haven't got your scenario: would you use them this way:
CArray <Point , Point &> m_arr;
m_arr.Add( CPoint(10,20));
..
CArray <Point *, Point *> m_arr;
m_arr.Add( new CPoint(10,20));
..
?
For this scenario I would go for option 1 (so that the CArray takes care of object cleanup).
[/update]
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
[My articles]
|
|
|
|
|
CPallini wrote: [update]
Maybe I haven't got your scenario: would you use them this way:
// option 1CArray <point ,="" point="" &=""> m_arr;m_arr.Add( CPoint(10,20));..
// option 2CArray <point *,="" point="" *=""> m_arr;m_arr.Add( new CPoint(10,20));..
?
I've used both. I just can't seem to see a difference, or benefit, of one over the other.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I'm not sure the first option would be as afficient as the second one: the compiler may naively construct a temporary object and then copy its content to the array item (i.e. another freshly allocated object). On the other hand, with the second approach you have to take care of memory clean up (and someone as already pointed out, you may incour in aliasing problems).
And, of course, Nemanja's observations hold true.
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
[My articles]
|
|
|
|
|
I wouldn't store raw pointers in a collection. As a general rule always keep some kind of object in there - either what you're trying to store or some reference like object. If you keep raw pointers in there you'll end up with exception safety and potential aliasing problems.
So the rule of thumb I use is: If you want to maintain a collection of objects of a single type then store them by value. If you want to maintain a collection of objects and access them polymorphically store something like std::shared_ptr or std::unique_ptr .
Cheers,
Ash
PS: One final point - using CArray is a bad idea - it breaks fairly often when using non-POD objects (it uses a really naive internal copy based on memcpy) and is really conservative when it has to grow.
|
|
|
|
|
Me think it depend on the object itself, not the collection.
If the object (class) can be copied with ease (performance issue) than it can be easier to just use the first option; if the object is complex, then it might be more optimal to use a pointers in the collection.
I personally use pointers (but with STL collections, not MFC collections).
I don't know if rvalue reference (VS2010 c++0x) can be used with CArray (this enable the "move" semantic that will "move" objects instead of copiyng them); but probably the MFC collection are being deprecated in the later VS releases in favor of STL (but that'nother whole story).
M.
Watched code never compiles.
|
|
|
|
|
"Better" really depends on your particular situation. If CGroupInfo is a polymorphic type you need to store pointers. If it is a small concrete type, prefer storing objects.
In any case, CArray is a bad idea. std::vector is a better alternative.
|
|
|
|