|
You will have to check the message queue frequently using PeekMessage. See for example MSDN KB Q74795, and I vaguely remember an article here on CP about it too.
PeekMessage is much easier than worker threads.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
i have process id and want to get main window hwnd how to get it.
r00d0034@yahoo.com
|
|
|
|
|
|
I think this might work for you, although it doesn't feel very elegant. Try looking at the Win32 API EnumWindows(). You define a callback function and pass that into EnumWindows(). For every top-level window open on the desktop, you'll get one call into your function, which hands you the HWND of that window and a user-defined field.
With the HWND, you can then call GetWindowThreadProcessId() to try and match to your already-known Process ID. So you'd set it up so that your callback function will keep churning (by setting the return value to TRUE) until it finds the right Process ID. Use the lParam field in EnumWindows to pass along an information struct that holds your ProcessID and the output HWND.
There's probably a cleaner way to do this, but this should get you on the right track. Here's some pseudo-code:
typedef struct
{
DWORD dwProcessID;
HWND hWnd;
} ENUM_PARAM, *LPENUM_PARAM;
BOOL CALLBACK cbEnumWindows( HWND hwnd, LPARAM lParam )
{
LPENUM_PARAM lpEnum = static_cast< LPENUM_PARAM >( lParam );
if( lpEnum )
{
DWORD dwProcessID = 0;
GetWindowThreadProcessId( hwnd, &dwProcessID );
if( dwProcessID == lpEnum->dwProcessID )
{
lpEnum->hWnd = hwnd;
return FALSE;
}
}
return TRUE;
}
int main( int argc, char *argv[] )
{
ENUM_PARAM EnumParam;
EnumParam.dwProcessID = 1234;
EnumParam.hWnd = NULL;
EnumWindows( cbEnumWindows, static_cast< LPARAM >( &EnumParam ) );
if( EnumParam.hWnd )
{
}
}
</code>
Ty
|
|
|
|
|
const int ca(200);
int &cb=*((int*)&ca);
cb=2400;
cout<<"ca="<
|
|
|
|
|
The compiler is probably optimizing because ca is declared const. The compiler can replace any references to ca and directly insert 200.
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Your reply sounds reasonable, but both the varibale of 'ca' and 'cb' have same address in memory, but their value is different, I just can't unstand it, it must be somewhere else for 'ca' or 'cb', is that correct!
|
|
|
|
|
cadinfo wrote:
, but both the varibale of 'ca' and 'cb' have same address in memory
After the compiler optimization, 'ca' has NO address in memory any more. It simply is the value '200' known at compile time.
You promised not to change this value by declaring it const, remember?
So the compiler can replace every access to 'ca' by the value '200' at compile time.
In effect, this is a little like a precompiler #define, in that both methods don't make a variable.
|
|
|
|
|
jhwurmbach wrote:
,After the compiler optimization, 'ca' has NO address in memory any more.
but in debug mode or use
cout<<"&ca="<<&ca<<"\t&cb="<<cb<<endl;
you will find address of ca is same to cb, and in debug time the value of ca will change to new value, but when output it return to '200'
|
|
|
|
|
Well, I did look at the assembly-code, after tracing did not reveal why '2400' is changed to '200' in output:
16: cout<<"ca="<<ca<<"\tcb="<<cb<<endl;
004017BE push offset @ILT+195(std::endl) (004010c8)
004017C3 mov edx,dword ptr [ebp-8]
004017C6 mov eax,dword ptr [edx]
004017C8 push eax
004017C9 push offset string "\tcb=" (0046e020)
004017CE push 0C8h
004017D3 push offset string "ca=" (0046e01c)
004017D8 push offset std::cout (0047c0c0)
004017DD call @ILT+640(std::operator<<) (00401285)
004017E2 add esp,8
004017E5 mov ecx,eax
004017E7 call @ILT+250(std::basic_ostream<char,std::char_traits<char> >::operator<< ) (004010ff)
At address 004017CE you see how the code inserts the '200' (0C8h) into the output stream and does not access the variable at [ebp-4].
Some sort of optimisation, even in debug mode.
But you can't blame the compiler, after all you *promised* that 'ca' would not change!
|
|
|
|
|
I have an MFC MDI App. In this I want to copy a bmp from Folder1 into folder2 .How does one do this?
Thanks,
ns
|
|
|
|
|
You could use CopyFile(), look it up in MSDN...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
SHFileOperation could find some use as well
|
|
|
|
|
I created a new database using ADOX. When I go to add ecords to it, they are added haphazardly, not in order. THe latest one might be in the middle somewhere...
How do I ensure that they get added in order?
Heres my code:
try
{
ADO::_RecordsetPtr rsBlob (__uuidof(ADO::Recordset) );
m_pCommand->CommandText="SELECT * FROM tblTest" ;
rsBlob->CursorLocation = ADO::adUseClient;
rsBlob->Open ((IDispatch *) m_pCommand, vtMissing, ADO::adOpenKeyset,
ADO::adLockOptimistic, -1);
rsBlob->AddNew();
rsBlob->Fields->Item["A_Image"]->Value = bstrFile;
char* charID = new char[strID.GetLength()+1];
strcpy(charID, strID);
rsBlob->Fields->Item["MINE_TYPE"]->Value = charID;
delete[] charID;
}
Thanks for helping,
ns
|
|
|
|
|
The SQL database does not guarantees, that it stores records in particular order (even if it often does). It's by design. The order of returned records is defined by the ORDER BY clause of SELECT query.
Pavel
Sonork 100.15206
|
|
|
|
|
Can someone give me a practical example/reason of why classes can contain static member functions, aside from data encapsulation I'm not sure I see their purpose. We were talking about them today in a class that I have and my professor couldn't give me any specific reason as to why we have this. Any ideas would be great as I am just a little curious (aside from those that say "So you can call method X without object instantiation" ). Thanks.
Nick Parker
|
|
|
|
|
I am writing a wrapper for XML in C# at the moment, and one thing that takes a few lines of code normally is to take a node and return the text value, if any, associated with it. node.text simply won't do the job well. By making the function GetNodeValue static, I am able to call it if I have a node kicking around but I don't have an instance of my class. The class essentially becomes a namespace that contains functions which I may have a use for even if I don't have an instance of the class at that point in time, so it saves me building the object needlessly.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Gotcha, I think that pretty much explains it.
Nick Parker
|
|
|
|
|
One of the good uses I've found for static members is factory like functions. If I have a class that I dont' want anybody but me to be able to instanciate I make all of hte constructors private. Then I allow creation through static member functions. This comes in handy sometimes especially in other languages such as C# and Java
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
Sometimes you need a class attribute, which is shared between all instances of the class.
Pavel
Sonork 100.15206
|
|
|
|
|
Pavel Klocek wrote:
Sometimes you need a class attribute, which is shared between all instances of the class.
Could you elaborate?
Nick Parker
|
|
|
|
|
If I have the data in 1.prv and I want embed that data in program while compile.
Can I include like this #include "C:/1.prv"?
Thank you.
|
|
|
|
|
Dunno - have you tried ?
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
hey all. I am working on a single document MFC program and currently have a problem. Under a CFormView document, there is the GetDocument function. Is there any way to use this function or get the same effect in a CDialog document? Any help is appreciated. Thanks.
Brad Jennings
|
|
|
|
|
CYourDoc *pDoc = (CYourDoc *)(((CFrameWnd *)AfxGetMainWnd())->GetActiveView()->GetDocument()); I guess this is what you're after.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|