|
MSDN says that when I receive a WM_LBUTTONUP or any other message concerning a mouse click, wParam should contain any keyboard modifiers and lParam the cursor position.
However, when I get these messages from a taskbar icon, wParam is always set to 1. Is it possible to modify the click to the icon with a keyboard modifier? And if so, is it possible for me to pick that up?
Cheers
Dave
|
|
|
|
|
Hi
I just recently learned about templates in C++, and I find it very useful and simple to use. I have one question though on a (possibly toy) problem.
Let's say I have the following declarations:
int maxint(int o1, int o2) {return (o1 > o2 ? o1 : o2);}
template <typename arg, typename T>arg Fun(arg i1, arg i2, T func)
{
return func(i1, i2);
}
and I invoke Fun in main() as follows:
cout << Fun(a, b, maxint) << endl;
where a and b are integers. This compiles and works without any error. But let's say I want to generalize maxint, and I create the following function template:
template <typename T>T maxi(T o1, T o2){return (o1 > o2 ? o1: o2);}
The linker always complains about unresolved external symbol "int __cdecl maxi(int,int)" when I tried to invoke maxi in main() with the following:
cout << Fun(a, b, maxi<int>) << endl;
Could anyone tell me what I did wrong, and how I can rectify it? Thanks!
|
|
|
|
|
Template functions do not exist unless they are called explicitly in your code. In your case, passing the address of a template function will compile because the function has been declared, but because it is not explicitly called anywhere, it is not defined, and is therefore unable to be found during linking. The solution is to call the function for int s at least once, or write a specialisation of the template function for int s:
template<> int maxi(int o1, int o2) { return (o1 > o2 ? o1 : o2); } Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Problem 1:
Your template functions aren't quite right (I didn't notice at first myself)
They should look like this
<br />
template <typename arg, typename T><br />
arg Fun(arg i1, arg i2, T func)<br />
{<br />
return func(i1, i2);<br />
}<br />
<br />
template <typename T><br />
T maxi(T o1, T o2)<br />
{<br />
return (o1 > o2 ? o1: o2);<br />
}<br />
Problem 2:
You can't use a function template as a function argument. That means the even with the correct definitions, it still won't work. Harrumph!
Solution:
Functors are like functions and classes all in one go - the STL uses them in the collection classes to order elements.
I re-wrote the functions like this...
#include <iostream>
using namespace std;
template <typename T>
struct Maxi
{
T operator () (T o1, T o2)
{
return (o1 > o2 ? o1: o2);
}
};
template <typename arg, typename Func = Maxi <arg> >
struct Fun
{
arg operator () (arg i1, arg i2)
{
Func func;
return func(i1, i2);
}
};
int main(int argc, _TCHAR* argv[])
{
int a (10), b (15);
Fun <int> fun;
cout << fun(a, b) << endl;
return 0;
}
Lo and behold, I get 15 as my output! Ask anything you're unclear about and I'll try and clarify
|
|
|
|
|
excuse me but
<font style="color:blue;">template </font><<font style="color:blue;">typename </font>T>T maxi(T o1, T o2){<font style="color:blue;">return </font>(o1 > o2 ? o1: o2);}
and
<font style="color:blue;">template </font><<font style="color:blue;">typename </font>T>
T maxi(T o1, T o2)
{
<font style="color:blue;">return </font>(o1 > o2 ? o1: o2);
} are the same !!! where do you see a difference ? the new line ? mwuaaahhahhh. whites spaces are ignored by the C/C++ compilers. didn't you know that ?
TOXCCT >>> GEII power
|
|
|
|
|
Yeah they're the same, when I did my original cut'n'paste though I thought I read
template T maxi(T o1, T o2){return (o1 > o2 ? o1: o2);}
I do apologise for any confusion there
Though since we're on templates, I feel I need to clarify your statement about white-space...
In a statement such as
std::map <std::string, std::vector<int> >
you really need that space between the >'s or the compiler thinks it's a shift-right operator
std::map <std::string, std::vector<int>>
|
|
|
|
|
in your classes, you must define the operator > for the test to be performed.
TOXCCT >>> GEII power
|
|
|
|
|
I have a ComboBox in which I am subclassing the list box (see my article Case-sensitive ComboBox[^]).
I now have a requirement to make some of the items bold. This is easily done by using an owner-drawn combo box. However, when I subclass the list of an owner-drawn combo, the list itself becomes owner drawn. This is a problem as it means that the list would need to know about which items to bold, but the information is in the combo box (apart from the fact that it just makes the architecture messy).
Has anyone come across this before? In a normal owner-drawn combo the drawing of the list items seems to be delegated to the combo, but I can't see a way of telling the subclassed list to do the same.
Any ideas would be appreciated!
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
OK, I've sussed it. So, for everyone out there who is dying to know what the solution is, here it is:
I have overridden OnChildNotify in my subclassed listbox (CListBoxCS ). I have then added the following code:
switch (message)
{
case WM_DRAWITEM:
case WM_MEASUREITEM:
case WM_COMPAREITEM:
case WM_DELETEITEM:
return FALSE;
}
return CListBox::OnChildNotify(message, wParam, lParam, pLResult);
This then causes all the drawing to be handled by the combobox rather than by the subclassed listbox.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
hi
normally GDI+ images are saved as RGB Color Format. But I want to save GDI+ bmp with CMYK Color.
If any one know it please help me.
|
|
|
|
|
Exactly what happens if I write:
char* arr = “Nisse”;
Can I run:
delete arr;
Or
delete [] arr;
What is the best thing to do?
...and justice for all
APe
|
|
|
|
|
The compiler allocates an area of code/data space with the string in it and sets *arr to point to it. Because its allocated by the compiler, it cannot be deleted (its not dynamic). You would get some kind of assertion error in debug and probably a crash in release.
Best thing to do.
Nothing.
Its not a leak.
Roger Allen - Sonork 100.10016
Strong Sad: I am sad I am flying
Who is your favorite Strong?
|
|
|
|
|
delete[] will call the right destructor for each cell member before destroying the tab itself. prefer it if you have to, but otherwise, it is destroyed automatically by the system at the end of its code block...
TOXCCT >>> GEII power
|
|
|
|
|
delete is for new
delete[] is for new[]
free is for malloc, calloc realloc
Nothing otherwise
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
|
loveablevirus wrote:
So your code,
char* arr = “Nisse”;
may work right at most times... but will make problem at some times.
The code is perfectly legal and will work at all times. "Nisse" will be allocated by the compiler in the global memory segment as a char[6] (null-terminated). arr is a stack variable which is pointing to this global memory. All is safe -- as long as you treat it as a char[6].
And since you have not allocated the memory (with new) you should not do a delete.
|
|
|
|
|
Whar are the other softwares/dependancies that are downloaded when I install Internet Explorer.
One of them will be JVM.
In order to which site can give me any information on this.
Kindly let meknow.
|
|
|
|
|
hi all
Is it possible to make a control which is inside dialog fullscreen ? Not whole dialog only selected control .
Bilge Kaan
|
|
|
|
|
No. The control will be clipped by the dialog. You can set it to whatever size you like, but only the part inside the dialog will be visible.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
HI
How can i make ComboBox readable only ...
no one can enter value in it.
thanx
|
|
|
|
|
by setting its type property to Drop List
TOXCCT >>> GEII power
|
|
|
|
|
Dear Fiends,
I got a child dialog box. Problem is that on pressing the enter key the dialog disappears. What i want is that on pressing the enter key, some button on the dialog gets pressed. How can i do so.
Imtiaz
|
|
|
|
|
override your OnOK and OnCancel of your Dialog. And comment out the
CDialog::OnOK() or CDialog::OnCancel()
Just check Michael Dunn FAQ article for detail.
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
Make the button Default from the prorpties of whhich u want the functionalty as a defualt on pressing first time ENter key..
may be it works..
|
|
|
|
|
Override OnOK() .
CMyDialog::OnOK()
{
PostMessage (WM_COMMAND, IDC_SOME_BUTTON);
} /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|