|
I need to find out how to open\write to a file and then close it. I just need to record the time at point 1 to the file and the record the second point 2 time. I have the time variable in one variable. Please and I will be very thankful for your help.
[It is possible to represent everything in this universe by using 0 and 1]
I'm going to live forever or die trying.
|
|
|
|
|
If you use MFC, you can use the CFile Class.Open,Close or Write Class Members are there. If you want a File Dialog you can use CFileDialog. Also there is the CStdioFile Class.
CStdioFile CalFile("YourFileName.dat",CFile::modeCreate | CFile::modeWrite | CFile::typeText );<br />
CalFile.WriteString(Time1.Format("%H,%M,%S"));
CalFile.WriteString("\n");
CalFile.WriteString(Time2.Format("%H,%M,%S"));<br />
CalFile.Close();
|
|
|
|
|
I'm new to programming.I received some code: the aim is that the commands are send with the socket-method, and then execute a console program, using the pipe-method. The code is rather long, so here is the fragment with the fault. I tried the following code : (with the aim to find the entire string that I typed in 'char kk', so I could compare it with another string like "help" or "howlong"...)
//////
{
long lEvent=WSAGETSELECTEVENT(lParam);
UINT r;
static char buf[MAXRECVBUF];
DWORD dwNumberOfBytesWrite;
SOCKET sock_tmp;
if (lEvent==FD_ACCEPT){
// "Accept" handler
SOCKADDR_IN clientAddr;
int nClientAddrLen=sizeof(clientAddr);
// Accept connection
if ((sock_tmp=accept(sock_listen,(LPSOCKADDR)&clientAddr,&nClientAddrLen))==INVALID_SOCKET){
if (WSAGetLastError()!=WSAEWOULDBLOCK) return;
}
if (NowUsing==TRUE){
closesocket(sock_tmp);
return;
}
sock=sock_tmp;
send(sock,BANNER,strlen(BANNER),0);
NowUsing=TRUE;
// Boot shell program
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
CreatePipe(&hPipeOutputRead,&hPipeOutputWrite,&sa,5000);
CreatePipe(&hPipeInputRead,&hPipeInputWrite,&sa,5000);
memset((void *)&si,0,sizeof(si));
memset((void *)&pi,0,sizeof(pi));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.wShowWindow = SW_SHOW;
si.hStdInput = hPipeInputRead;
si.hStdOutput = hPipeOutputWrite;
si.hStdError = hPipeOutputWrite;
CreateProcess (NULL,SHELL_NAME,NULL,NULL,TRUE,0,NULL,START_DIR,&si,&pi);
CloseHandle(hPipeOutputWrite);
CloseHandle(hPipeInputRead);
// Create character read&send thread
hThread_out = CreateThread(NULL,0,OutputToSocket ,NULL,0,&dwChildThreadIdOut);
return;
}else if (lEvent==FD_CLOSE){
// "Close" handler
closesocket(sock);
TerminateProcess(pi.hProcess,0);
TerminateThread(hThread_out,0);
CloseHandle(pi.hProcess);
CloseHandle(hPipeOutputRead);
CloseHandle(hPipeInputWrite);
NowUsing=FALSE;
return;
}
/////start problem-code//////
// Recv packet from client and write to SERVER.EXE
if ((r=recv(sock,(LPSTR)buf,MAXRECVBUF,0))==SOCKET_ERROR) {return;}
kk[i]=buf[0];
kk[i+1]='\0';
MessageBox(NULL,kk,"speciale functie uploaden en zo",MB_OK);
i=i+1;
WriteFile(hPipeInputWrite,&buf,r,&dwNumberOfBytesWrite,NULL);
/////end problem-code//////
}
/////
But now the messagebox always returns:
when I type the 1st character: the first character
when I type the 2nd character: the first character is now a trash character and the second is the character I typed
when I type the 3rd character: the first two character's are now trash character's and the third is the character I typed
...
What should I do so that I can find only the string I typed in "kk", without the trash??
|
|
|
|
|
Hi,
In my app I have to put some bitmamps in RichEditCtrls as Ole Objects. I load the bitmaps at the start of the application and I use OleCreateFromFile to create the object from the bitmap file.
The problem that I have is there are too many images (over 25) and the loading process takes about 7 seconds. If I load them in the main thread, the applications seems dead. You can't move the window, can't minimize it...
I tried to load the images in a separate thread but with the same code the OleCreateFromFile returns an error: "The system cannot find the specified file" altough if I make an fopen in the same thread I can read that file.
Do you know something about this? Am I doing something wrong?
Thanks
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
I have a QUESTION!
I'd just finished building a simple program.
All the while it works..
and now suddenly when i compile it.. no errors and no warnings..
but after i Build it...its ok...everythings fine..
But when i EXECUTE it (Ctrl+F5)..
nothing happened!!
it didnt load at all..no warnings...no errors...just didnt load like it used to!!!
can anyone help me?
thanks
-thong-
twh81@tm.net.my
...
|
|
|
|
|
colormyiris wrote:
can anyone help me?
Use F5 instead of Ctrl+F5.;)
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Does it not load, or does it load, run and close so quickly you can't see it? I've sometimes found this when there is an error in the initialisation code that causes the application to close before it does anything.
Hopes this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Is there a way in MFC to control the background color of each item in a listbox. I've seen some custom controls that will do it but I would just like to use the standard listbox.
|
|
|
|
|
No, not without doing an ownerdraw listbox. There are examples here on CP.
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
Hi,
Thank you for checking out my post.
I am writing a simple CPropertySheet (with property pages of course) VC++ 6 Doc/View application, and I want to change the look of the OK or CANCEL buttons.
Trouble is that I don't seem to be able to create a control variable of either buttons. The buttons are provided by the framework I am thinking, but does anyone know how to access them?
The only interaction I have with the Cancel or OK buttons is to check the return value when dlg.DoModal() returns and that is it.
Thanks for any suggestions.
Michael
|
|
|
|
|
In the property sheet class, you can call GetDlgItem(IDOK) to get a CWnd* on the OK button. Change IDOK to IDCANCEL for the Cancel button.
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Hi Mike,
Thank you so much for replying. I seem to recognize your name...I think you have kindly helped me in the past.
Anyway, I did try GetDlgItem(ID_OK) before I posted my question and I couldn't get it to work. It must be the way I did it. It would compile ok but crash on running when doing the check "ASSERT(::IsWindow(m_hWnd));". Here's the code I used within my CPropertySheet class's constructor :-
CMyPropertySheet::CMyPropertySheet(LPCTSTR pszCaption,
CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
//add each page to the propert sheet
this->AddPage(&this->m_prop_page1);
//get pointer to OK button so I can alter it
CButton * pbutton = (CButton *)this->GetDlgItem(IDOK);
}
Actually, as I write this I realize that maybe the propertySheet is not a window (and that includes the OK button) until I run "property_sheet_obj.DoModal()", so that might be the problem right there. Do I have to alter the OK button after the DoModal().....I will try that.
Thanks Mike and thank you all for any suggestions or confirmation.
Michael
|
|
|
|
|
No windows are created until after DoModal(), so it might be easiest to do the change in the first page that gets shown:
CPropertySheet* pSheet = (CPropertySheet*) GetParent();
CWnd* pOKBtn = pSheet->GetDlgItem(IDOK);
pOKBtn->SetWindowText ( _T("'Aight") );
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
|
I'm about to create a Word like replacement for my self, Word doesn't have CD-R burning features/XML format/Templates (HTML)/portiblility from comp to comp that i need so I'm going to make a replacement. Possibly if it is built right I'll sell copies. To start out how should I CFormView or CRichEdit?
Also I'm courious about how to include an Intelisense Like feature in a RichEdit/Edit box.
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
|
Nope, I've had a teacher that specifily requested Arial font, 1inch margins, specific headers etc. and my other teachers hated format. Instead of modifing the default and going against it, used XML and my CMS (ltpb.8m.com/XMLHTML[^]) and it worked well, I can take all of my work from the year on a floppy disk, including the data, templates (which preserve the formating) and programs I can use it almost anywhere. Also computers at school are a niche for macro and other viruses. Plus, I don't want to have to bother with O97/2k/2k3 incompatibilities.
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
I'm not sure you realize what you're proposing. Word required hundreds of developers and years to create.
If you wish to use MFC, the proper way to start is not with CFormView or CRichEdit -- but with CWnd (doing everything from scratch). I seriously doubt that Edit or RichEdit controls would be modifiable to do what you want.
A couple suggestions:
- IE provides a DHTML Editor.
- OpenOffice[^] -- has a Word clone with cross platform source.
Perhaps one or the other could be modified to do what you want.
|
|
|
|
|
Who ever thinks they can get a word processor is really high on something cause you would have alot of time and man power. You could just make a program like notepad but wordpad would still be hard to do. []_.(()).[]_.
[It is possible to represent everything in this universe by using 0 and 1]
I'm going to live forever or die trying.
|
|
|
|
|
snyp wrote:
[...]is really high on something[...]
Probably the same stuff that my management uses...
snyp wrote:
[It is possible to represent everything in this universe by using 0 and 1]
But not necessarily with a number of digits less than unlimited....
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Ever heard about LaTeX to write reports ?
~RaGE();
|
|
|
|
|
How do I make a dialog box in my MFC SDI app behave like a AutoHiding dialog box in vs.net? (with the tab on the side)?
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
If you are interested, there are a few libraries out there that can do this for you. One I found that is very good is Xtreme Docking Pane.
See: http://www.codejock.com/products/dockingpane/.
Very affordable and comes in MFC, ActiveX and .NET Windows Forms.
Cheers,
Scott Evans
|
|
|
|
|
Hi
I am looking for some good UI and a place to buy components. I know of:
http://www.componentsource.com
http://www.programmersparadise.com
Most of the components are good but is there one focused site that concentrates on MFC/C++ components? And what do you guys think of the CodeJock library as that is the one I am closely looking at purchasing After reading the CP review and such.
Your thoughts or recommendations would be greatly appreciated.
Code4Food
----
"There is no try; only do or do not"
-Yoda
|
|
|
|
|
BCGControlBar is excellent. Very similar to CodeJock, high quality, and cheaper.
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|