|
Hi,
Hope someone can help me out here.
I'm trying to add a tracking tooltip to my app, so I got the required code from the vS help files and then added it to my code. So basically I have:
<br />
HWND WINAPI CreateTT(HWND hwndOwner)<br />
{<br />
<br />
<br />
}<br />
in my wndproc I added
<br />
case WM_MOUSEMOVE:<br />
<br />
if(g_bIsVisible){<br />
<br />
#define X_OFFSET 15<br />
#define Y_OFFSET X_OFFSET<br />
GetCursorPos(&point);<br />
SendMessage(g_hwndTT,<br />
TTM_TRACKPOSITION,<br />
0,<br />
(LPARAM)MAKELPARAM(point.x + X_OFFSET,<br />
point.y + Y_OFFSET));<br />
}<br />
return 0;<br />
I then added to my CASE WM_CREATE:
<br />
g_hwndTT = CreateTT(hwnd);<br />
When I compile my app I get a "Run-Time Check Failure #3 - The variable 'g_hwndTT' is being used without being defined." whenever I move the mouse. I don't understand why I get this error when I'm defining g_hwndTT using g_hwndTT = CreateTT(hwnd); I'm sure it is something simple I'm missing. Any help appreciated,
Thanks in advance,
Paddy.
|
|
|
|
|
When an MFC application starts up does it intentionally set the "current direcotry" to its folder? I'm trying to load a file into the app when it's type is opened through Explorer, I've disable it from complaining about it not find the file (CCommandLineInfo::m_strFilename doesn't like spaces . When it loads the file..even though its not the one opening (doc class). How can I prevent it from changing the directory it throws all of the CFile file openings off (even though all of them use the full directory path).
-Steven
CP Addict
By reading this message you are held fully responsible for any of the mispelln's or grammer, issues, found on, codeproject.com.
For those who were wondering, actual (Linux) Penguins were harmed in creating this message.
|
|
|
|
|
Once again I have gotten bitten by VC++ treating the "bool" type as the rough equivilant of "void". Given the following two member functions (simplified slightly):
::Parse(LPCTSTR pStr, TCHAR delimeter, bool append = false);<br />
::Parse(LPCTSTR pStr, bool append = false);
When I use xxx.Parse(str, ',');
VC++ declared they are ambiguous. On whose planet?
I seriously want a switch that makes a bool type accept only true , false or the result of a comparison operation.
Having ranted all that, what does the C++ standard say about bool ? Is it the empty type VC++ uses or a strict type?
|
|
|
|
|
bool is an proper type and can be used to overload functions the way you want.
Looks like Microsoft is wrong. Again.
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
Awasu v0.4a[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Are you sure you're not doing a Unicode build?
the thingies above resove fine (for me) when TCHAR is actually a char.
However, when TCHAR resolves to unsigned short, it's of course ambigous (should it expand to 16 bit, or reduce to one?)
Those who not hear the music think the dancers are mad. [sighist] [Agile Programming]
|
|
|
|
|
Joe Woodbury wrote:
Once again I have gotten bitten by VC++ treating the "bool" type as the rough equivilant of "void".
That is not entirely correct I believe, and depending on what TCHAR expands to it might actually be that the VC compiler (even that you don't state version) might actually be correct.
If you are compiling the displayed code as Unicode, meaning TCHAR expands to either the C++ required type wchar_t, or the MS invented undigned short (this depends upon both compiler version and compiler flags!), there would be an equally bad match for both bool and unsigned char for the char literal ','.
|
|
|
|
|
I've identified the problem.
Since the character is not defined as a wchar_t (either with L or _T), in UNICODE mode, it is still a char . The compiler must then fit the plain char with the "best" match, but [in my tests] never considers wchar_t if there is an alternate available. It will even pick int over wchar_t .
In my opinion, bool should never be selected. Even if there were only one function with a bool argument, I want an error to be generated. (For example, given void function(bool isValid); , function(1) should generate an error.)
char should pick wchar_t before to int , or at least a switch should be available to force this behavior.
|
|
|
|
|
I would imagine Christian would have a good idea which direction the compiler should try first. He seems to have researched this type of stuff. Interesting question.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
*grin* I actually answered and then read your answer, expecting you to have said the same, but leaping in anyhow, because Microsoft are correct. char to int is guarenteed in the standard. You can do this:
char a = 65;
and this
int a = 'a';
so it stands to reason that the compiler will attempt that conversion.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Joe Woodbury wrote:
It will even pick int over wchar_t.
In standard C++, conversion between char and int is implicit.
Joe Woodbury wrote:
char should pick wchar_t before to int, or at least a switch should be available to force this behavior.
I disagree. char to int is embedded in the C++ standard.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
In standard C++, conversion between char and int is implicit.
... char to int is embedded in the C++ standard.
Close.
After some research and reading I realized why the compiler is behaving the way it is. When trying to determine which overloaded function to use, if an exact match is not found, the compiler then checks promotions, then conversions.
char to int is a promotion.
char to wchar_t is a conversion. (char is is a numeric value that can represent an ASCII character (0-127) and by definition, the first 127 characters of UNICODE exactly match ASCII. Thus, if the char is in the range 0-127, it appears to be a promotion. However, since by defintion char is a numeric value and wchar_t is a character value, it still is a conversion.)
Anything "going to" a bool, except true or false (or an expression that resolves to true or false), is a conversion, thus the ambiguity I encountered. I still believe, however, that any conversion should take precedence over a conversion to bool.
(I still firmly believe conversions to bool should be optionally disallowed.)
|
|
|
|
|
What might be part of the problem here is that char is signed and wchar_t is unsigned. Thus char -> wchar_t is a degenerative conversion given that over half the range of char can not be properly mapped to wchar_t. However, char -> bool is a well defined conversion given that char fully maps into a bool.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
How icon run my program as any programs in computer,for example i programmed an organizer and i want to run it as any programms,how i can build it ,,any one help me?
|
|
|
|
|
BOOL CWnd::GetWindowPlacement(WINDOWPLACEMENT* lpwndpl) const
{
<code>ASSERT(::IsWindow(m_hWnd));</code>
lpwndpl->length = sizeof(WINDOWPLACEMENT);
return ::GetWindowPlacement(m_hWnd, lpwndpl);
}
Crash says its not a window. However in my code I am getting a nonNUll pointer:
for (int i = 0 ; i <imageDisplayVectorsize ; i++)
{
CImageDisplay* imageDisplay =ImageDisplayVector[i];
imageDisplay->GetWindowPlacement(&wp);
I've used my ImageDisplayVector elsewhere as
int vecSize = ImageDisplayVector.size();
for (int i = 0; i < vecSize; i++)
{
CImageDisplay * pImageTemp = ImageDisplayVector[i];
pImageTemp->ShowWindow(SW_SHOW);
}
and the windows show up (first I'd hidden them) with no problem. Which makes me think my pointer is fine.
SO why does the GetWindowPl think its not a window?
How shall I approach the debugging of this problem?
Appreciate your help,
ns
|
|
|
|
|
Hello Everybody:
This is the weirdest thing that I experienced with MFC. In a project that I'm working, there is a class that is derived from a CScrollView that displays images. When I run the program and the CScrollView is visible on the screen, sometimes it shows up as a text editor. It stays as an text editor and the images shows up. There are some occasions that the text editor just stays there. By any chance any of you guys experienced this before? Any place that you guys can suggest that I can start looking? It's been hard to spot because the code is written by someone else. I tried in the CScrollView's OnInitialUpdate and I don't find anything. This is happens in a Win2k and a WinXP machine. Any answer is more than welcome.
Best regards,
Luis E. Cuadrado
)
|
|
|
|
|
I spent a while debugging this.:
I had a loop:
for (int i = 0; i &< nSize; i++) ;
{
vec[i]->someMethod();
}
where I was storing pointers to a class in the STL vector.
Well, eventually I saw why my code was crashing......(the . What puzzles me is that the variable i was still holding its final value of nSize + 1 when it finished with the for(). Besides which my code should have complained that i was not declared.....since its within the for ....
Maybe i am wrong in my scope assumptions?
Appreciate your help,
ns
|
|
|
|
|
Declaring a variable inside the for() is the same as declaring it outside the for(). I'd certainly prefer this not to be the case. As an aside you should be using STL iterators.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
I could...but thats the appeal of an STL vector for me instead of some other container- accessing by index ............ But it would save me from this sort of mishap
Thanks much. I was mistaken in my scoping assumption then.....
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
I was mistaken in my scoping assumption
Actually, you're right. Microsoft is wrong in this case. Very annoying when you're trying to code for multiple platforms.
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
Awasu v0.4a[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Hasn't this change been introduced only recently to the standard?
And, although it solves a common nuisance, it can make existing code break silently (though admittedly badly written). A bad move, I'd say...
Those who not hear the music think the dancers are mad. [sighist] [Agile Programming]
|
|
|
|
|
peterchen wrote:
Hasn't this change been introduced only recently to the standard?
Depends if you work for Microsoft and/or consider half a decade to be "recent", or if you consider the ISO C++ standard to be a document Microsoft should follow.
|
|
|
|
|
As I understand it, this was in the proposed revisions, then taken out, then put back in.
If you want the standards behavior you can add extra braces:
{for (int i = 0; i < 10; i++)<br />
{<br />
...<br />
}}
Incidentally, you can turn this enforcement on in VC++.NET.
|
|
|
|
|
Joe Woodbury wrote:
Incidentally, you can turn this enforcement on in VC++.NET.
That might be what you believe, and what Micros~1 wants to fool you into believing - the truth is that you're only screwed from the side, and not directly from behind, with that "fix".
for (int i=...) {}<br />
for (short i=...) {<br />
}
|
|
|
|
|
Mike Nordell wrote:
for (int i=...) {}
for (short i=...) {
// guess type of 'i'
}
short
I just checked (and it does what it advertises.)
|
|
|
|
|
ns wrote:
What puzzles me is that the variable i was still holding its final value ...
This is a well known bug in Microsofts compilers, and even in their "latest and greatest" the bug persists, only in a much more evil form:
for (int i=...) {}<br />
for (short i= ...) {<br />
}
There is but one solution to this problem: To the top of every source file wanting to keep scope of for-loop-variables, add
#ifdef _MSC_VER<br />
#define for if(0) {} else for<br />
#endif
|
|
|
|