|
look into the strcpy function
eg:
char* dest[1024];
CString sSource = "testline";
strcpy(dest, sSource);
|
|
|
|
|
I think this should help (I didn't check)
CString strMfc;
string strStl;
strMfc = "Aaaa";
strStl = strMfc; //1st assignment -> simple
strStl = "Bbbbb";
strMfc = strStl.c_str(); //2nd assignment -> use c_str() for char * conversion
Miroslav Rajcic
http://www.spacetide.com
|
|
|
|
|
Hello,
I'm working on a dialog for one of my projects that allows the user to enter various program settings. Since most of the values that must be entered are numerical I have to check them to make sure they are in the right range, etc. I've created integer member variables for every edit box I have on my dialog and set the range on each, however, if the user presses backspace to clear the 0 that is automatically put in the edit box they get yelled at instantly with a very annoying "Please Enter A Number" message box. What I would like to do is change these variables to CStrings and then make sure that all values are exceptable when the user clicks the OK button of my dialog. However, when I create a handle to capture the BN_CLICKED message of the OK button, add some code and run my program, the dialog box remains when the user presses OK. The dialog box is invoked from the rest of the program in an if statement: if (MyDialog.DoModal()==IDOK) ... How can I have my dialog do all necessary value checking when the user clicks OK and still close and return IDOK to the main program? I'm new to the world of MFC and Visual C++ and I haven't had any luck finding anything like this. I really appreciate any help, thanks!
Joseph LeBlanc,
unixd0od@hotmail.com
|
|
|
|
|
Ah - the dreaded M$ screwed up DDX bug.
You make them CStrings, as you thought, and keep the ints as a seperate variable. Hungarian notation is good here, ie m_szValue/m_iValue. Now go to your dialog editor and click on each edit box and add a handler function for EN_CHANGE ( from memory, it's the one that you get when someone types text ).
Now in your handler, UpdateData() to get the value in, parse it and pass the value to the int only if it is valid, but bring up a dialog only if the value given is positively wrong, rather than empty or on the way to being right ( i.e. if you accept 5-100, don't complain about < 100 until user presses OK, as they may have been entering 10, 27, 43, etc ).
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
If you do decide to override the click of the OK Button, the last line of that function should be CDialog::OnOK();
so:
void MyDialog::OnOK()
{
.......... //whatever
CDialog::OnOK();
}
|
|
|
|
|
What I'd like to do is send a simple text e-mail message using whatever default mail settings the user has already set up on their machine with an easy call like:
CreateEmail("User@Somewhere","A Subject Here","Here is the important thing I wanted to send");
I'm writing an MFC app - and heck I can even assume Outlook or Outlook Express will be installed on the user machines if that makes the solution easier. W98, W2K or NT4 are the OS's I need to work with.
What is the easy way to do this - if every virus kid in the world can figure it out, it has to be easier than using 40 lines to talk to MAPI or the other partial solutions /examples I've seen so far. Somewhere I think I must just not be looking for the right function call.
Thanks!
Mark Terrano
|
|
|
|
|
Assuming that you know (or can get) the user's SMTP server name, and can assume that the user is connected to the internet, this article should suit your needs nicely.
http://www.codeproject.com/internet/csmtpconn.asp
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
OK, I am working on an article and I have only one thing to fix: saving. I wrote a simple app that loaded and saved a bitmap in different formats, worked fine. So I went ahead with this:
BOOL CGDIPlusPaintDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
CString name(lpszPathName);
CString ext = name.Right(3);
ext.MakeLower();
CLSID Clsid;
int ret;
if (ext == "jpg")
{
ret = GetCodecClsid(L"image/jpeg", &Clsid);
}
else if (ext == "gif")
{
ret = GetCodecClsid(L"image/gif", &Clsid);
}
else if(ext == "tif")
{
ret = GetCodecClsid(L"image/tiff", &Clsid);
}
else if (ext == "png")
{
ret = GetCodecClsid(L"image/png", &Clsid);
}
else
{
ret = GetCodecClsid(L"image/bmp", &Clsid);
}
if (m_Bitmap->Save(name.AllocSysString(), &Clsid, NULL)!= Ok)
AfxMessageBox("Failed to save");
return CDocument::OnSaveDocument(lpszPathName);
}
It just plain won't work !! I've traced it all through, the save returns Ok, but the file is 0 length. Here's the odd bit. If I hardcode a path like this:
L"c:\\image.bmp"
then it saves fine every time !! Argh !! I know my string is OK, I use the same method to load the files. I know saving is possible, a hard coded path saves. I know my string is correct going in, it creates an empty file at that location. Any suggestions ?
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Since it saves with a hard-coded string, experiment with different ways of passing the filename. T2COLE, CComBSTR, _bstr_t, etc.
--Mike--
http://home.inreach.com/mdunn/
#include "buffy_sig"
|
|
|
|
|
Looks like I get the VB book on my desk next week. I was saving in the Documents OnSaveDocument handler. I didn't delete the call to the base class. Hard coded paths worked because they were not immediately erased by the base classes serialisation attempt.
In my defence, I worked on this at 3 in the morning, having just got up from 2 1/2 hours sleep. Not that this will save me from a fate worse than death - the VB Visual Quickstart Guide.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
I am a C++ programmer with basic VB abilities.
I have a 3rd party Active X container that must be interfaced to our C++ system, here's the basic problem. I need to send to the Active X functions a BSTR*. I am even willing to write a VB wrapper to go around their container so I can pass it BSTR (which I tried). . . . .many questions.
1) How do you convert any basic string type to a BSTR* that VB will understand
or
2) How do you write the parameters for a VB function so that imported as an Active X it will want plain BSTR and not BSTR*
i.e. - this VB function declaration imports as an active X, but then in C++ you must pass in BSTR* (which I can't get to work)
Public Sub PackageFiles(XMLFileName As String, HTMLFileName As String, DropLocation As String)
. . . .
End Sub
|
|
|
|
|
I Ask the point number 1;
CString strOut = _T("aaaaaaaaaaa");
::SysFreeString(*pstrOut);
*pstrOut = strOut.AllocSysString();
return S_OK;
Where pstrOut is BSTR*
Cheers
Carlos Antollini.
|
|
|
|
|
Use the _bstr_t class. It simplifies life.
|
|
|
|
|
I agree with James. It's True!!!
Cheers
Carlos Antollini.
|
|
|
|
|
In order to accept "enter" key in Single Line Edit Box of
of My Dialog I am using
UINT CQSmartEditCtrl::OnGetDlgCode()
{
UINT code = CEdit::OnGetDlgCode();
code |= DLGC_WANTMESSAGE;
return code;
}// OnGetDlgCode
and then I process return Key Like this...
void CQSmartEditCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar == ReturnKey ) // Return Key
{
((CQKernelMainDlg*)GetParent())->OnQGoto();
}
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
everything works fine but DLGC_WANTMESSAGE is making edit box to get
tab and Esc keys also. Which makes dialog not to exit on escape or change
focus on Tab.
How to Handle this situation?
Bad judgement gives Good experience;
Good judgement comes with Bad experience
|
|
|
|
|
How do you display text on the screen that isn't on a form. An good example
of what I'm looking for is the volume control feature on some keyboards.
When you change the volume, a volume indicator is display on the screen.
Does everyone have any suggestions.
|
|
|
|
|
CWindowDC dc(NULL);
dc.SetBkMode(OPAQUE);
dc.SetTextColor(COLORREF())
dc.SetBkColor(COLORREF());
dc.TextOut(x,y,string);
I don't know how refresh the screen again though.....
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Hi all,
I am an experienced programmer in C, VB, PB and done lot of wotk in Oracle etc... I know C++ concepts and synax tough i didn't do much programming in C++.
I started doing VC++ nad was confused using MFC, after some time I came to a conclusion that before doing MFC , I really need to undersand and program Windows using WIN32 API. Am I correct? Is there any books/ material which can teach both. ie starting from WinAPI and taking that o MFC??
|
|
|
|
|
I think you're wrong. I learned MFC first and found it to be a safety blanket, which insulated me from all the things I had to learn when I started to do some Win32 programs. I must admit, I nearly gave up when I first tried to understand the whole Doc/View/where does everything go part of it all, you may prefer to write some dialog based stuff first, and even then it's a little bit of a paradigm shift. I found 'MFC programming with Visual C++ Unleashed' to be a good book, I admit I haven't seen the Microsoft title ( although I own Petzhold, THE Win32 book ). Of course, the fact we are talking means you've already found the *best* resource, a place where you can download existing projects to experiment with and people you can ask if you get stuck.
LEarning Win32 first would be like learning C, then C++. I think it's a bad idea for the same reasons Stroustrup says it's a bad idea to learn C first. It's more complex, and there are more opportunites to shoot yourself in the foot.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
I have to agree with Christian. Although knowledge of WIN32 has proved helpful when programming some MFC implementations, the MFC library is basically a large wrapper class for the WIN32 Architecture and makes almost everything much easier.
|
|
|
|
|
well i agree with them both win32 is very tough and impossible to comprehend sometimes .besides u said u r a C programmer i recommend u this "very beginners" book.. sams teach yourself VC++ in 21 days u'll get started right away from the first chapter and also its is soooo easy to understand the language also the other thing that could help is the most famous MSDN i admit that with that library i learned 80% of what i could do with VC++ also it has that thousands or millions of topics that u could read and learn but as a start choose the most easy thing coz u know one of my friends read petzoldas a begining in win32 programming he is now a great VB programmer with no VC experience
have fun.........
|
|
|
|
|
Whew. I read that as it is written and I am out of breath. Am I the only one who finds posts with 'words' like 'u', 'r', and 'h8' draining to read ? Oh, and lets not forget making our vowels a310u....
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
I'm with you Christian. I decided not to reply to posts containing multiple exclamation marks, 'u', 'r' and the like. The people who use these features must be ^g^g^g^g^g^g ^g^g^g^g^g^g
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Thank you all for your suggessions. Its very valuable, I will again take a shot at going MFC directly. By the way, I am planning to purchase "Programming Windows with MFC (MS Press)", if any one has idea about how is the book?
|
|
|
|
|
When I try to Import data from text file, using DTS Wizard, there appears a protection error message. What that means. Is there something that I have to do before all. I'm using Desktop Edition (MsSQL Server7) under Win98. Any help will be usefull!!!
|
|
|
|