|
did you spell check that?
~SilverShalkin
|
|
|
|
|
Tim Smith wrote:
not picking on you redeemer
Then, who else are ya picking on?
Moi???
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
i have a picture box controls on a dialog box.i want to show bitmap on it, on the click event of another dialog. doing so causes DEBUG ASSERTION FAILED! msg first and then image iz displayed on the top left corner of screen instead of picture box. i m trying to solve the problem for the last two weeks but didnt find any solution.
(if i use the device context of Dialog instead of picture box then it works well but when i try to get the device context of picture box it don't.)
if u know something about this problem or have some helping code plz give it to me. thanx
God Helps those who help others.
|
|
|
|
|
Can't quite figure that out yet...
THanks
|
|
|
|
|
NM_RCLICK doesn't work?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Yes, and then create a
NMLISTVIEW *pNmlv;
and assign the value of lParam to it
pNmlv = (NMLISTVIEW *)lParam;
and
if (pNmlv->iItem == -1)
then no item is selected, otherwise some item is selected and the index number of the item is in pNmlv->iItem
Thankuoi
|
|
|
|
|
Hey guys, im trying to figure out how I would override a mouse even in Outlook with an add-in i've made. More specifically, I want have my own dialog pop up when i double click an appointment spot in the calendar. Any help would be nice. Thanks
|
|
|
|
|
I apologize for asking this question over and over, but I'm still having trouble with the variables in my application. The problem I am having, for example, is when a CString variable is populated within a particular function, all of the CString variables in that function are populated with the same data and, inexplicably, share the same memory address. Therefore, when the data in one of the variables is changed, all of the others change along with it. I'm not sure what I'm doing wrong. some people have mentioned that I might be overwriting the stack. I'm not sure how to overwrite the stack and so I'm not sure if I'm doing it or how to fix it. Any help would be greatly appreciated.
|
|
|
|
|
Post some code. It sounds like coding error.
|
|
|
|
|
for(int i = 0; i < TempPlaybookFileComboBox.GetCount(); i++)
{
fstream PlaybookFileStream;
CString StrippedFileName;
CString PlaybookFile;
char *pdest;
int result;
int ch = '.';
int slash = '\\';
TempPlaybookFileComboBox.GetLBText(i, PlaybookFileName);
StrippedFileName = PlaybookFileName.Left(PlaybookFileName.GetLength() - 4);
// populate the treectrl
HTREEITEM hti = m_wndPlaybookTree.InsertItem(StrippedFileName);
PlaybookFileStream.open(PlaybookFileLocation + "\\" + PlaybookFileName, ios::binary | ios::in);
while(!PlaybookFileStream.eof())
{
CString PlaybookFilePath;
int PathLength;
PlaybookFilePath = "";
PlaybookFileStream.getline(PlaybookFile.GetBuffer(0), 128, '\n');
PlaybookFilePath = PlaybookFile;
PathLength = PlaybookFile.GetLength();
// strip out the filename from the path-filename combination
pdest = strrchr(PlaybookFile.GetBuffer(0), slash) + 1;
result = pdest - PlaybookFile.GetBuffer(0) + 1;
if (result > 0)
sprintf(PlaybookFile.GetBuffer(0), pdest);
// strip off the extension
pdest = strchr( PlaybookFile.GetBuffer(0), ch );
result = pdest - PlaybookFile.GetBuffer(0) + 1;
// null terminate the string and add to the tree
PlaybookFile.GetBuffer(0)[result - 1] = '\0';
m_wndPlaybookTree.InsertItem(PlaybookFile.GetBuffer(0), hti);
// Allocate memory for new offensive position
ptrPlaybookFileItem = new PlaybookFileRec;
if (ptrPlaybookFileItem == (PlaybookFilePtr)NULL)
{
AfxMessageBox("Unable to allocate memory for Playbook File information", MB_OK);
AfxAbort();
}
ptrPlaybookFileItem->PlaybookFileName = PlaybookFile;
ptrPlaybookFileItem->PlaybookFilePath = PlaybookFilePath;
// Add the Offensive Postion information to the vector
m_PlaybookFiles.push_back(ptrPlaybookFileItem);
}
PlaybookFileStream.close();
}
There's a little snippet of code. The PlaybookFile and PlaybookFilePath variables are mapped to the same memory address.
|
|
|
|
|
This doesn't look right to me.
PlaybookFileStream.getline(PlaybookFile.GetBuffer(0), 128, '\n');
the argument in GetBuffer causes CString to allocate at least that many characters to the buffer. If your CString object starts out with an empty string and you do a GetBuffer(0) you still have no memory allocated. Try this instead.
PlaybookFileStream.getline(PlaybookFile.GetBuffer(0128), 128, '\n');
You must allso call ReleaseBuffer after modifying the string.
|
|
|
|
|
I think Bill Wilson nailed it for you: misunderstanding how CString works, and then abusing it like that usually leads to problems. And whoever you saw using GetBuffer( 0 ) like that should be slapped!
If you assign one CString to another, they will share the same memory. When you instantiate a CString object, it automatically initializes itself to an empty string (which is why you should not initialize them with "" : it just wastes time). Internally, CString s (this is different in VS.NET, BTW) keep an object around referred to by afxEmptyString , which is used to indicate an empty string. Since you have two CString s containing empty strings (thus both pointing to afxEmptyString ), you can see that problems will occur is you then use CString::GetBuffer( 0 ) to get a buffer: you will "step on" (and likely over) the internal afxEmptyString object, and thus screwed every other empty CString out there!
IMHO, I think that you would benefit from not misusing CString objects in the ways your code shows, and use normal char/TCHAR buffers. For example, StrippedFileName and PlaybookFile could likely be plain buffers of MAX_PATH + 1 length, or even 32KB each, which your stack will likely have more than enough room for, and is long enough for a network-based path name. You also avoid the unnecessary hit of dynamic memory allocation.
IME, I have found misuse of CString objects to be pretty damn near, if not right at, the heart of MFC applications with performance problems (esp. after running for an extended period of time, and/or with multiple threads).
Peace!
-=- James.
"Some People Know How To Drive, Others Just Know How To Operate A Car."
(Try Check Favorites Sometime!)
|
|
|
|
|
VS6's class wizard would often add stuff like:
public:
protected:
it used this for the message map, etc.. and i have just deleted em.. what i'm wondering about is this at the begining of my .h files:
#if !defined(AFX_SCTAX_H__9275F024_08D4_11D6_B612_00A0CC5C3AED__INCLUDED_)
#define AFX_SCTAX_H__9275F024_08D4_11D6_B612_00A0CC5C3AED__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif can i get rid of this stuff? and just replace it with what VS .net seems to put at the begining of .h files:
#pragma once
just looks like crap and i'd like to get rid of it once i get a change to run through my code and clean it up..
thanks!
-dz
|
|
|
|
|
If you're asking can you get rid of #if _MSC_VER > 1000, then yes.
The AFX_ define is used to make unique include files. If yours are unique AND you don't share them with anyplace they might not be unique (like CodeProject), then yes.
If you're sure you always have stdafx.h in you include path, then yes.
|
|
|
|
|
I say no.
The
#if !defined(AFX_SCTAX_H__9275F024_08D4_11D6_B612_00A0CC5C3AED__INCLUDED_)
#define AFX_SCTAX_H__9275F024_08D4_11D6_B612_00A0CC5C3AED__INCLUDED_ code is good practice for header files. If you don't like the way it looks you can clean it up a bit
if !defined (_SCTAX_H__INCLUDED_)
#define _SCTAX_H__INCLUDED_ if that makes you happy.
All the //{{AFX...//}}AFX... comments are markers used by the class wizard to added code to your project.
If MFC is going to put this stuff in all the applications you create, why bother tring to delete it all out? I would spend the time writting code instead of deleting comments...
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
dazinith wrote:
it used this for the message map, etc.. and i have just deleted em..
So you'll be unable to use ClassWizard for adding virtual functions. You'll have to type the member function declaration in header file and function body in .cpp.
And if you get rid of //{{AFX_MSG section, you'll need to add manually three pieces for each message handler - one in .h and two in .cpp files.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
.net doesn't have the classwizard.. and it doesn't add any of this extra stuff when creating message handlers, etc.. so deleting it does nothing.. i guess ill leave the stuff at the top of the .h files.. i was just curious if any of the .net users had noticed that the code looks alot better with classes and functions made using .net over VS6..
-dz
|
|
|
|
|
BTW, the #pragma once is VS.NET's way of implementing the #ifndef/#define/#endif sentries that you normally find at the top of Header Files.
IIUC, the #pragma once method is a slightly faster (it is also available in VC++ 6.0) way of preventing multiple-inclusion: the preprocessor keeps track of files that use the #pragma and can locate that information faster than going through its symbol table looking for the Sentry symbol.
Peace!
-=- James.
"Some People Know How To Drive, Others Just Know How To Operate A Car."
(Try Check Favorites Sometime!)
|
|
|
|
|
If you will delete the lines
//{{AFX_MSG_MAP(CStatusBarMsgWnd) and
//}}AFX_MSG_MAP
from the CPP file, and respectively
//{{AFX_MSG(CStatusBarMsgWnd) and
//}}AFX_MSG
from the H file,
class wizard will tell that it doesn't find AFX_MSG_MAP or
AFX_MSG and wants to remove the class from its view.
Also if class wizard is run for the first time, it will
tell NOTHING and your custom class will not appear at all.
These lines look like a comment but class wizard uses them.
|
|
|
|
|
I've just read how Windows NT/2000 OS's are native Unicode and that a performance hit will be encountered if using ANSI strings. So, the recommendation was to #include <tchar.h> and use the _TEXT macros and so on. I also want to build for Win 9x too so I took this recommendation to heart.
I started to convert a library I just converted from BC++ to VC++ and
encountered this problem:
TCHAR* TRadar::GetString(TCHAR *buff)
{
ostrstream os(buff, 100);
os << radarTag.GetString() << " " << maxRange << " " << scanTime;
return buff;
}
The error is:
error C2664: '__thiscall std::ostrstream::std::ostrstream(char *,int,int)' : cannot convert parameter 1 from 'unsigned short *' to 'char *'
Obviously, ostrstream does not know what a Unicode array is. Is there a simpler way than below? Or, am I gonna have to do this to all of my objects that print msgs to a std::stream output. I thought the whole purpose of using TCHAR and the macros was so that I didn't have to put any conditional preprocessor statements in except defining _UNICODE.
TCHAR* TRadar::GetString(TCHAR *buff)
{
#ifdef _UNICODE
USES_CONVERSION;
ostrstream os(W2A(buff), 100);
#else
ostrstream os(buff, 100)
#endif
os << radarTag.GetString() << " " << maxRange << " " << scanTime;
return buff;
}
|
|
|
|
|
Use
typedef std::basic_ostringstream<tchar> _tostringstream;
TCHAR* TRadar::GetString(TCHAR *buff)
{
_tostringstream os(buff); os << radarTag.GetString() << " " << maxRange << " " << scanTime;
.
.
.
}
|
|
|
|
|
You lost me. I don't see where basic_ostringstream's constructor takes a TCHAR pointer. And, if you meant char pointer, I still have to convert from ANSI to Unicode and would still need the #ifdef _UNICODE so that I can convert for NT but not for Win 9x. Could you clarify, please? Thanks.
|
|
|
|
|
It was a typo
Here is the complete code
TCHAR* TRadar::GetString(TCHAR *buff)
{
_tostringstream os;
os << radarTag.GetString() << " " << maxRange << " " << scanTime;
_tcscpy(buff, os.str().c_str());
return buff;
}
(It is not as efficient as strstream but strstream is not in the Standard C++ lib anymore.)
|
|
|
|
|
I must be missing something. I get what you are saying about using _tcscpy() but the second parameter in the code you posted would be an ANSI string which would work if _UNICODE is not defined. But if it is, then I would get a compile error: cannot convert parameter 2 from 'const char *' to 'const unsigned short *'
I have researched that there is a "wide char" version of this ostringstream class called, wostringstream. But, I would run into the same problem when it comes to converting it in the _tcscpy(). That is, if I am using .c_str(). How do I convert properly?
|
|
|
|
|
JohnnyG wrote:
I must be missing something
I lost the <> in HTML conversions so my code which typedefs actually looks like
typedef std::basic_ostringstream<TCHAR> _tostringstream;
|
|
|
|