|
Hi,
to check if a control key is pressed with the wished key,
you can test it this way :
if(GetKeyState(VK_CONTROL)<0 && pMsg->WPARAM == VK_DOWN) {
// CTRL + DOWN
}
I hope it helps
|
|
|
|
|
wow,
it works.
GetKeyState() is the function, which i wanted exactly.
thank you.
|
|
|
|
|
You check for VK_CONTROL in WM_KEYDOWN/WM_KEYUP and set an internal flag.
Depending on that state you can then react to VK_LEFT , VK_UP , VK_RIGHT and VK_DOWN .
A lot like this:
void CMyListBase::OnKeyDown(UINT nChar)
{
switch (nChar)
case VK_CONTROL:
if (true)
m_bControl = true;
else
m_pListCtrl->Default();
break;
case VK_LEFT:
if( m_bControl)
HandleLCTRLLeft();
break;
}
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
thanks for your reply.
your logic is also good and seems to work.
|
|
|
|
|
Hello,
does anyone have some expierience with stdext::hashmap with VS2005?
Is this container ready for use, is it sure for use?
I have some problems in my program with them, the find function does not find items in map
and i know that they are inside!
Thanks for Answers!
termal
|
|
|
|
|
For me, stdext::hashmap from VC.NET 2005 does work flawlessly.
Can you give some sort of a minimal testprogram showing your problems?
-- modified at 7:32 Monday 22nd October, 2007
Stupid typo fixed.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Hello,
thanks for answer, here is a sample code:
class CMyClass
{
CString csName;
CString csVName;
int iName;
}
typedef LPCTSTR MyString;
struct str_compare
{
bool operator()(const MyString& lpStr1, const MyString& lpStr2)
{
return wcscmp(lpStr1, lpStr2) == 0;
}
};
CMyClass myClass;
myClass.csName = L"John";
myClass.csVName = L"Do";
myClass.iAge = 20;
hash_map<MyString, CMyClass>myhashmap;
myhashmap.insert(L"John", myClass);
hash_map<MyString, CMyClass, hash_compare<MyString, str_compare>>::iterator testiterator;
testiterator = myhashmap.find(L"John");
if(myhashmap.end() != testiterator)
AfxMessageBox("Item found");
else
AfxMessageBox("Item not found");
To add items and iterate trough my hash_map is no problem, with iterate i mean if i use any loop
and print all items out!
I have to say that project is in unicode and multithreaded, that means that many threads
add items and read them from a hash_map!
So, each thread search in a hash_map to see if item is already inside, if not, add a new item,
if the item is already inside, update them content!
Thanks for your time!
Regards
termal
|
|
|
|
|
Your code does not even compile!
Anyway, are you positivly sure you want a hash_map here?
You do not have a good hash at hand, it seems. A normal map would be smarter, I think.
Anyway,
typedefs can help you sort the myriads of < and >.
str_compare should do what exactly? Define a strict ordering between the items given. Look how less<> works and define your comparer accordingly.
Here, I have used the standard less comparer.
And you are right, it doesn't work when mixing CString and LPCTSTR in insert and find . My version works if LPCTSTR or CString are used consistently.
#include "stdafx.h"
#include <hash_map>
#include "iostream"
#include "windows.h"
#include "atlstr.h"
class CMyClass
{
public:
CString csName;
CString csVName;
int iAge;
};
int _tmain(int argc, _TCHAR* argv[])
{
CMyClass instance1;
instance1.csVName = _T("John-Boy");
instance1.csName = _T("Walton");
instance1.iAge = 20;
CMyClass instance2;
instance2.csVName = _T("Jim-Bob");
instance2.csName = _T("Walton");
instance2.iAge = 16;
typedef stdext::hash_map<LPCTSTR, CMyClass, stdext::hash_compare<LPCTSTR, std::less<LPCTSTR> > > MyHashMapT;
typedef MyHashMapT::iterator MyHashMapIt;
MyHashMapT myhashmap;
std::pair<MyHashMapIt, bool> result = myhashmap.insert( MyHashMapT::value_type( _T("John-Boy"), instance1));
result = myhashmap.insert( MyHashMapT::value_type( _T("Jim-Bob"), instance2));
MyHashMapIt testiterator = myhashmap.find( _T("John-Boy"));
if( myhashmap.end() != testiterator)
std::wcout << _T("Item found") << std::endl;
else
std::wcout << _T("Item not found") << std::endl;
return system("pause");
}
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Hello,
thank you very much for your help, that helps me i hope to solve my problem!
Can you write this line again:
typedef stdext::hash_map > > MyHashMapT;
I can see that i isert items in other way as in your sample, maybe is that the problem:
My insert:
myhashmap.insert(L"John-Boy", instance2);
Your insert:
myhashmap.insert(MyHashMapT::value_type( _T("John-Boy"), instance1));
I dont use ::value_type, i try now with your codesample, and make typedefs!!
Regards
termal
|
|
|
|
|
The line you were missing:
typedef stdext::hash_map< LPCTSTR, CMyClass, stdext::hash_compare< LPCTSTR, std::less<LPCTSTR> > > MyHashMapT;
I hate how the pre-tag is not able to take its content literally!
The value_type should just be a std::pair made of key-type and value-type. It might actually be clearer to write:
std::pair<MyHashMapIt, bool> result = myhashmap.insert( std::pair< LPCTSTR, CMyClass>( _T("John-Boy"), instance1));
result = myhashmap.insert( std::pair< LPCTSTR, CMyClass>( _T("Jim-Bob"), instance2));
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Hello,
do you have a little sample from your work, how you use the hash_map,
i think im going crazy now with my map!
I can't find intems in my map!
What kind of datatype u use for a key?
I need any string type that is compatible with my hash_map and VS8 to set as key value!!
With best regards!
termal
|
|
|
|
|
I use int as a key.
Why do you desperately need a hash_map and not a normal std::map ?
For any practical purposes, the speed will not be too much different. If you worry about speed but do not get your work done you are doing premature optimization anyways.
You might need to come up with a hashing-function for your string and provide that to your hash_map. But I have never done that myself.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
I have developed a Tool . This tool basically check for latest release in the source location and automatically starts copying the release folder to destination. For copying i have used Robocopy software. I have written the code in Win32 console application C++. The problem is the robocopy software should be present in C drive ie (it is hard-coded in code).
How can i attach Robocopy exe to main appliation Exe , such that whenever you invoke the application exe , it will search whether robocopy exe is present at that place , if not it will copy the robocopy exe which is embedded in the Application exe to required location.
Is it possible? Do i need to convert from Win32 console application to MFC application?
Thanks,
Ashish
|
|
|
|
|
You can embedd an exe/dll within your application itself as a resource(i recommends MFC & Visual Studio IDE for speed up your development). and later on you can extract and use it. the only problem is total size of your application will grow.
Never Work Hard! - Work Smart!!!
|
|
|
|
|
Ash20 wrote: such that whenever you invoke the application exe , it will search whether robocopy exe is present at that place , if not it will copy the robocopy exe which is embedded in the Application exe to required location.
Add this exe as a resource to your main exe. Later on if exe is not found at the required place, dump it there.
Read this --> http://www.codeproject.com/cpp/UpdateResource.asp[^]
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http:\\nibuthomas.wordpress.com
|
|
|
|
|
If you have copied the robocopy exe to the user's hard drive, remember to remove it after your program is done its stuff so that the user's system is in the same state (except for what your program did) as before your program.
Also, better check the licensing for Robocopy. It may prohibit you from doing what you want to do.
Judy
|
|
|
|
|
Hello everyone,
I saw a couple of form of assert in code on Windows,
1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.
Which one is the most correct to use? I saw people always define this to that, and I want to find the root one which is defined by Windows.
I also saw people manually define assert to NULL if macro DEBUG or _DEBUG is not defined, is that necessary?
I feel assert is in a mess and I want to find a clear and unified way for this item.
thanks in advance,
George
|
|
|
|
|
Yes assert is a bit of a mess. One of the reasons for this is that it isn't defined by Windows. It is defined by the C Library but not in a particularly good, reusable or modifyable way. Hence every library writer tends to create their own so now we have several less than ideal assert macros and functions. In the end the choice comes down to: use the one that suits you best, none is really more or less correct, or do what every one else has done and write your own
The third way I suppose is to find another implementation you like and copy it. John Robbin's SuperAssert is certainly the most complete I've come across.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
|
The link doesn't work for me but that sounds OK. assert will be taking an int because it's in 'C' where bool doesn't exist. I would say if you're going to use the existing asserts then use the MFC version with MFC and the C Library version in plain Win32. There is certainly no need define _ASSERT and assert manually to NULL when !_DEBUG. They should already be #defin(ed) to disappear altogether in Release builds.
I understand the value of asserts but I don't personally use them. I know this is a controversial oppinion and not to be taken as advice but I think they're an incomplete or broken concept. One of these days I'm going to work out why they annoy me so much and replace them with something better.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Thanks for sharing your experience, Matthew!
regards,
George
|
|
|
|
|
Matthew Faithfull wrote: or do what every one else has done and write your own
Just what we need, another bloody assert macro!
Steve
|
|
|
|
|
George_George wrote: 1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.
Which one is the most correct to use?
I use #1 for MFC, and #2 for Win32. If you are curious what each resolves to, if anything, just place the mouse cursor on it and press F12.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks DavidCrow,
I think there is no need to manually define ASSERT and other forms of ASSERT to NULL when in release configuration, right?
regards,
George
|
|
|
|
|
George_George wrote: I think there is no need to manually define ASSERT and other forms of ASSERT to NULL when in release configuration, right?
I've never had the need to, but then again, I'm prejudice.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|