|
Find the handle of the window (FindWindow or EnumWindows work well), then send it a WM_CLOSE message.
If this causes it to ask to save data, and you don't want that, use DestroyWindow instead, although this is very brutal.
|
|
|
|
|
|
I am having a problem using the CEdit class and the CRgn class. I am using the CRgn to make a roundedrect and then setting the region to the CEdit control during PreSubClassWindow ( I am actually trying to make a class that is derived from CEdit that is a rounded edit control ). However it seems that the region is only having an effect on the border of the CEdit. The white part ( the part you type in ) is still a rectangle. Any Ideas why this is happening?
|
|
|
|
|
Friends,
I have a vector of pointers:
vector< PhoneRecord*> phonerecs(MAX);
I want to pass this vector to a function so I can add things to it outside of main().
The function declartion is:
void addPhoneRecord(PhoneRecord* records[]);
and call it from main() using something like:
addPhoneRecord(phonerecs);
The error I'm getting is:
error C2664: 'addPhoneRecord' : cannot convert parameter 1 from 'class std::vector<class PhoneRecord *,class std::allocator<class PhoneRecord *> >' to 'class PhoneRecord *[]'
I understand I'm not passing this correctly...
I'm sure this is a somewhat easy solution, but I can't seem to pinpoint it.
Thanks in advance!
|
|
|
|
|
|
Dave, thanks again for your quick and informative reply.
Allow me to include better code representation:
My function definition is:
void addPhoneRecord(string& name, string& address, string& phone, PhoneRecord* records[])<br />
{<br />
Name* nameEntry = new Name();<br />
nameEntry->set_name(name);<br />
Address* addressEntry = new Address();<br />
addressEntry->set_address(address);<br />
PhoneRecord* phoneEntry = new PhoneRecord(nameEntry, addressEntry);<br />
phoneEntry->set_phoneNumber(phone);<br />
<br />
records.push_back(phoneEntry);<br />
}
When I call it from main I'm using:
addPhoneRecord(name, address, phone, &phonerecs.back());
All of the setting functions and the like work like they should, and properly.
The error I'm getting is:
error C2228: left of '.push_back' must have class/struct/union type
If I comment out the records.push_back(phoneEntry); it compiles fine, but I get the standard WinXP error report problem.
Any suggestions?
Thanks again.
|
|
|
|
|
Since you are actually trying to use the vector as a vector (instead of just an array as you indicated in your previous message), you should pass a reference to the vector into the function. The last parameter should be: vector< PhoneRecord*>& records - then you will be able to use the push_back member.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Dave,
Thank you again. You're a master.
|
|
|
|
|
My program uses API calls and now that I have converted my program from a simple console app to a windows service, I cannot use all of the same API calls. If anybody is familiar with this type of problem, please fill me in with possible fixes. Thanks!
|
|
|
|
|
A little more information would be useful here...
What do you mean when you say that you cannot use all the same API calls? Is it not compiling? Or not running? If it isn't running, what error is produced? What APIs aren't working?
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
services start before a lot of the system has initialised and they have no logged on user generally
there is a bunch of info about what u can and cant do on ms
what exactly are u trying to do?
"there is no spoon" biz stuff about me
|
|
|
|
|
I need to use CWnd::FindWindow to find out if the game "Freelancer" is running. If I use NULL as the first parameter and "Freelancer" as the second, it also finds windows explorer windows that are in a "Freelancer" directory. Therefore, I need to also specify the classname in the first parameter. The problem is, how do I determine Freelancer's classname? I tried GetWindowInfo, but that returned an ATOM number that varies; not good!
|
|
|
|
|
Spy++ will tell you. It's the string after the string in quotes (which is the window title). For example, this window I'm typing into is called "The Code Project- Free Source Code and Tutorials - Microsoft Internet Explorer" and is of the class named "IEFrame".
Alternatively, try GetClassName .
|
|
|
|
|
Friends,
I'm trying to create a function so I can print the conents of a STL list from main(). It looks like:
<br />
void TraverseAndDisplay(list< PhoneRecord>::iterator& itor, const list< PhoneRecord>& l) <br />
{ <br />
while (itor != l.end()) <br />
{ <br />
cout << *itor++ << " "; <br />
} <br />
cout << endl; <br />
}
Unfortunately, because PhoneRecord is not a primitive data type (it's my own class), the default operator != won't work.
The exact error I'm getting is:
error C2679: binary '!=' : no operator defined which takes a right-hand operand of type 'class std::list<class PhoneRecord,class std::allocator<class PhoneRecord> >::const_iterator' (or there is no acceptable conversion)
Obviously I need to overload the != to work. I don't know how to overload the != operator to work for iterators in this case?
Thanks in advance for your help!
|
|
|
|
|
Can you please repost the code, using < and > for the angle brackets so that we can see the template parameters?
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Sorry about that. It's reposted. Ignore the space after the < and before PhoneRecord.. it was making it a smiley.
|
|
|
|
|
I suspect it is because you are comparing an iterator with a const_iterator. Since the list passed in as a parameter is constant, it will only return a const_iterator, so you could either make the list non-cost, or pass in a const_iterator instead of an iterator as the first parameter (the better option as you do not appear to be modifying the list here). Alternatively, you could pass in the end iterator as a parameter rather than passing in the entire list - this is the approach used by STL, as then the type of container can be changed without modifying the function itself.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Dave, thank you so much for your help!
|
|
|
|
|
I have a small program I'm getting my feet wet with in having different ASCII, Extended ASCII and hopefully Unicode characters in a message window. This is the code
int n;
CHAR cTempChar[2];
LPCTSTR lpAsciiString=""
WCHAR wTempWchar[2];
static wchar_t szTitle[] = L"Unicode Characters";
static WCHAR wzTitle[] = L"high Unicode Characters";
static wchar_t * wzUnicode = L"U";
lpAsciiString=cTempChar;
cTempChar[1]=0;
for(n=48;n<70;n++)
{
cTempChar[0]=(CHAR)n;
MessageBox(NULL, lpAsciiString, TEXT("ASCII Characters"), MB_OKCANCEL|ML_ICONHAND);
}
wzUnicode=wTempWchar;
wTempWchar[1]=0;
for(n=48;n<60;n++)
{
wTempWchar[0]=(WCHAR)n;
MessageBoxW(NULL, wzUnicode, wzTite, MB_YESNOCANCEL|MB_ICONQUESTION);
}
for(n=204;n<226;n++)
{
wTempWchar[0]=(WCHAR)n;
MessageBoxW(NULL, wzUnicode, wzTitle1, MB_ABORTRETRYIGNOR|MB_ICONEXCLAMATION);
}
This is a sample for class and I'm supposed to change things to show the new Unicode characters (sample of). How would I go about doing this?
I need much help in the class and I hope this is the right place to get it cause I'm about out of ideas forhelp.
|
|
|
|
|
I am new to C++ and was presented with this piece of code to try and figure out what it does. I was hoping that someone could tell me or give me some idea. Here is the code, for(c=a^b, cnt=0; c>0; cnt += c%2, c>>=1);
Thanks, Claytide
|
|
|
|
|
two variables are being set, c and cnt. I believe that ^ is exclusive or ( in other words, use only bits set in only one of the two numbers ), and % is definately remainder, so t will = 1 or 0, depending on if c is odd or even. I don't see how cnt t = c%2 works, is the second t a typo ? I presume so, and so if t = 1 and c is odd, or t = 0 and c is even, the loop ends.
>> is the shift operator, so if a right shift of the number results in a value of 1, the loop ends.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
It's been a couple of years since I've done C++ but here goes:
a^b : ^ is a bitwise Exclusive-OR operator, e.g. 1^1=0; 1^2=3; 2^2=0; 32^64=96; 32^96=64;
Bitwise Exclusive OR Operator: ^[^]
c%2 : % is a modulus operator
C Multiplicative Operators[^]
>>= is a right-shift assignment operator
Shift Operators: >> and <<[^]
for
C++ language reference: The for statement[^]
c is initialised to a XOR b
cnt is initialised to zero.
The iteration will continue to loop around so long as c is greater than zero. This test is done at the start of each iteration.
At the end of each iteration cycle cnt is set to the remainder of c divided by 2 (In other words cnt will be 1 if c is odd, or zero if c is even) and c is shifted one bit to the right (in other words divided by two)
Now, while I was writing this, it occurred to me that this is an interview style question. No one in their right mind would code this.
So, for a bonus, (assuming c is an unsigned int and the code inside the loop doesn't alter c), what is the maximum number of iterations possible?
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
|
|
|
|
|
It looks like you've mis-transcribed it a bit. That should be a 't', it should be a '+', giving:
for(c=a^b, cnt=0; c>0; cnt += c%2, c>>=1) ;
And that then clearly counts the number of bits that are different between 'a' and 'b'. *chuckles* Isn't that obvious?
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Is it possible to simulate mouse clicks?
|
|
|
|
|
Yes.
Just send (or post) WM_LBUTTONDBLCLK (and similar) messages to a target window. However, you need to deliver the messages to the right target window, which can be easier said than done. (Finding the window can be non-trivial).
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|