|
I'm looking for some VS c++ code that 1) preallocates a file 2) opens a preallocated file for sequential writing starting at the beginning of the file 3) writes(appends) ascii message strings to the file. Thanks
|
|
|
|
|
I'm not sure exactly what you mena by point 1, but opening a file for appending is quite straightforward, and writing text is even more so. Take a look at the STL file stream classes[^] or use the Createfile[^] and associated functions.
I must get a clever new signature for 2011.
|
|
|
|
|
You need to seek to what you want to be the end of the pre-allocated space, then set the EOF marker, then seek back to the start so you are writing from the beginning of the file, like so
HANDLE hFile = CreateFile("C:\\test", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
SetFilePointer(hFile, 4 * 1024 * 1024, NULL, SEEK_SET);
SetEndOfFile(hFile);
SetFilePointer(hFile, 0, NULL, SEEK_SET);
CloseHandle(hFile);
}
Edit:
I missed part 3...
quite simply seek to the end of the data in the file to append to it.
SetFilePointer(hFile, 0, NULL, SEEK_END);
SetFilePointer(hFile, nDataLength, NULL, SEEK_SET);
Writing to a file is pretty straight forward. You just need a buffer and the length of data you are writing
LPSTR szWrite = "hello world";
DWORD nLength = strlen(szWrite);
DWORD nBytesWritten;
WriteFile(hFile, szWrite, nLength, &nBytesWritten, NULL);
CloseHandle(hFile);
If you are writing strings in unicode you need to multiply the length by sizeof(wchar_t) or sizeof(TCHAR)
Finally, All file writes (and reads) are sequential for all APIs that I know of. It moves the file pointer to the end of the data you have just written (or read)
modified on Wednesday, January 12, 2011 11:23 AM
|
|
|
|
|
|
i am writing small utility there i wanted to show all bookmarks on right click of one icon(as a popupmanu)...it is working fine upto 2000 bookmarks
or more(depends)... i want to insert more bookmarks to popupmanu..
|
|
|
|
|
Your numbers are really too large for the mechanism you have chosen. Popup menus are designed to hold small numbers (fewer than 50) of items. If you want to display large lists then you would be better using some form of scrollable view or list. There are plenty to choose from among the windows controls.
I must get a clever new signature for 2011.
|
|
|
|
|
then how mozilla browser is showing more then 30thousand bookmarks on clicking Bookmarks Menu...?
|
|
|
|
|
yogish293 wrote: then how mozilla browser is showing more then 30thousand bookmarks on clicking Bookmarks Menu...?
Probably by writing some clever code. I did not say it was impossible, just not the best way to do things. You probably need to create a virtual menu which does not have any items in it but uses the owner draw feature to return the relevant items when the user clicks or scrolls into the menu. However, you should ask yourself whether your users will really have the patience to search through such a list for one single item.
I must get a clever new signature for 2011.
|
|
|
|
|
i tried to insert all menu item but its taking time to insert and after that my PC got restarted..
|
|
|
|
|
yogish293 wrote: i tried to insert all menu item but its taking time to insert and after that my PC got restarted..
Well that should give you a clue that those of us who are suggesting that you need to rethink your design may actually have a point.
I must get a clever new signature for 2011.
|
|
|
|
|
And you think it's a good idea ?
Anyway, it's probably some sort of "ownerdrawn" nenu.
I could suggest you have a look at the Firefox/Mozilla source code.
Watched code never compiles.
|
|
|
|
|
This is essentially a repost of the same question[^], were the answers there not helpful?
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Hello Friends
I am loading an image.Now I want to Load another image that I want floating over the first so that i can move when i want.Do I need to get Some DC Or any other Idea?
I m confused Do i need to create a new DC or by using the Existing DC?
Thanks & Regards
Yogesh
|
|
|
|
|
For flicker free drawing, you may use a memory dc to draw two images and BitBlt it into the window dc.
yogeshs wrote: so that i can move when i want.
You mean by means of mouse?
|
|
|
|
|
Yeah,I want to move by mouse.
And Does By getting Memory DC ,the second image will be a floating image?
Thanks For Reply.
Regards
Yogesh
|
|
|
|
|
yogeshs wrote: By getting Memory DC ,the second image will be a floating image?
It doesn't mean.
If your requirement is simple, better to draw the floating image on another window, probably a child one without borders and title. Size this window to same size as image. Use WM_NCHITTEST message to enable the moving of this window by dragging the mouse anywhere in client area. (From NCHITTEST message handler, if the mouse coordinate is with in the window rect, return HTCAPTION to accomplish this)
Otherwise, once both the images are rendered to the same window dc, you have to manually handle mouse clicks and mouse moves which comes inside the second image, and redraw it appropriately. For this to work smoothly, you may first draw to a memory dc and then BitBlt to window dc.
|
|
|
|
|
I am trying to get the document idispatch. Note that I already know the hwnd for each instance of the application that I am interested in, but cannot get the right application idispatch with multiple application instances running. The GetDocDispatch method, referred to in the article referenced below, displays a message with the idispatch. How can I call the GetDocDispatch method or access the values from native C++?
http://support.microsoft.com/kb/190985/[^]
modified on Wednesday, January 12, 2011 4:16 AM
|
|
|
|
|
hi all,
following is a code snippet of my program having vc6 mfc sdi and formview as basic characteristics.
void CScada_thrdsView::dsp_cnt()
{
while (!exit_thrd)
{while(!nw_cnt) ;
sprintf(cstring,"%d",count);
m_val.InsertString((count-1),cstring);
UpdateData(FALSE);
` nw_cnt = 0;
}
}
i am getting an error
debug assertion failed;file wincore.cpp;line no 883
from debugging i gather that this error is being caused due to the updatedata statement.
the function dsp_cnt is in form view but is being called from the worker thread.
i request for help in sorting out this error.
thnx
ashwani
|
|
|
|
|
You cannot manipulate UI elements from a non UI thread. I suggest you read this excellent article[^]. It's a bit long but it is really worth reading it, because you will learn a lot of very useful things.
|
|
|
|
|
|
I would guess it is 1 of 2 problems.
1. Most likely that they belong to a different thread (the main thread). To my knowledge, UpdateData must be called from the thread that owns the controls.
2. The controls haven't been created yet, if it is in initialisation code.
The best way I would suggest for fixing problem 1 would be to register a custom message WM_USER + 1 and have the handler call UpdateData like this:
header file:
#define CM_UPDATEDATA WM_USER + 1
class CScada_thrdsView : public BaseClass {
protected:
afx_msg LRESULT OnUpdateData(WPARAM wParam, LPARAM lParam);
}
source file:
BEGIN_MESSAGE_MAP(CScada_thrdsView, BaseClass)
ON_MESSAGE(CM_UPDATEDATA , OnUpdateData)
END_MESSAGE_MAP()
LRESULT CScada_thrdsView::OnUpdateData(WPARAM wParam, LPARAM lParam) {
UpdateData((BOOL)wParam);
return 0;
}
in the thread:
void CScada_thrdsView::dsp_cnt() {
while (!exit_thrd) {
while(!nw_cnt);
sprintf(cstring,"%d",count);
m_val.InsertString((count-1),cstring);
PostMessage(CM_UPDATEDATA, FALSE);
nw_cnt = 0;
}
}
|
|
|
|
|
thnx andrew.xtremely detailed help.
thnx
|
|
|
|
|
hi andrew,
i did as directed,and it worked. thnx.one small point though,in this code UpdateData((BOOL)wParam); probably should'nt it be lParam instead of wParam.
thnx
ashwani
|
|
|
|
|
No, wParam is correct.
The function I used to send the message was CWnd::PostMessage(UINT Msg, WPARAM wParam = 0, LPARAM lParam = 0);
Using the Msg as CM_UPDATEDATA and wParam as FALSE (or TRUE if you want to update the variables instead), and lParam as its default unused value of 0
Hence the wParam variable in the CScada_thrdsView::OnUpdateData function is the 1 that holds the bSaveAndValidate parameter to UpdateData.
You can change it to use the lParam by using PostMessage(CM_UPDATEDATA, 0, FALSE); to send the message if you prefer
|
|
|
|
|