|
Now I can write data from program to text file by using WriteString() and SeekToEnd().
So I want to write program to copy all data within first text file to second text file by using CStdioFile
Do you know how to do that?
Thank you for your answer.
These below is some part of my program to write data from program to text file by using CStioFile
outp_filename = m_uniquecodeFileName;<br />
<br />
CStdioFile EncryptedUniqueCode;<br />
CFileException FileExc;<br />
UINT nOpenFlags;<br />
CString szTemp, m_string;<br />
nOpenFlags = CFile::modeWrite;<br />
if (!EncryptedUniqueCode.Open(outp_filename, nOpenFlags, &FileExc)) {<br />
FileExc.ReportError();<br />
return;<br />
}<br />
EncryptedUniqueCode.SeekToEnd();<br />
<br />
.<br />
.<br />
.<br />
<br />
EncryptedUniqueCode.WriteString(m_string+'\n');<br />
<br />
EncryptedUniqueCode.Close();
|
|
|
|
|
Is there a reason you need to use CStioFile ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Is there the other way to do that? Christian.
If you know how to do that, please tell me.
|
|
|
|
|
If you open one file with an ifstream and the other with an ofstream, you can use getline to read the file a line at a time and then copy it into the new file. Something like:
#include <iostream>;
#include <string>;
...
std::ifstream input("c:\input.txt");
std::ofstream output("c:\input.txt");
std::string s;
while (std::getline(input, s))
{
output << s << std::endl;
}
But that is off the top of my head with no error checking, etc.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
This is more efficient (no parsing needed):
ifstream ifs("in.txt");
ofstream ofs("out.txt");
ofs<<ifs.rdbuf();
Anyway, I think there's no compelling reason not to use ::CopyFile instead.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi.
I have a formview with a tab control. Basically, I would like the formview to show different objects depending on which tab the user activates. I have considered using a lot of if/else and enable/disable the objects, but CTabCtrl is a more elegant solution. Thus I am designing the program around CTabCtrl.
There are three formview classes and one tab control.
ViewMain
theTab
ViewChild1
ViewChild2
I added theTab in formview ViewMain. There is not problem there. However, now I cannot figure out how to correspond ViewChild1 and ViewChild2 to the theTab.
I would like to know, Is it valid to create the two childviews from CFormView? If yes, given the design described above, How do you correspond the two childviews to the CTabCtrl object?
Thanks,
Kuphryn
|
|
|
|
|
kuphryn wrote:
I cannot figure out how to correspond ViewChild1 and ViewChild2 to the theTab.
What Exactly u meant by this...
kuphryn wrote:
Is it valid to create the two childviews from CFormView
Yeah it is Valid
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
Given three formview classes and one with a CTabCtrl object, I want to show either childview1 or childview2 depending on what tab the user clicks.
Kuphryn
|
|
|
|
|
my vb program is as follows
this works fine.
Option Explicit
#If Win32 Then
Private Declare Function SQLAllocEnv Lib "odbc32.dll" _
(phenv As Long) As Integer
Private Declare Function SQLAllocConnect Lib "odbc32.dll" _
(ByVal henv As Long, phdbc As Long) As Integer
Private Declare Function SQLConnect Lib "odbc32.dll" ( _
ByVal hdbc As Long, ByVal szDSN As String, _
ByVal cbDSN As Integer, ByVal szUID As String, _
ByVal cbUID As Integer, ByVal szAuthStr As String, _
ByVal cbAuthStr As Integer) As Integer
Private Declare Function SQLFreeEnv Lib "odbc32.dll" _
(ByVal henv As Long) As Integer
Private Declare Function SQLFreeConnect Lib "odbc32.dll" _
(ByVal hdbc As Long) As Integer
Private Declare Function SQLError Lib "odbc32.dll" ( _
ByVal henv As Long, ByVal hdbc As Long, ByVal hstmt As Long, _
ByVal szSqlState As String, pfNativeError As Long, _
ByVal szErrorMsg As String, ByVal cbErrorMsgMax As Integer, _
pcbErrorMsg As Integer) As Integer
#ElseIf Win16 Then
Private Declare Function SQLAllocEnv Lib "odbc.dll" _
(phenv As Long) As Integer
Private Declare Function SQLAllocConnect Lib "odbc.dll" _
(ByVal henv As Long, phdbc As Long) As Integer
Private Declare Function SQLConnect Lib "odbc.dll" ( _
ByVal hdbc As Long, ByVal szDSN As String, _
ByVal cbDSN As Integer, ByVal szUID As String, _
ByVal cbUID As Integer, ByVal szAuthStr As String, _
ByVal cbAuthStr As Integer) As Integer
Private Declare Function SQLFreeEnv Lib "odbc.dll" _
(ByVal henv As Long) As Integer
Private Declare Function SQLFreeConnect Lib "odbc.dll" _
(ByVal hdbc As Long) As Integer
Private Declare Function SQLError Lib "odbc.dll" ( _
ByVal henv As Long, ByVal hdbc As Long, _
ByVal hstmt As Long, ByVal szSqlState As String, _
pfNativeError As Long, ByVal szErrorMsg As String, _
ByVal cbErrorMsgMax As Integer, pcbErrorMsg As Integer) _
As Integer
#End If
Private Const SQL_SUCCESS As Long = 0
Private Const SQL_SUCCESS_WITH_INFO As Long = 1
Private Function IsValidODBCLogin(ByVal sDSN As String, _
ByVal sUID As String, ByVal sPWD As String) As Boolean
Dim henv As Long 'Environment Handle
Dim hdbc As Long 'Connection Handle
Dim iResult As Integer
'Obtain Environment Handle
iResult = SQLAllocEnv(henv)
If iResult <> SQL_SUCCESS Then
IsValidODBCLogin = False
Exit Function
End If
'Obtain Connection Handle
iResult = SQLAllocConnect(henv, hdbc)
If iResult <> SQL_SUCCESS Then
IsValidODBCLogin = False
iResult = SQLFreeEnv(henv)
Exit Function
End If
'Test Connect Parameters
iResult = SQLConnect(hdbc, sDSN, Len(sDSN), sUID, Len(sUID), _
sPWD, Len(sPWD))
If iResult <> SQL_SUCCESS Then
If iResult = SQL_SUCCESS_WITH_INFO Then
'The Connection has been successful, but SQLState Information
'has been returned
'Obtain all the SQLState Information
If Check1.Value Then ShowSQLErrorInfo hdbc, vbInformation
IsValidODBCLogin = True
Else
'Obtain all the Error Information
If Check1.Value Then ShowSQLErrorInfo hdbc, vbExclamation
IsValidODBCLogin = False
End If
Else
IsValidODBCLogin = True
End If
'Free Connection Handle and Environment Handle
iResult = SQLFreeConnect(hdbc)
iResult = SQLFreeEnv(henv)
End Function
Private Sub Form_Load()
Text1.Text = "DSN"
Text2.Text = "User ID"
Text3.Text = ""
Text3.PasswordChar = "*"
Command1.Caption = "Test Connect"
Check1.Caption = "Return Errors and Warnings"
End Sub
Private Sub Command1_Click()
Dim sServer As String, sLogin As String, sPassword As String
sServer = Text1.Text
sLogin = Text2.Text
sPassword = Text3.Text
If IsValidODBCLogin(sServer, sLogin, sPassword) = True Then
MsgBox "Connection Successful", vbInformation, "ODBC Logon"
Else
MsgBox "Connection Failed", vbExclamation, "ODBC Logon"
End If
End Sub
Private Sub ShowSQLErrorInfo(hdbc As Long, iMSGIcon As Integer)
Dim iResult As Integer
Dim hstmt As Long
Dim sBuffer1 As String * 16, sBuffer2 As String * 255
Dim lNative As Long, iOutlen As Integer
sBuffer1 = String$(16, 0)
sBuffer2 = String$(256, 0)
' Do 'Cycle though all the Errors
iResult = SQLError(0, hdbc, hstmt, sBuffer1, lNative, sBuffer2, _
256, iOutlen)
If iResult = SQL_SUCCESS Then
If iOutlen = 0 Then
MsgBox "Error -- No error information available", _
iMSGIcon, "ODBC Logon"
Else
MsgBox Left$(sBuffer2, iOutlen), iMSGIcon, "ODBC Logon"
End If
End If
' Loop Until iResult <> SQL_SUCCESS
End Sub
where as my VC ++ program is
this program doesn't work
void main()
{
SQLHENV m_SQLEnvironment;
SQLHDBC m_SQLConnection;
SQLRETURN iReturn;
// Obtain Environment Handle
iReturn = SQLAllocEnv(&m_SQLEnvironment);
if (iReturn != SQL_SUCCESS)
printf("Error in Allocating Environment");
// Obtain Connection Handle
iReturn = SQLAllocConnect(m_SQLEnvironment,&m_SQLConnection);
if (iReturn != SQL_SUCCESS)
{
printf("Error");
iReturn = SQLFreeEnv(m_SQLEnvironment);
}
//Test Connect Parameters
iReturn = SQLConnect(m_SQLConnection,(SQLCHAR*)"OraTest",SQL_NTS,(SQLCHAR *)"scott",SQL_NTS,(SQLCHAR *)"tiger",SQL_NTS);
if (iReturn != SQL_SUCCESS)
{
if (iReturn == SQL_SUCCESS_WITH_INFO)
{
// 'The Connection has been successful, but SQLState Information
// 'has been returned
// 'Obtain all the SQLState Information
// If Check1.Value Then ShowSQLErrorInfo hdbc, vbInformation
// IsValidODBCLogin = True
printf("Connected");
}
else
{
// 'Obtain all the Error Information
// If Check1.Value Then ShowSQLErrorInfo hdbc, vbExclamation
// IsValidODBCLogin = False
printf("Failed Connecting");
}
}
else
{
//IsValidODBCLogin = True
printf("Connected");
}
//'Free Connection Handle and Environment Handle
iReturn = SQLFreeConnect(m_SQLConnection);
iReturn = SQLFreeEnv(m_SQLEnvironment);
}
can anyone figure out the problem.
its urgent
|
|
|
|
|
r u copying same code to VC?? if yes then of course it will give errors.
|
|
|
|
|
the VC++ program is attached under the VB program asked in the question
try that first and then answer please.
i understand that vb code doesn't work in vc
that is why i gave the vb and also the vc code attached.
|
|
|
|
|
You can't mix VB code and C++ code!
If it was possible... I would go to hell!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
vc code is also attached below the VB code
|
|
|
|
|
cant find WM_SETFOCUS for my dialog from class wizard for some reason.
I can find WM_KILLFOCUS however...?
it's a dialog application btw. Thanks
norm
|
|
|
|
|
Go to the last page of the wizard - there's a combo that lets you select which messages you want displayed. Set it to "window" and you should see all the messages.
Shog9
------
So they took me down to the gallows
And this boy, he said to me:
"Why do you smile, when the rope's around your neck?"
I said, "I tell you boy, when i get back..."
|
|
|
|
|
I've found it. I added two event handlers:
1. one for WM_SETFOCUS
2. one for WM_KILLFOCUS
My intention is that when my dialog application loses focus, the dialog will become more transparent. When the dialog gets focused, the dialog becomes more opaque.
But it seems that my dialog does not respond to the event WM_SETFOCUS and WM_KILLFOCUS for some reason. Are these two events for controls only? But from MSDN, it seems that these two messages are generic "windows" message. And a dialog is a window...?? And I dont want to use mouse leave event neither...
Thanks!
norm
|
|
|
|
|
Check out WM_ACTIVATE ...
Shog9
------
So they took me down to the gallows
And this boy, he said to me:
"Why do you smile, when the rope's around your neck?"
I said, "I tell you boy, when i get back..."
|
|
|
|
|
yes, someone from CodeGuru already suggested to me to use WM_ACTIVATE (get focused), but what about WM_DEACTIVATE (lose focused)?
norm
|
|
|
|
|
Ok. First, the window that has focus and the active window are two different (though related) things, at least on Windows. Second, WM_ACTIVATE gets sent to both the window being activated and the window being deactivated; a flag is passed along with it to allow them to distinguish which is which. See MSDN for details...
Shog9
------
So they took me down to the gallows
And this boy, he said to me:
"Why do you smile, when the rope's around your neck?"
I said, "I tell you boy, when i get back..."
|
|
|
|
|
thanks! i was silly enuf to spend all the time looking for WM_DEACTIVATE while WM_ACTIVATE is dispatched under both circumstances...
anyway, thanks, it's working now.
norm
|
|
|
|
|
Shog9 wrote:
a flag is passed along with it to allow them to distinguish which is which.
Gawd, I'm such a dork for not reading the manual ... I've been doing a lot of junk code just to do this !
Thanks!
Max.
|
|
|
|
|
how can u remove your application from taskbar?
thanks
norm
|
|
|
|
|
|
trying to draw on top of a button
CRect * prtExit = NULL;
CDC * pExitDC = NULL;
CWnd * pbtnExit = this->GetWindow(IDC_EXIT);
pExitDC = pbtnExit->GetDC();
pbtnExit->GetClientRect(prtExit);
pExitDC->TextOut( prtExit->left+5, prtExit->top+5, "Testing");
//I understand we dont need to text out and there's simpler way to do this, but I am just testing to see if I have control over the device context of a button. I was going to load a bitmap (I also know about BM_SETIMAGE...)
Anyway, the code crashed: "The memory could not be read".
By the way, this is done in dialog class constructor... is it possible that the button has not been constructed yet...?
norm
|
|
|
|
|
just tried to render a bitmap on face of a button, crashed the very same way: memory access:
HBITMAP h_bmpExit = NULL;
h_bmpExit = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), "./res/StopButton.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if(h_bmpExit==NULL)
{
//Additional error handling here!
}
pbtnExit->PostMessage(BM_SETIMAGE, IMAGE_BITMAP, (LPARAM) (HANDLE) h_bmpExit);
norm
|
|
|
|
|