|
Hi all,
I am very sorry, I am beginner with Visual C++
but I have this problem :
I creating some application and I need send message about
kyepress to another application. My code is :
CWnd* poWnd = FindWindow(NULL, "Name of Window"); // I know name from SPY++
if (poWnd != NULL)
poWnd->SendMessage(WM_KEYDOWN,VK_TAB,1);
But this code do not work. What I must do ???
Thank you for all helps
Libor Matejka
|
|
|
|
|
It's probably working, but the target window (the mainframe) may not be the correct destination. You probably want to send the message to a child of the mainframe, perhaps a dialog or edit control?
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
|
Hi,
I'm looking for help writing a utility that searches through all the files in a directory looking for a string. I'd like something as fast an efficient as the Search Assistant provided with Windows. For example, it searches through a 40Mb file for my 9 digit string in about 2 seconds.
Is opening each file in the directory with CreateFile() and then searching through the file the only way or is there something more efficient?
Cheers
Steevie
|
|
|
|
|
This is what I use. Other than strlower it should work as is.
template <class InIt, class FwIt>
bool search_input(InIt begin, InIt end, FwIt find1, FwIt find2)
{
FwIt findstart(find1);
while (begin != end)
{
if (tolower(*begin) == tolower(*find1))
{
while (find1 != find2 && begin != end && tolower(*begin) == tolower(*find1))
{
++find1;
++begin;
}
if (find1 == find2)
{
return true;
}
find1 = findstart;
continue;
}
++begin;
}
return false;
}
bool FindInFile(const char* file, std::string str)
{
std::ifstream In(file, std::ios::in|std::ios::binary);
if (!In)
{
return false;
}
std::string s = str::strlower(std::string(str));
while (search_input(std::istreambuf_iterator<char>(In),
std::istreambuf_iterator<char>(), s.begin(), s.end()))
{
return true;
}
return false;
}
Todd Smith
CPUA 0x007 ... shaken not stirred
|
|
|
|
|
There's also other way - you can use memory-mapped files. Check the docs for CreateFileMapping and MapViewOfFile[Ex].
Have no idea if mapped files will be faster or slower than CreateFile/ReadFile combination. You'll have to measure the performance.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I looking for a way to launch VBScript Macro (VS6 editor environment) from external application or from other Macro
(I know about 3 ways to launch Macro: Shortcut key, ToolBar button, or command line)
Thanks in advance
Didi Gurfinkel
|
|
|
|
|
Hi,
Suppose you have the following scenario:
Log(CString & szMessage);
Log(); // this one reads its message of a member variable
And you need to add time to the messages before logging them. You essentially have two options:
AddTimeToLog(szMessage)
{
AddTime(szMessage);
}
AddTimeToLog()
{
AddTime(m_szMessage);
}
AddTime()
{
//perform the time addition
}
2nd option...
you can also use an if/else style and only use one single function as opposed to 3 functions and get it done...
I was wondering, which one would be considered efficient and at the same time better programming? Would cluttering your class with multiple functions be considered better than creating a code full of if/else conditions.
thanks
|
|
|
|
|
IMO use inline functions.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Or add optional arguments to your functions:
BOOL Log(CString &szMessage, BOOL bAddTime = FALSE);
which you can call like this:-
CString mystring=" no!!!! not another memory leak!";
Log ( mystring);
Log ( mystring, TRUE);
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Hi all,
Anyone want to give me some tips on the STL iterator?
I'm trying to implement a binary search on a list. here's a little snippet of code:
typedef struct _key_data{
KEY k;
DATA d;
} key_data;
typedef list<key_data>::iterator KLiterator;
KLiterator m_it_begin;
...
...
...
CKeyList::Search( KEY key )
{
KLiterator temp_it;
int sub_size;
...
...
...
temp_it = m_it_begin + sub_size;
...
...
...
the problem is with my iterator's + operator. When i try and compile I get this error msg:
error C2678: binary '+' : no operator defined which takes a left-hand operand of type 'class std::list<struct CKeyList<double,unsigned int>::_key_data,class std::allocator<struct CKeyList<double,unsigned int>::_k
ey_data> >::iterator' (or there is no acceptable conversion)
now I expect this will turn out to be a really dumb mistake, but I can't figure out why it's not working
Can anyone spot what's wrong?
TIA,
pete
|
|
|
|
|
You're using list. A binary search on list is going to be VERY expensive, as list has only bi-directional iterators. They define operator ++, but not operator +, because you need to step through the elements one at a time, you can't do an arbitrary jump. You need random access iterators for that ( as in vector ).
For the most efficient search on list, use the member function provided.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Doh!
Random access on a linked list? What was I thinking?
Thanks for pointing that one out.
Christian Graus wrote:
For the most efficient search on list, use the member function provided
do you mean list::sort()? I couldn't find a search function in my documentation.
Does anyone have a clue on how efficient the sort algorithm is. I'm guessing it'll be slower than a qsort() on an array, right?
Pete
|
|
|
|
|
|
The error is descriptive enough: You cannot shift a list iterators by adding some integer. Instead, you should do something like
temp_it=m_it_begin;
(for size_t n=0;n<subsize)temp_it++ But this is an indication of a flaw in your design. Please keep on reading.
Why list iterators cannot be added an integer? lists as implemented by STL1 are not suitable for random access (that is, going to somewhere inside the list from a position index). As list nodes are typically connected to the previous and subsequent nodes by means of internal pointers, the only way to get to the n-th element is by transversing the entire list from the beginning. This is an expensive (in computational terms) operation and should be avoided whenever possible. Because of this, designers of STL decided to ban operator + on these iterators to remind the programmer about this issue. If you want random access, use vector instead. As so often in life, there's a tradeoff involved here: vector s are random access, but insertions in the middle of a vector are way more expensive than for lists.
1 STL dos not mandate any particular implementation, but takes into account typical implementation tecnhiques as long as they affect the overall design of the components described.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for such a descriptive answer
Hmm, now i have to decide how I'm gonna improve the efficiency of my problem.
I've got a function which is generating double's. I eventually need to have these ordered. I initially just shoved them in an array, then qsort()ed it.
Then I tried sorting them as I inserted them into a list.
The two methods were pretty much equivelent in terms of speed.
Maybe I'll try hash-tables and buckets...
Can anyone a better way?
|
|
|
|
|
The structure of your data (pairs of key-value) might be an excellent candidate for std::map .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Looks like you're right.
I guess I'll use that rather than trying to reinvent the wheel. My wheel would probably be wobbly and fall off anyway
Thanks,
Pete
|
|
|
|
|
If, for some reason, you'll decide to stick with std::list, remember that there's std::list::sort method (which is different than generic std::sort from algorithm header).
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Does anyone have info on C++ object layout as implemented by VC++? Thanx.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Some info on this in Stanley Lipman's book "Inside C++ Object Model". For example, VC++ compiler inserts vptr at the first slot of an object, so *this dereferences it.
|
|
|
|
|
Thanx! Actually, I was looking for some info in the net I could consult for free. Anyway, maybe I can drop by some bookshop and take a look at that book.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I know what you mean, but I doubt that Microsoft would publish such information. Have a look trough the book (it is an excellent one), he compares different object model implementation done by Sun and Microsoft.
|
|
|
|
|
Hmm, here is a quick run down...
Like a structure, data inside a class is placed inside the class in the order it is defined using the current alignment. (99% sure...)
The virtual table is in the order that virtual functions are defined. (I think...)
The virtual table is a simple pointer to a table at the beginning of the class.
If a class is derived from another class, then any virtual functions defined in the derived class are added at the end of the vtable (I think, that is most logical). Overridden methods just replace the proper entry in the vtable.
All objects of the same class share the same vtable. However, a base class of a derived class might not share the same vtable as an instance of the base class when it is created directly (i.e. not derived).
HERE IS WHERE IT GET HAIRY...
When class is derived from 2 or more classes that contain virtual tables, then there actually exists multiple virtual tables in the object. Let us take an example where class C is derived from A and B in that order. At the head of object C is the vtable for all the virtual methods in A, B and C. At the start of B you have the vtable for B (which might contain overridden methods in C.)
Now the fun begins with the required thunking of the this pointer.
First, let us consider the case where the program has a pointer to object C and wants to invoke a method in B that isn't overridden by C. The calling routine would access the vtable at the start of C (which is the combo A, B and C vtable) and invoke that routine using C as the address. However, since the routine has NOT been overridden, the method in B would be receiving a pointer to C while expecting a pointer to B. So instead of having a pointer to the method in B in the combo vtable, you actually have a pointer to a thunk routine that adjusts the this pointer from C to B and then invokes the real routine.
In the opposite case, you have an object C which a program is referencing via a pointer to B. The program wishes to invoke a method in B which has been overridden by C. When the method is invoked, the vtables at the start of the B object inside of C is accessed (since all you have is a pointer to B, you are required to access its vtable). The method address retrieved from the vtable is actually the pointer to the overridden method in C. But, like in the previous case if we passed this, which is pointing to B to the routine expecting a pointer to C, the program would fail. Thus once again the vtable points to a thunk that adjusts the this pointer and then invokes the proper routine.
(I hope I got most of this right...)
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
The virtual table is in the order that virtual functions are defined. (I think...)
where the slot 0 contains run-time type class id, slot 1 contains pointer to the first virtual function, slot 2 contains pointer to the second virtual function etc.
|
|
|
|