|
CreateProcess has a PROCESS_INFORMATION structure as the last parameter.
You can use the dwThreadId member of this structure and the WM_QUIT message to close a window using the PostThreadMessage API.
::PostThreadMessage(pi.dwThreadId, WM_QUIT, 0, 0);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi all,
I am working on VC2008, suppose i am woking on a project i opened it in vc2008 enviorment by double cliking on my .sln file. Now suppose i search for any variable or functions, it will provide me a result in find window i click on it and start modifying it now when i run my application the changes are not reflected... Now i come back in my editor and click on .cpp file and two files with same name are opened i.e two copies of same file is being made but when i come to folder where my files is being stored only one file exsist..... I am not getting how to resolve this....
Can anybody please help me with solution for this....
Thanks in advance
|
|
|
|
|
My MFC dialog based application has a combo box for the selection of languages.I want to change a static text on the selection of particular language.I have made resource DLLL for each language.
Can anyone tell me that how to link resource DLL with my MFC dialog based application and how to load strings from Resource DLL on selection of language from combo box..
Thanks in advance...
|
|
|
|
|
Look at the function CString::LoadString .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Is there any setting also to load the Resource DLL in MFC dialog based application?
|
|
|
|
|
What I am trying to do is create a base class that provides a basic interface and several child classes that implement the interface and extend it a little bit. I would then like to create a child class (at run time using pointers to the base class) whose type is determined by data in a table. So far so good.
In the code which has the pointer I am trying to call some of the functions that extend the interface depending on the situation. Compiler chokes (rightly) telling me the virtual base class doesn't implement those functions.
I can get around this by making the virtual base class define all the possible functions in the child classes and put dummy implementations in some child classes but it seems in-elegant.
Is there a better way to do this?
|
|
|
|
|
Since you are using the base class pointer to call the functions, those functions must exist as virtual or pure virtual in the base class.
In the derived classes, you must override whatever virtual functions are needed. In the case of pure virtual functions, it is mandatory that you implement this in the derived classes.
So instead of having dummy implementations is several derived classes, have a dummy implementation in the base class and don't make it pure virtual.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I did it by adding the virtual functions to the base class. Just seems like a clunky solution.
Thx very much.
|
|
|
|
|
i ues string class in a Win32 Console Application(build by VC++ 6),here is the code and errors, how can i fix it?
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "Psapi.h"
#include <iostream.h>
#include <string>
using namespace std;
void PrintProcessNameAndID( DWORD processID )
{
string szProcessName;
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
int len = lstrlen(szProcessName);
GetModuleBaseName( hProcess, hMod, szProcessName,
len);
}
if(lstrcmp(szProcessName, "smss.exe"))
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
}
CloseHandle( hProcess );
}
int main(int argc, char* argv[])
{
...
return 0;
}
errors:
... : error C2664: 'lstrlenA' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
... : error C2664: 'GetModuleBaseNameA' : cannot convert parameter 3 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
... : error C2664: 'lstrcmpA' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
i 've tried ,then i have no regret
|
|
|
|
|
Trying using szProcessName.c_str() instead of only "szProcessName " in the functions 'lstrlenA' , 'GetModuleBaseNameA' and 'lstrcmpA' .
|
|
|
|
|
Thank u,Naveen.I did as u told me ,but comes a new error:
...:error C2664: 'GetModuleBaseNameA' : cannot convert parameter 3 from 'const char *' to 'char *'
how to do?
i 've tried ,then i have no regret
|
|
|
|
|
oh yea.. haha i must be looking like a fool now...
i fix it
thanks for yr help
i 've tried ,then i have no regret
|
|
|
|
|
hmm..
I modified you code a little.Just changed the szProcessName to TCHAR.
void PrintProcessNameAndID( DWORD processID )
{
TCHAR szProcessName[MAX_PATH];
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
MAX_PATH);
}
if(lstrcmp(szProcessName, "smss.exe"))
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
}
CloseHandle( hProcess );
}
|
|
|
|
|
thanks for ue help nave, but yr code still have a little problem
if(lstrcmp(szProcessName, "smss.exe"))
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
that is: function lstrcmp(lpstring1, lpstring2),when lpstring1 equals lpstring2,the return value is zero.so if i need only see "smss.exe" on the screen,i should change it like this
if(!lstrcmp(szProcessName, "smss.exe"))
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
i 've tried ,then i have no regret
|
|
|
|
|
CHYGO wrote: if(!lstrcmp(szProcessName, "smss.exe"))
lstrcmp() is not a boolean function so you should refrain from treating it as such:
if (lstrcmp(szProcessName.c_str(), "smss.exe") == 0)
... Also, since szProcessName is a string variable, why not just use:
if (szProcessName != "smss.exe")
...
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
What's the best way to reliable determine if a volume is online and ready for use?
Current I am using GetVolumeInformation to do this. My assumption is that.
Should I go a step further and read the root folder?
Just wondering if GetVolumeInformation can report something present that's not ready for access?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
I need to construct Rational numbers, but they have to be in the simplest form... Here's what I have.
Rational::Rational( int Num , int Den )
{
int A = Num;
int B = Den;
int temp;
while(B)
{
temp = B;
B = A%B;
A = temp;
}
if( A != 0 )
{
Numerator_ = Num/A;
Denominator_ = Den/A;
}
}
modified on Thursday, March 5, 2009 8:52 PM
|
|
|
|
|
What's your question exactly ?
|
|
|
|
|
We're always happy to see your achievements, now what is the question?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Your Euclidean algorithm is correct. What's your concern?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi,
I'm looking for much better optimzed code for adding escape sequence than the below.
void appendSlash(const string& source, string& result)
{
for(unsigned int i = 0; i < source.length(); i++)
{
switch(source[i])
{
default:
result += source[i];
break;
case '"':
result += "\\\"";
break;
}
}
}
The switch-case in the current code is to handle more scenarios that might be added for implementing later.
Thanks in advance,
Regards,
Mayur M
|
|
|
|
|
You should use the infamous find and replace
string class (rather basic_string class) has a member function called find to find the character that you specify in your switch statement. After finding the character, use the replace member function to put in the escape sequence that you wish.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
What about PathAddBackslash() , or:
if (source.substr(source.length() - 1) != "\\")
source += '\\';
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Can someone please take a look at this class and tell me what I'm doing so terribly wrong. The compiler gives me an error I search around fix it and then another one pops up.
I will post my header file and my code...And if someone has a thought about how to overload the input operator that would help because i am lost on that one
#ifndef RATIONAL_
#define RATIONAL_
using namespace std;
#include <iostream>
class Rational
{
public:
Rational( int = 0, int = 1 );
Rational( const Rational& );
Rational& operator=( const Rational& );
int GCD();
void Simplify();
bool IsValid() const;
int Numerator() const;
int Denominator() const;
friend istream& operator>>( istream&, Rational& );
friend ostream& operator<<( ostream&, const Rational& );
private:
int Numerator_;
int Denominator_;
};
bool operator==( const Rational&, const Rational& );
bool operator!=( const Rational&, const Rational& );
bool operator< ( const Rational&, const Rational& );
bool operator<=( const Rational&, const Rational& );
bool operator> ( const Rational&, const Rational& );
bool operator>=( const Rational&, const Rational& );
Rational operator+( const Rational&, const Rational& );
Rational operator-( const Rational&, const Rational& );
Rational operator*( const Rational&, const Rational& );
Rational operator/( const Rational&, const Rational& );
#endif
</iostream>
using namespace std;
#include <iostream>
#include "proj06.rational.h"
Rational::Rational( int Num, int Den )
{
Numerator_ = Num;
if (Den <= 0)
{
Denominator_ = 1;
}
else
{
Denominator_ = Den;
}
}
Rational::Rational( const Rational& C )
{
Numerator_ = C.Numerator_;
Denominator_ = C.Denominator_;
}
Rational& Rational::operator=(const Rational& C )
{
Numerator_ = C.Numerator_;
Denominator_ = C.Denominator_;
return *this;
}
int Rational::GCD()
{
int A = Numerator_;
int B = Denominator_;
int Temp;
while(B)
{
Temp = B;
B = A%B;
A = Temp;
}
return A;
}
void Rational::Simplify()
{
int GCDNumber = GCD();
if(GCDNumber != 0)
{
Numerator_ = Numerator_/GCDNumber;
Denominator_ = Denominator_/GCDNumber;
}
}
bool Rational::IsValid() const
{
return ( Denominator_ != 0 );
}
int Rational::Numerator() const
{
return Numerator_;
}
int Rational::Denominator() const
{
return Denominator_;
}
bool operator==( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator() == B.Numerator() and A.Denominator()== B.Denominator());
}
bool operator!=( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator() != B.Numerator() and A.Denominator()!= B.Denominator());
}
bool operator<( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator()*B.Denominator())<(A.Denominator()*B.Numerator());
}
bool operator<=( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator()*B.Denominator())<=(A.Denominator()*B.Numerator());
}
bool operator>( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator()*B.Denominator())>(A.Denominator()*B.Numerator());
}
bool operator>=( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator()*B.Denominator())>=(A.Denominator()*B.Numerator());
}
Rational operator+( const Rational& A, const Rational B )
{
int Num;
int Den;
Num = A.Numerator()*B.Denominator()+A.Denominator()*B.Numerator();
Den = A.Denominator()*B.Denominator();
Rational C(Num, Den);
return C.Simplify();
}
Rational operator-( const Rational& A, const Rational B )
{
int Num;
int Den;
Num = A.Numerator()*B.Denominator()-A.Denominator()*B.Numerator();
Den = A.Denominator()*B.Denominator();
Rational C(Num, Den);
return C.Simplify();
}
Rational operator*( const Rational& A, const Rational B )
{
int Num;
int Den;
Num = A.Numerator()*B.Numerator();
Den = A.Denominator()*B.Denominator();
Rational C(Num, Den);
return C.Simplify();
}
Rational operator/( const Rational& A, const Rational B )
{
int Num;
int Den;
Num = A.Numerator()*B.Denominator();
Den = A.Denominator()*B.Numerator();
Rational C(Num, Den);
return C.Simplify();
}
ostream& operator<<( ostream& Out, const Rational& Item )
{
Out << Item.Numerator() << "/" << Item.Denominator();
return Out;
}
</iostream>
|
|
|
|
|
what is the error you getting?
Yusuf
|
|
|
|
|