|
icabod wrote:
But that's not the point. Your original "look at the other threads" comment was valid, which is why I voted it up earlier :]
visibly, not everyone understood that we were talking about the use of the (LPCTSTR) cast operator...
I really don't see why i continue awering/helping people that don't take 1 minute of their time to see if their question is not already on the last 50 ones on the forum ...
such behaviors sucks... (and i don't care to be voted down for this... )
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I work on a single document app. Now I have the problem that messagehandling doesn't work right. I want to activate the creation of a new document from another point as the main menu and toolbar. For that purpose I included
ON_COMMAND(ID_FILE_NEW, OnFileNew)
in a view class and tried to start the OnFileNew() function by sending a message to the view class:
pvw->SendMessage(ID_FILE_NEW)
It doesn't work! When debugging the whole matter I saw that OnFileNew() wasn't activated (and processed). Even if it does, I have to do all by myself (setting default name for empty document and so on).
How can I activate the applications OnFileNew Funktion? Why doesn't the message sending work?
I hope someone helps me with that (basic MFC) matter.
|
|
|
|
|
well friend,
i will not go in detail of message handling, but i will concentrate on your basic problem of Starting a new document whenever you click File->New.
When you use App Wizard and create a single document app, it automatically does it for you.
And if you wnat to do something else on file->new (like automatically saving the previous file without prompting etc anything) then you and Message handler using the Class Wizard to your Mainframe or any view class.
Hope that make things clearer, if not make post.
hey did you forget to rate? Plz rate my reply.
|
|
|
|
|
I did not make me clear enough. I used the App Wizard and clicking the New Document button or selecting it in main menu works.
I want to start it from another point too. For example a context menu or from another button. If there is a button in another toolbar that launches a funktion that requires a new document, I have to call the OnFileNew Funktion. But it doesn't work at the moment.
How can I create a new document from within own classes or functions?
|
|
|
|
|
You have to send or rather post a WM_COMMAND message with ID_FILE_NEW as parameter to your view class.
Hope this helps
--
Roger
|
|
|
|
|
Thank you! It works!
The right answer is:
AfxGetMainWnd()->SendMessage(WM_COMMAND,ID_FILE_NEW);
|
|
|
|
|
I need free VOIP library,
for implementing by me peer-to-peer call application,
as SCYPE does,
but without third party managed MAIN servers,
server - must be mine, - with availbale code or does not need.
are there such a libraries, with some good quality ?
Thanks you
|
|
|
|
|
hi
I am facing this problem that the windows in my application get distorted<the controls="" which="" usually="" come="" on="" them="" dont="" fit=""> after I increase system's DPI settings to maybe 120.
I want to resolve this problem through coding(c++).
I found a useful article for the same http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dngdi/html/highdpiapp.asp
Please help.
Regards
Atul
|
|
|
|
|
I'm using SendInput to control the mouse however I've found a funny with it.
If I move the mouse to the left and then to the right by the same amount then the mouse pointer returns to its initial position. However if I move the mouse to the left and then send a left button down (to initiate a drag action) and then send a right action the mouse pointer moves a lot further than it should (probably around 1.75 times more than expected).
Has anyone came across this before and have any solutions to it?
TIA,
Andy
|
|
|
|
|
further to this, i've since found that its only the first movement that appears to be incorrect. After that every movement is consistent to the anticipated results.
Does anyone have any ideas why the first one would be different? (the same code is used for all of the movements)
TIA
|
|
|
|
|
Hello all,
Does anyone know ho can I stop the MSSQLSERVER service?
Thanks in Advance!
|
|
|
|
|
Hi
How to convert from 'class _variant_t' to 'struct tagVARIANT *'
Bye
|
|
|
|
|
Does this works ?
VARIANT *pVar;
_variant_t var;
pVar=&(var.Detach());
~RaGE();
|
|
|
|
|
Hello, everyone!
When I compile my project in Debug mode, the compiler tell me :
"error C2601: syntax error: identifier '_DebugHeapTag'"
The error from fstream, it's C++'s standard header, I donn't know
how to resolve it,
Who can tell me, Thanks a lot!
|
|
|
|
|
I wonder how to convert a string from CString(MFC) to LPTSTR. I want to use my string in CString as a LPTSTR but i don't know to convert it.Please help me!
Thanks a lot
|
|
|
|
|
In case you can do with a LPCTSTR (which in most cases is safer), you can easily convert a CString to a LPCTSTR, the CString class provides an operator CString::operator LPCTSTR to achieve that.
CString MyCString;
LPCTSTR mystring=MyCString.operator LPCTSTR();
To force the conversion to a non constant string, use the GetBuffer and ReleaseBuffer functions.
~RaGE();
|
|
|
|
|
Thanks for your helping me. But I don't want to return a LPTSTR, not a LPCTSTR.Anyway, thanks you a lot.
|
|
|
|
|
CString already provides such an operator...
CString str = "Hello you";
char* pszTxt = (LPTSTR)str;
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Thanks for your answering, but when I try doing the following code
LPTSTR CMainDlg::XuLyChuoi()
{
char *tmp_sz = new char[1000];
::GetWindowText(GetDlgItem(IDC_EDIT1),tmp_sz,1000);
CString s = tmp_sz;
int index = 1;
while ((index=s.Find("x", index)) != -1)
{
CString s1 = s[index-1];
s1+= s[index];
CString s2 = s[index-1];
s2+= "*";
s2+= s[index];
s.Replace(s1, s2);
}
tmp_sz = (LPTSTR)s;
return tmp_sz;
}
I have the error:
error C2440: 'type cast' : cannot convert from 'class WTL::CString' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
- 1 error(s), 0 warning(s)
Can you explain?Thank you.
|
|
|
|
|
put aroud your literal string some _T() because you seem to use UNICODE...
and also declare tmp_sz as a TCHAR* , not a char*
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
thanks again, but it still give me that error.
|
|
|
|
|
LPTSTR CMainDlg::XuLyChuoi() {
TCHAR* tmp_sz = <font color=blue>new</font> TCHAR[1000];
::GetWindowText(GetDlgItem(IDC_EDIT1), tmp_sz, 1000*<font color=blue>sizeof</font>(TCHAR));
CString s = tmp_sz;
<font color=blue>int</font> index = 1;
<font color=blue>while</font> ((index = s.Find(_T(<font color=gray>"x"</font>), index)) != -1) {
CString s1 = s[index-1];
s1 += s[index];
CString s2 = s[index-1];
s2 += _T(<font color=gray>"*"</font>);
s2 += s[index];
s.Replace(s1, s2);
}
::_tcscpy(tmp_sz, (LPTSTR)s); <font color=green>
<font color=blue>return</font> tmp_sz;
}
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Not relating to the use of strings or conversion etc, but it looks to me like you have a chance of memory leakage here.
You allocate memory for the string on the heap, then copy this into a CString. Later on you change the pointer to point to the LPTSTR of the CString (I think it should maybe be LPCTSTR, as casting a CString will probably only be safe if cast to a const - which may explain the error you're getting).
This means that you lose the memory you allocated at the start of the function, as nothing's pointing to it any more. Also, you're returning a pointer to something which is about to be deleted (the CString will be deleted when you exit the function).
I think what you actually should be doing (tho' feel free to correct me) is to copy the contents of the CString into the address pointed to by tmp_sz, and then return the tmp_sz pointer. Just remember that you need to later on delete the pointer that you're returning.
So your last bit of code would do something like:
strcpy(tmp_sz, (LPCTSTR)s, s.GetLength());
return tmp_sz;
After making sure that the length of CString s is not > 1000 (including the NULL terminator).
Does that make sense? I'm speed-typing coz it's lunchtime and I'm hungry.
|
|
|
|
|
Doing the following would work.
strncpy (tmp_sz, s, 1000);
tmp_sz [999] = 0; // strncpy doesn't place a null on a full buffer
return tmp_sz;
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
cauvang wrote:
convert a string from CString(MFC) to LPTSTR
Are you certain that your CString is an MFC CString?
I ask this because in the more detailed answer your gave toxcct here[^] looks like your using a CString defined in a namespace called 'WTL' which could indicate that it's all about the WTL version of CString you are using. I don't know anything about WTL so I won't be able to guide you there.
Check this out. If you're not using the MFC version our answers won't make sense.
Perhaps you even should post your question in the WTL forum.
--
Roger
|
|
|
|