|
-
Jan 6th, 2003, 10:39 AM
#1
Thread Starter
Frenzied Member
FindWindow Weird Error
Hi im getting a error:
PHP Code:
error C2440: '=' : cannot convert from 'class CWnd *' to 'struct HWND__ *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
My Code is:
PHP Code:
HWND i;
HWND x;
i = FindWindow("Program",0);
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 6th, 2003, 11:36 AM
#2
Monday Morning Lunatic
You're mixing MFC and API.
Use ::FindWindow(...).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 6th, 2003, 01:34 PM
#3
Since you're already using MFC:
Code:
CWnd *pWnd;
pWnd = FindWindow("Program", 0);
Don't forget that the CWnd pointer is not valid any longer than the function you're in. After that it might get deleted at any time.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 6th, 2003, 02:47 PM
#4
Thread Starter
Frenzied Member
ok i got it using parksies' way. Now can you tell me how do i convert the HWND to Char ?
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 6th, 2003, 03:38 PM
#5
Frenzied Member
Why would you want to do that? (maybe you can just cast it)
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 6th, 2003, 03:58 PM
#6
Thread Starter
Frenzied Member
How do i cast it ? What is casting it?
- JayWare
Live to love. Not to Hate
Im to busy to have a site. But I got one and still working on it.
http://dre3k.net/
-
Jan 6th, 2003, 04:06 PM
#7
Frenzied Member
First please explain me why you want to convert it to a char?
Code:
MessageBox(myhWnd,(LPSTR)myhWnd, "Casting!", MB_OK);
that's casting what's happening over there at the bold part.
I know this example won't work, but it's just to illustrate how casting works. It kinda tells the compiler that you want it to send the HWND as a LPSTR to the MessageBox function.
damn my explaining is totally blurry today, hope you understand what I mean.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 6th, 2003, 04:40 PM
#8
Mine is more MFC-like...
Whatever. You can't convert HWND (32-bit) to char (8-bit) without loss of most the data you want. If you however (as I assume) want to convert the HWND to a string of some kind then you have three options.
The first I'd recommend the least:
Code:
// To decimal:
char decimalbuf[12];
sprintf(decimalbuf, "%i", hwnd);
// To hex:
char hexbuf[12];
sprintf(hexbuf, "0x%8x", hwnd);
The second is the most MFC-like as it uses the MFC string class CString:
Code:
// To decimal:
CString strDecimal;
strDecimal.Format("%i", hwnd);
// To hex:
CString strHex;
strHex.Format("0x%8x", hwnd);
The third is under normal circumstances (that is, if you're not using MFC) the best and uses the STL classes. Requires <sstream>, <iomanip> and <string> to be included.
Code:
ostringstream ss;
// To decimal:
ss << hwnd;
string strDecimal = ss.str();
// Reset ss:
ss.str("");
// To Hex:
ss << setbase(16) << hwnd;
string strHex = ss.str();
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 6th, 2003, 04:46 PM
#9
Jop, be careful, he might really try what you're posting.
Casting only works to some extent. The above is likely to result in an access violation. If not it would only output garbage.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 6th, 2003, 06:25 PM
#10
Frenzied Member
Hehe that wasn't my intention, and while I was posting it I was sure that I wasn't explaining things clearly, so I thought I would illustrate it, which made it even worse just ignore my post JasonLpz!
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|