|
Can i just seek to position <filesize-128> and write a null char?
|
|
|
|
|
In WIN32, the API is SetEndOfFile
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
redeemer wrote:
Can i just seek to position and write a null char?
NUL characters do not terminate a file. You would have to either truncate the file at (length - 128 ), or fill the last 128 bytes with some characters.
Peace!
-=- James.
"Fat people are hard to kidnap."
(Try Check Favorites Sometime!)
|
|
|
|
|
Your Best bit is to use GetFileSize() to get the file size and assign it to a DWORD then subtract 128 from this DWORD then pass the DWORD to SetEndOfFile().
Peter
|
|
|
|
|
Is that not what I said:
You would have to either truncate the file at (length - 128 )[...]
Peace!
-=- James.
"Fat people are hard to kidnap."
(Try Check Favorites Sometime!)
|
|
|
|
|
I have a more identical propert page and it is necessary for me to change caption for each of them!
How it to make?
Best regards,
Eugene Pustovoyt
|
|
|
|
|
Hi Eugene,
You might glean the information you need from the following article: Hacking the CPropertySheet. Try scrolling down to "Changing the Tab Label". Hope this helps.
- Jason
(SonorkID 100.611)
"I just recieved an email from myself but I didn't send it ?"
- Colin Davies, Sonork conference
|
|
|
|
|
I tried, but a method
TC_ITEM item;
item.mask = TCIF_TEXT;
item.pszText = "New Label";
pSheet.GetTabControl()->SetItem (0, &item);
causes a mistake of the program
Eugene Pustovoyt
|
|
|
|
|
What you're showing is what I have in the MFC book I wrote and certainly works in all my code. Try this simply because it has a couple of ASSERTs and VERIFYs that might tell you where the problem occurring.
(By the way, this code needs to be in your CPropertySheet class)
CTabCtrl* pTab = GetTabControl();
ASSERT(pTab);
TC_ITEM ti;
char szText[100];
ti.mask = TCIF_TEXT;
ti.pszText = szText;
ti.cchTextMax = 100;
VERIFY(pTab->SetItem(0, &ti));
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
|
|
|
|
|
Thank you Tom and thank you Jason
for Your the help, I have made it
Best regards,
Eugene Pustovoyt
|
|
|
|
|
hi all. i'm trying to sort my tree item, which are file names by type, by date, by size or by name. so i called csortchildrencb to sort them. but first of all i want all the folder name at the begining of the tree and the all the files name to be below. so i wrote my callback function like below. but i dont really know how csortchildrencb sort the tree items. and i could not able to get all the folder on the top and the files below. right now folder and file are still mixing. what should be change in callback function??
i'm not sure lParam2 is comparing to lParam1 or lParam1 is comparing to lParam2?
<br />
<br />
CTreeCtrl *myTreeCtrl;<br />
static int CALLBACK MyCompareProc1(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)<br />
{<br />
<br />
CTreeCtrl *pmyTreeCtrl = (CTreeCtrl*) lParamSort;<br />
FileInfo *file1 = (FileInfo*)lParam1; <br />
FileInfo *file2 = (FileInfo*)lParam2;<br />
int compare;<br />
<br />
if(file2->status == FOLDER && file1->status == FILE)<br />
{<br />
compare = 1; <br />
}<br />
else if(file2->status == FOLDER && file1->status == FOLDER)<br />
{<br />
compare = file2->name.Compare(file1->name);<br />
}<br />
else if(file1->status == FILE && file2->status == FILE )<br />
{ <br />
compare = file2->type.Compare(file1->type);<br />
}<br />
<br />
return compare;<br />
<br />
}<br />
<br />
<br />
void CSMPprojectDlg::SortTreeItem()<br />
{ <br />
myTreeCtrl = &m_TreeCtrl;<br />
TVSORTCB tvs; <br />
tvs.hParent = m_TreeCtrl.GetRootItem();<br />
tvs.lpfnCompare = MyCompareProc1; <br />
tvs.lParam = (LPARAM)myTreeCtrl; <br />
m_TreeCtrl.SortChildrenCB(&tvs); <br />
<br />
}<br />
<br />
void CSMPprojectDlg::SortingAtree()<br />
{<br />
SortTreeItem(); <br />
}<br />
<br />
class FileInfo<br />
{<br />
public : <br />
int status;<br />
CString name;<br />
CString size;<br />
CString createdTime;<br />
CString lastWrite;<br />
CString lastAccess;<br />
CString type;<br />
};<br />
<br />
thanks..
|
|
|
|
|
You are not handling the case file1->status == FOLDER && file2->status == FILE .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
still not doing so..
still can't find reason yet.
<br />
static int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)<br />
{<br />
CTreeCtrl *pmyTreeCtrl = (CTreeCtrl*) lParamSort;<br />
FileInfo *file1 = (FileInfo*)lParam1; <br />
FileInfo *file2 = (FileInfo*)lParam2;<br />
int compare;<br />
<br />
CString p;<br />
<br />
if(file2->status == FOLDER && file1->status == FILE)<br />
{ <br />
compare = 1;
}<br />
else if(file1->status == FOLDER && file2->status == FILE)<br />
{<br />
compare = -1;
}<br />
else if(file1->status == FOLDER && file2->status == FOLDER)<br />
{<br />
compare = file2->name.Compare(file1->name);
}<br />
else if(file2->status == FILE && file1->status== FILE)<br />
{<br />
compare = file2->name.Compare(file1->name); <br />
} <br />
<br />
return compare;<br />
}<br />
<br />
void CSMPprojectDlg::SortTreeItem(HTREEITEM hItem)<br />
{ <br />
CTreeCtrl *myTreeCtrl;<br />
myTreeCtrl = &m_TreeCtrl;<br />
<br />
TVSORTCB tvs; <br />
tvs.hParent = hItem;<br />
tvs.lpfnCompare = MyCompareProc; <br />
tvs.lParam = (LPARAM)myTreeCtrl; <br />
m_TreeCtrl.SortChildrenCB(&tvs); <br />
<br />
}<br />
<br />
void CSMPprojectDlg::SortingAtree(HTREEITEM hItem)<br />
{<br />
while(hItem != NULL)<br />
{<br />
if(m_TreeCtrl.ItemHasChildren(hItem))<br />
{<br />
SortTreeItem(hItem);<br />
SortingAtree(m_TreeCtrl.GetChildItem(hItem)); <br />
}<br />
hItem = m_TreeCtrl.GetNextSiblingItem(hItem);<br />
}<br />
}<br />
|
|
|
|
|
I'm sorry I couldn't be more hepful, but it seems all OK to me. Try inspecting the code of PJ Naughter's CTreeFileCtrl, his control does the kind of sorting you're after.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have a dialog class that will allow multilple windows to exist at one time. I would like to have the first window come up and stay up as it already does. Then another selection will popup another dialog window. Then if another dialog is to popup the last dialog is closed.
Anyone have any clues on this?
Than ks
|
|
|
|
|
Are the dialogs to behave in a modal fashion (i.e. user input is blocked for all of them except the active one)? If not so, have an invisible parent dialog orchestrate the ins and outs of the other. Popup dialogs should be childs of the hidden parent.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have this thread that sits doing recv()'s and kicking out data packets; the main application is running in another thread getting on with doing its stuff.
So:
is my "recv() thread" eating lots of CPU time, or is this a nice efficient way of doing things?
(& can you direct me to a webpage or something that actually says this is the case! I've looked at about a million descriptions of what blocking IO is and none tell me what I want..)
and:
any idea how i can terminate my "recv() thread"?
currently if a client is connected, the recv() function blocks until the client sends something; this is great until i want to kill my server application - if the client is still connected, the server's "recv() thread" currently wont die.
(I know I could for example send() to the client & tell it to send() me back some data to wake the recv() function up, but that seems a little poxy).
Thanks in advance to anyone who takes the time to reply
|
|
|
|
|
Unless there is something you are not telling us, such as you have set the socket non-blocking, recv should block and not eat up any significant CPU time until there is data available. Do you have some indication that your recv thread is eating lots of CPU time?
As for your second question, I was going to tell you about WSACancelBlockingCall, but I see it is no longer supported. (I wonder what they were thinking. This was a useful mechanism.) You might try closing the socket from another thread (your main thread, for instance) to see if that unblocks the recv. The only alternatives that I can think of involve using some form of select().
|
|
|
|
|
When recv is blocked waiting for more data, it does so in an efficient manner, you shouldn't note an increase in CPU usage --so if that's the problem, it lies somewhere else.
As for how to terminate a blocking recv a simple and dirty way is to closesocket the socket the call is waiting on (recv will return with an error.)
If you have time and interest in redisigning your app, some other types of sockets are possible:- Non-blocking sockets, handled thru
select .
- Asynchronous sockets managed thru windows messages (see
WSAAsyncSelect .)
- Asynchronous sockets managed thru events (see
WSAEventSelect .) All of them are better fit to make up a design involving premature termination.
You can find much more (and better) info than fits in this post in Warren Young's Winsock Programmer's FAQ.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I think this is an efficient way, but I cannot point you to a web page that says so. I do this all the time, and cpu usage is miniscule.
Re: recv(): I have a loop in a separate thread that does a socket accept(), and I have a similar problem--how do I tell that thread to stop? When I'm ready to stop, in the main thread I close the socket that the accept is waiting on. The accept returns with an error. That thread checks to see if the main thread has asked it to stop (global variable accessed through a function), and ends.
That sounds pretty severe to me (that is, closing the socket out from under the accept), but it seems to work well. I suspect it might work fine with the recv, as well.
Hope this helps.
mflanagan@MJFlanagan.com
|
|
|
|
|
Thanks for the info!
Re: your accept() problem/ solution:
I had this problem too:
My CSocketServerThing class starts up a thread in its constructor;
the thread sits doing a socket accept()
now, say no one connects, and my CSocketServerThing destructor is called - it had no way to terminate its "accept()-blocked" thread;
My solution (i say "my", i nicked it off a newsgroup is to have my destructor:
set a boolean that the "accept()-blocked thread" can see to indicate destructor has been called;
create a temporary client that connects to the blocked "accept()" thread's socket
(this unblocks the accept() thread, which then checks the bool: "ohno!" it thinks, "destructor call! I wont bother doing anything else then!" and so my thread terminates which is what i want)
close my temporary client
This means the accept() call does its stuff (instead of having the socket closed from under it) and the thread terminates gracefully.
I'm not too good @ explaining... I can send you the (currently hackish) source if you want, mail me on uviolets@icqmail.com if interested.
Thanks again,
5th
|
|
|
|
|
Thanks everyone so far, nice to see someone out there understands this sockets guff
re my "recv() thread": no, it doesnt appear to be eating CPU cycles, everything looks fine
(
my reason for asking was I have a very fast PC and its not doing much else other than running my sockettest program ATM, so i was worried I was using CPU and not noticing (I didnt want it to come back & bite me later on when I'm doing lots of intensive compression stuff )
)
- so I'm happy to have you confirm its a nice efficient way of doing stuff.
re killing the thread: i thought of just doing a close(), but it seemed a little harsh, but if thats what you reccomend I'll give it a go (main worry was handle/ resource leakage: I've no tools to show such leaks & I dont personally know enough about sockets to know if principle is sound)
Thanks again & I'll keep an eye on the thread in case anyone else has further gems of wisdom
|
|
|
|
|
I have the CMainFrame class derived from the CMDIFrameWnd and I'm trying to handle the WM_SIZE message. I added the function to my code and without any modifications to the code provided by the wizard, my application acts all screwy. By that I mean, I have the Main Fram maximize on startup but the application doesn't draw correctly. In Theory, I guess it's maximized since the Minimize, Resize, and Close buttons are in the upper right hand corner of my screen and I can grip the frame in the bottom right hand corner to resize the application, but the window seems to think it's not maximized. If I click the Resize button in the upper right hand corner, the window draws correctly. Other than that, it doesn't work correctly. Not sure if I'm explaining this well enough for someone to understand what the hell I'm talking about. I hope I have and I hope someone will have some information for me.
|
|
|
|
|
In your OnSize() method, are you calling the base class implementation? If not, yeah, things are gonna look pretty bad.
--------
Higher education helps your earning capacity. Ask any college professor. --Shog9 --
|
|
|
|
|
I know I can do -
CMenu* m_mMenu = AfxGetMainWnd()->GetMenu();
to get a pointer to the main menu, but how do I get a pointer to the specific menu in my FormView?
Ed
|
|
|
|