|
Usually these functions work well. Can you post the relevant code?
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.
|
|
|
|
|
I am writing a visual C++ Windows XP app for a computer that has 2 usb mice. When I receive a WM_MouseWhatever message I need to know which mouse it came from. This really has me stumped.
|
|
|
|
|
Something in my gut tells me this may not be possible with just the WM_ messages.
Perhaps if you could watch the usb port to see what goes in and out.
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
When you have two mice, Windows doesn't give you two mouse pointers. It merely moves the single mouse pointer in response to whichever mouse moved. Therefore it gives no way to tell which mouse was moved.
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
I needed to do something simular to handle multiple touchscreen monitors...
Have a look at Raw Input[^]...
Stormblade
|
|
|
|
|
I will take a look. In fact, I also am using two touch screen monitors, but I did not want to comlicate the question. As you know, the touch screen activity is reported as WM_MouseWhatever messages. So any additionl info you can give me to point me in the right direction would be great.
|
|
|
|
|
I am using the CFileDialog and need to know when the user deletes a file and the file he deleted. Using Visual C++ Enterprise Edition that came with Visual Studio 07.
|
|
|
|
|
You mean when you delete a file/folder from within the CFileDialog dialog ?
I don't know, but it's a good question, maybe there is an event that gets triggered that you could handle.
maybe have a look at OFN_ENABLEHOOK, OFN_EXPLORER, or OFNHookProc ?
|
|
|
|
|
For Windows 2000 Pro and above, maybe you could use FindFirstChangeNotification[^].
Note you'd have to use a separate thread to monitor changes with FindFirstChangeNotification().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all,
I have a class, for the purposes of this message 'class AClass'. The class requires a copy-constructor for the typical purposes. The following represents what I usually do:
class AClass<br />
{<br />
public:<br />
AClass();<br />
AClass(const AClass& copy_from);<br />
<br />
...<br />
};
In my implementation 'AClass' initiates a large amount of data whilst potentially undertaking a fairly complex procedure. The entire procedure can be optimised very easily when a non-constant version of the object is supplied:
class AClass<br />
{<br />
public:<br />
AClass();<br />
AClass(AClass& copy_from);<br />
<br />
...<br />
};
However, this leads to a different problem because the 'const' keyword is no longer used. There are places within my application which must parse such objects as 'const'. So the natural solution would seem the following:
class AClass<br />
{<br />
public:<br />
AClass();<br />
AClass(AClass& copy_from);<br />
AClass(const AClass& copy_from);<br />
<br />
...<br />
};
Sadly the above produces the following warning message:
'warning C4521: 'AClass' : multiple copy constructors specified'
I know there are workarounds which involve 'const_cast', but in my application the two copy constructors need to behave differently. Also, it isn't appropriate to use pointers and references to avoid this issue because it would cause serious maintenance issues and would be too confusing.
Any help or advice would be great.
Lea Hayes
|
|
|
|
|
Hi,
Just to expand a little further...when I execute the program the correct constructor is in fact called based upon const-ness. But what I need is confirmation that this is correct well-formed C++ and that it will compile correctly on other compilers. As this is only a warning (as opposed to an error) I just want to make sure that what I am attempting is not somehow dangerous or insecure.
If it isn't dangerous (or insecure) I will just use:
#pragma warning(disable: 4521)
Thanks again,
Lea Hayes
|
|
|
|
|
lhayes00 wrote: The entire procedure can be optimised very easily when a non-constant version of the object is supplied:
Could you elaborate on that point ? That seems a bit akward to me. Maybe that would be a better solution: be able to optimise the procedure on a const object (if at all possible).
|
|
|
|
|
Without knowing how the optomization works, I am limited. If the non-const copy constructor doesn't change the source in any significant way, you might be able to declare certain members mutable . If the copy constructor destroys the source object, you might want to implement it as a swap function. In either case, I can imagine special cases that would require alternative methods.
Nathan
|
|
|
|
|
Hi,
Thankyou very much....I didn't know about the 'mutable' keyword....I can see that being very useful.
|
|
|
|
|
I don't understand, are you wanting to modify the copy_from when copying it to a new AClass ?
the AClass(const AClass& copy_from); should be sufficient; the const applies to the parameter inside the method, not outside.
You could call the copy constructor with a const AClass or a non const AClass.
for example
void SomeClass::DoSomething( const AClass& c)
{
AClass newClass = c;
}
or
void SomeClass::DoSomethingElse( AClass& c)
{
AClass newClass = c;
}
|
|
|
|
|
Hi,
The non-constant version does make changes to the copy_from object. When an object of the type AClass is returned from a method, it can be flagged.
AClass BClass::DoSomething()<br />
{<br />
AClass myObject;<br />
...<br />
myObject.IndicateReturn();<br />
return myObject;<br />
}<br />
<br />
<br />
AClass::AClass(AClass& copy_from)<br />
{<br />
if(copy_from.IsReturnIndicated())<br />
Swap(copy_from);<br />
else<br />
Copy(copy_from);<br />
}<br />
<br />
AClass::AClass(const AClass& copy_from)<br />
{<br />
Copy(copy_from);<br />
}
|
|
|
|
|
lhayes00 wrote: When an object of the type AClass is returned from a method, it can be flagged.
I have no idea what you are doing but my best guess is you have some design flaws that are causing your copy constructor issue. To achieve an optimal solution you would have to fix those flaws first.
|
|
|
|
|
I don't know what you are trying to achieve, but even if you were to manage to have two different copy constructors now, I think you would be laying a maintenance minefield. Reading your code it is not easy to understand which version will be invoked and what happens. Seeing
AClass a(b)
gives no clue that b is modified. You, or others, may not recall this when maintaining the code.
If possible, implement the const copy constructor that uses a const object.
Think of a good descriptive name to call the non-const version, and do a two-step construction, if necessary creating a separate constructor to create an empty or invalid object, e.g.
AClass a;<br />
a.CopyFromAndModify(b);
If these are always created on the heap you could make a simple helper function to do the work
AClass* pA = CreateNewClassAndModify(b);
I'm sure there are other ways.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
How can be made empty the keyboard buffer in VC++6?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: How can be made empty the keyboard buffer in VC++6?
If it is a windows app, you can use PeekMessage to eat all the pending key press messages.
Nathan
|
|
|
|
|
Thanks a lot!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
(also posted on the dundas forum)
I'm using the Dundas grid to display a simple grid.
In one of the cell, I use the Ellipsis Cell type, it's a cell type with a "..." button to call up a dialog.
When I click on the "..." button my dialog is called, but it's not "modal", the grid still has focus and I can click the button again and again. seems the dialog message loop is overridden for at least one message, if I click on the dialog, the dialog really become modal.
This code is copied from the cell type Dundas sample. ( and I tried the same thing with the dundas demo to see if the problem is in my code )
int CMbJobInfoGrid::OnEllipsisButton(long ID,int col,long row,long msg,long param){
CUGCell cell;
GetCell(col,row,&cell);
int nCellTypeIndex = cell.GetCellType();
if(msg == UGCT_ELLIPSISBUTTONCLICK)
{
CMbEditCommentDialog dlg();
dlg.DoModal();
}
return TRUE;
}
It's a small problem, but it's bugging and I'm not certain why the DoModal does really eat the messages, and there's one message that get handled by the underlying grid.
Thanks.
Solution : There was SetCapture that was not supposed to be there. I removed it, tested all relevant code and behaviour and now everything is ok; no need to disable parent window or do other things, DoModal works as is should.
modified on Friday, December 07, 2007 3:51:44 PM
|
|
|
|
|
Modal dialogs in MFC are not really modal, and I believe that this allows for better message handling in the MFC framework. Modal dialogs just disable their parent to simulate a modal dialog.
You should be able to manually disable the dialog's parent to get around this problem.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
callback (p1, p2, p3, ....)
{
CView *pView = (CView *)p1
pView->whatever() causes ASSERT as defined in wincore.cpp - void CWnd::AssertValid()
}
MainApp{
CDocument::OnCommand - selected some operation from menu
CView *pView = get active view
call DLL (pView, p2, p3, ...)
}
DLL {
put up dialog
move slider, now need to update pView in main app
callback(pView, p2, p3 ...)
}
No matter if I pass a ptr to CDocument or CView the callback will fail (ASSERT) someplace
If I pass in the HWND and in the callback use CWnd::FromHandle() and then call InvalidateRect() I can get thinks to redraw but I want to access items in the Doc or View.
The ASSERT code states
// Note: if either of the above asserts fire and you are
// writing a multithreaded application, it is likely that
// you have passed a C++ object from one thread to another
// and have used that object in a way that was not intended.
// (only simple inline wrapper functions should be used)
//
// In general, CWnd objects should be passed by HWND from
// one thread to another. The receiving thread can wrap
// the HWND with a CWnd object by using CWnd::FromHandle.
//
// It is dangerous to pass C++ objects from one thread to
// another, unless the objects are designed to be used in
// such a manner.
So does anyone have a way around this?
Thanks in advance
Tony Teveris
Gerber Scientific Products
Senior Software Engineer
Phone: 860 648 8151
Fax: 860 648 8214
83 Gerber Road West
South Windsor, CT 06074
|
|
|
|
|
Tony Teveris wrote: So does anyone have a way around this?
Does anyone include Microsoft[^] ?
|
|
|
|