|
tsk - a non-programming question in the programming forums?
What is the world coming to?
Go to the lounge, and say that again, and I'm sure you'll get a few s
(happy birthday, btw. You now get an entire year of the blink 182 "nobody loves you when you're 23" line bouncing around your head or is that just me?...)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
I have a binary file and its got stuff in it that looks like:
10 20 10 30 etc.
What I need to do is replace the first two numbers so that the file looks like:
a b 10 30 ....
Can I trouble you for some sample code that does this? The file extension is something weird....not .txt or anything like that...
Appreciate your help,
ns
|
|
|
|
|
two options
1) Open your file as a binary file - seek to the positions you want to change and write new bytes to it then close the file
2) open your file as a binary file, read in the whole lot to a buffer of bytes, modify the bytes you want to change and write it back and close
Have a look at the CFile docs in MSDN (if you're using mfc, that is)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
A spot of trouble. I dont have a binary file to test it with. But I did this:
void CReadin2View::OnButton1()
{
CFile myFile;
myFile.Open("C:\\abc.dat", CFile::modeReadWrite);
long length = myFile.GetLength();
char * buf[length];
myFile.Read(buf,length);
buf[0] = 'p';
buf[1]= 'k';
myFile.Write(buf,length);
}
Even though I dont have abc.dat yet, it should compile right?
I'm getting errors:
Compiling...
readin2View.cpp
C:\readin2\readin2View.cpp(130) : error C2057: expected constant expression
C:\readin2\readin2View.cpp(130) : error C2466: cannot allocate an array of constant size 0
C:\readin2\readin2View.cpp(130) : error C2133: 'buf' : unknown size
C:\readin2\readin2View.cpp(134) : error C2440: '=' : cannot convert from 'const char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\readin2\readin2View.cpp(136) : error C2440: '=' : cannot convert from 'const char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
readin2View.obj - 5 error(s), 0 warning(s)
Question 2:To make a binary file,
void CReadin2View::OnButton2()
{
CFile myFile;
myFile("c:\\abc.dat", CFile::modeCreate |CFile::modeWrite );
myFile.Write ( <code>....how to write some binary stuff to this file?</code>..)
}
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
char * buf[length];
That should be:
char * buf;
buf = new char[length] (and remember to delete it afterwards - oh, and a myFile.Close() after you've written wouldn't go amiss, either)
ns wrote:
....how to write some binary stuff to this file?..
Easy - just make a buffer exactly the same way as you do in the OnButton1 member (after my fix, ofc), fill in the values to the buffer array, then write it (again in exactly the same way)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
Guess my question is this:
If it were text I'd do
buf[0] = 'y';
buf[1] = 'l';
etc etc,
but I want my file to be binary, so how do I write a binary char, and how does my CFile know that I want a binary file not a text file?
The thing looks like:
10 20 30 40 etc when I open it in a binary editor. SO am I suppodsed to do:
buf[0] = '10';
buf[1] = '20'
For sme reaso n I dont think so....
Whats getting me is that you have flags like 'rb' etc in
(!(fpIn = fopen(inputFile,"rb"))
but I want to use MFC
Appreciate your help,
ns
|
|
|
|
|
in order to accomplish that u need to convert ur binary chars to ascii correspondant check out for this purpose CString::Format (keep in mind using (LPCSTR) operator to get back the char* if needed)
The flags are like CFile::typeBinary of nOpenFlag in ur CFile constructor or Open method
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
OOPs! Do I need to create a new file to write to? Because if I write to the same myFIle what will I get? I dont know if it will overwrite? Or will it append?
Appreciate your help,
ns
|
|
|
|
|
Depends how u create the file:
CFile::modeCreate or CFile::modeReadWrite
check CFile::CFile open flags
ull also need CFile::typeBinary so be sure to pipe it
CFile::typeBinary | CFile::modeReadWrite
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Nope, you don't need to specify typeBinary.
You can find this comment in filecore.cpp:
// CFile objects are always binary and CreateFile does not need flag
and this is what MSDN says:
CFile::typeBinary Sets binary mode (used in derived classes only).
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hello,
I would like to programatically drive the Open file dialog of Office 2000/XP. I therefore got the ID of the edit control where one can enter a filename and was looking for the ID of the OK button to send it a BM_CLICK message.
However the control does not show up in Spy++: when I drag the Finder tool then the dialog is hilited and not the button. What kind of control can this be? ActiveX? Will I be able to send it a BM_CLICK message (or anyhting else that will validate the change I made in the edit with a WM_SETTEXT)? How?
Regards,
mynab
|
|
|
|
|
Spy++ sometimes fails to be able to graphically pick certain controls. Look for it in the tree, it'll be there even tho you can pick it off the screen. There's nothing special about the button. In fact, if it's a OK button, then there's a good change the ID is IDOK.
Joel Lucsy (jjlucsy@concentric.net)
|
|
|
|
|
No the control does not appear in the tree either. Even if I spy all the messages and I move the mouse over the button, then the WM_SETCURSOR messages that appear have the HWND of the dialog. If I move the mouse over the Filename RichEdit then the WM_SETCURSOR has a different HWND... Of course I tried GetDlgItem(IDOK) on the dialog but it returns NULL.
Seems I am really stuck!
|
|
|
|
|
Great! I found one working solution... Instead of clicking the OK button (that I can't find) I simulate a VK_RETURN keypress. Works in Office 2000 ; hoping it works in Office XP!
::SendMessage(pEdit->GetSafeHwnd(), WM_KEYDOWN, VK_RETURN, 0x001c0001);
::SendMessage(pEdit->GetSafeHwnd(), WM_CHAR, VK_RETURN, 0x001c0001);
::SendMessage(pEdit->GetSafeHwnd(), WM_KEYUP, VK_RETURN, 0xc01c0001);
mynab
|
|
|
|
|
Hi all,
I have a "small" problem.
I have an SDI with a CFormView. From the CFormView I open a dialog box
using CDialog::Create with the parent as NULL and ShowWindow.
The problem is that when I click on the CFormView the Dialog box doesn't change its Z-order. It remains on top of my SDI, thus hiding part of the SDI.
Mind you, I wish for the Dialog to remain open.
Is there any way to get over this?
Thanks in advance
Alberto Gattegno
Software Engineer
http://www.itgil.com
|
|
|
|
|
Try with this:
...
p_Dialog->Create(IDD_NEURAL_DIALOG, this);
p_Dialog->ModifyStyle(NULL, NULL, SWP_NOACTIVATE);
p_Dialog->ShowWindow(SW_SHOW);
..
|
|
|
|
|
Nope... No good.
It stays the same: The dialog over the SDI. What I need is the dialog under the SDI.
Thanks anyway.
Alberto Gattegno
Software Engineer
http://www.itgil.com
|
|
|
|
|
A little correction: try with with parent NULL:
p_CDialog->Create(ID_MY_DIALOG, NULL);
This works if you call the dialog from some other dialog window and not from main application!
|
|
|
|
|
Yeah I figured that much out.
I think this is Micro$oft's idea of a twilight zone.
Thanks
Alberto Gattegno
Software Engineer
http://www.itgil.com
|
|
|
|
|
I want manually to horizontal scroll CListBox to the right position.
I change the position of the scroll with:
CListBox* p_CListBox;
..
..
sz = pDC->GetTextExtent(str);
dx = sz.dx;
p_CListBox->SetHorizontalExtent(dx);
dx = p_CListBox->GetScrollLimit(SB_HORZ);
p_CListBox->SetScrollPos(SB_HORZ, dx, TRUE);
..
But now I can't actually scroll the view of the CListBox?
I tryed with the:
SendMessage(p_CListBox->GetSafeHwnd(), WM_HSCROLL, MAKEWPARAM(SB_ENDSCROLL, 0),0);
but no success!
(the view is scrolled correct if I click on scroll with the mouse!)
|
|
|
|
|
The code which works is:
SendMessage(p_CListBox->GetSafeHwnd(), WM_HSCROLL, MAKEWPARAM(SB_PAGERIGHT, 0),0);
but I must sent it number? of times to reach the most right HSlider position!
|
|
|
|
|
Hi.
My application was designed for Win2000 only (I use DirectX 7). And I plan to detect attempt to run this on WinNT4 , because there is error message "The procedure entry point DirectDrawCreateEx could not be located in the dynamic link library DDRAW.dll, but this message show up before WinMain call.
Thanks for advise.
|
|
|
|
|
Afaik you can't run DirectX > 3 on Windows NT 4.0. ( Execute-buffers, you've got to love them... )
-=jarl=-
|
|
|
|
|
I know this, but I need only valid error report, maybe like this:
"This program requiedWin98/2000 only"
I need to detect OS version BEFORE the program say "...Entry Point for DirectDrawCreateEx was not found..."
I think that in DDRAW.dll in DllEntryPoint there is call of DirectDrawCreateEx and i have this error message before Step IN to WinMain
|
|
|
|
|
Oh, sorry, I see. You need to load the DLL manually, ( using LoadLibrary ), then.
-=jarl=-
|
|
|
|