|
actually, you need to add 1 to the length of the buffer, if you want to put the NULL on the end:
char* Buff = new char[nFileSize + 1];
then, before the MessageBox, you have to "delete [] Buff".
-c
Cheap oil. It's worth it!
|
|
|
|
|
Thank you for your help, it really helped me alot and got me to the solution.
void CMyClass::MyFunction(){
CFile myFile;
UINT uBytesRead;
CSting szText;
myFile.Open("File.txt",CFile::modeRead,NULL);
int nFileSize = myFile.GetLength();
char* pBuff = new char[nFileSize];
while(uBytesRead = myFile.Read((void*)pBuff,nFileSize){
Buff[uBytesRead] = NULL;
szText += CString(pBuff);
}
delete [] pBuff
MessageBox(szText,"Thank you for your help",MB_OK);
}
|
|
|
|
|
Hi,
I would like to know how I could go about writing a program that can record mouse clicks on a Excel Spreadsheet and sending the XY coordinates to a file?
Any ideas on how to begin?
Thanks, James Wong
|
|
|
|
|
You could use SetWindowsHookEx() to install a system wide WH_GETMESSAGE hook (inside a DLL), get the HWND of the window you want to track, filter out mouse message going to the window, and then send a custom message to your application to write this data to a file.
Check out this article:
http://www.codeproject.com/dll/hooks.asp
Good luck!
--
Dana Holt
Xenos Software
|
|
|
|
|
Hi:
There are two things that I am trying to achieve:
1) the default behaviour of the CListCtrl is that the user clicks the item he/she desires to edit once (to give it focus). Waits a little bit, and then clicks it again to start editing it. It the user simply double clicks on the unfocused item, it doesn't work. Any ideas how I can override this behaviour?
2) I have written the code that allows the user to right click the item. A menu pops up. The user selects "Insert ...". the code add a line above the focused line and gives focus to the new line. Until this point, it works beutifully. Then I would like the code to enter into the editing mode for the item (i.e., set the blinking cursor inside of the item - ready for keyboard input) without the user having to click the newly created item again. Here I have a problem. here is what I have got so far:
CDocUniverse* pDoc = (CDocUniverse*) GetDocument();
int nItem = pDoc->m_ViewUniverseListBox.GetNextItem(-1, LVNI_FOCUSED);
if (nItem == -1)
nItem = 0;
pDoc->m_ViewUniverseListBox.InsertItem(nItem, "", 0);
UINT uFlags = LVIS_SELECTED | LVIS_FOCUSED;
pDoc->m_ViewUniverseListBox.SetItemState(nItem + 1, 0, LVIS_SELECTED);
pDoc->m_ViewUniverseListBox.SetItemState(nItem, uFlags, uFlags);
// Send notification
CString str = pDoc->m_ViewUniverseListBox.GetItemText(nItem, 0);
LV_DISPINFO dispinfo;
dispinfo.hdr.hwndFrom = pDoc->m_ViewUniverseListBox.m_hWnd;
dispinfo.hdr.idFrom = pDoc->m_ViewUniverseListBox.GetDlgCtrlID();
dispinfo.hdr.code = LVN_BEGINLABELEDIT;
dispinfo.item.mask = LVIF_TEXT;
dispinfo.item.iItem = 0;
dispinfo.item.iSubItem = 0;
dispinfo.item.pszText = (LPTSTR)((LPCTSTR)str);
dispinfo.item.cchTextMax = str.GetLength();
GetParent()->SendMessage( WM_NOTIFY, pDoc->m_ViewUniverseListBox.GetDlgCtrlID(),
(LPARAM)&dispinfo );
Any ideas?
Thank you
|
|
|
|
|
Anton A. Loukine wrote:
Hi:
There are two things that I am trying to achieve:
1) the default behaviour of the CListCtrl is that the user clicks the item he/she desires to edit once (to give it focus). Waits a little bit, and then clicks it again to start editing it. It the user simply double clicks on the unfocused item, it doesn't work. Any ideas how I can override this behaviour?
Hi,
I think that you mean this:
void CMyDlg::OnLbnDblclkList()
{
int nCurSel = m_listBox.GetCurSel();
CString szCurSel;
m_listBox.GetText(nCurSel, szCurSel);
AfxMessageBox(szCurSel);
}
When a user doubleclicks an item in the list, a message box displays the selection.
After you should change the AfxMessageBox that is only for dimostrative purposes to something that fits your needs.
I hope this helps.
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
I want to change the background colour of a button but am unable to do it. This button is attached to a class derived from CButton, and i want the code to reside in this class, not the dialogs class.
==================================================
When Your Mind Wonders...Where Does It Go???
|
|
|
|
|
Check out some of the owner-drawn button articles for ideas. You might be able to use one of them without modifications.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I think you can do it in Paint of this class.
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
This is the best button you will ever get
Best regards,
Alexandru Savescu
|
|
|
|
|
|
thanks, i haven't had a good look at the code to see if I can incorporate it into my class, but it looks promising.
==================================================
When Your Mind Wonders...Where Does It Go???
|
|
|
|
|
Hi!
Does anyone has some ideas about dynamic software update ? (existing classes ...)
My purpose is to reduce effort while distributing a new release of the same software.
I just want to put the new version on a shared network directory, and force my software to update itself and its components (DLLs, exe files, config files ....)
What's the good way to add such a funtion ??
Thanks,
Vince
vince
|
|
|
|
|
You can use a class derived from WebResourceProvider to check for component (DLL) updates at run time.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Checking updates at run time is not realy a strong effort !
My real need is to learn technicals about the way to force an exe file to auto-update.
|
|
|
|
|
A (one) simple way to do that is to have a very thin driver app that calls an explicitly loaded DLL's exported function that does all the work of the app. When your "update app" logic fires, unload the DLL, replace it with a newer version and reload the DLL.
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I have objects that I create with new() and I store pointers to them in a CArray:
Object *o;
o=new Object();
Array.Add(o);
When I want to delete all and free all memory, do I have to do:
while (Array.GetSize()){
delete Array[0];
Array.RemoveAt(0);
}
Thanks!
|
|
|
|
|
Yep, that should work.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Jason Hihn wrote:
while (Array.GetSize()){
delete Array[0];
Array.RemoveAt(0);
}
That's a pretty inefficient way of doing it since every time you remove at 0 the upper data has to be shifted down. I would just keep it simple e.g.
for(int i=0; i
|
|
|
|
|
Jason Hihn wrote:
while (Array.GetSize()){
delete Array[0];
Array.RemoveAt(0);
}
Let's try again.
That's a pretty inefficient way of doing it since every time you remove at 0 the upper data has to be shifted down. I would just keep it simple e.g.
for(int i=0; i < Array.GetSize(); i++)
{
delete Array[i];
}
Array.RemoveAll();
Joel
|
|
|
|
|
Joel Matthias wrote:
for(int i=0; i < Array.GetSize(); i++)
{
delete Array[i];
}
Array.RemoveAll();
I prefer to write this as follows, personally:
while (Array.GetSize())
{
delete Array[0];
}
Array.RemoveAll();
I don't like using for() loops when clearing out arrays - but I guess that's just me being picky about coding style.
: Dean 'Karnatos' Michaud
|
|
|
|
|
That's fine but the code doesn't work and infact it produces an infinite loop since you never actually remove the pointer from the array.
Also you imply that 'while loops' are somehow more correct or are a better coding style than 'for loops' how do you justify that. People have been using 'for loops' to iterate through arrays for years.
Joel
|
|
|
|
|
Dean `Karnatos` Michaud wrote:
I prefer to write this as follows, personally:
while (Array.GetSize())
{
delete Array[0];
}
Array.RemoveAll();
Imho, that's bad, for 2 reasons: (1) it's inefficient to repeatedly make a function call to GetSize() and (2) it's dangerous to treat integers as boolean expressions. Better to write while (Arrary.GetSize() > 0) .
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Do you know how to exclude a MFC dialog-based application from the taskbar?
rechi
|
|
|
|
|
Remove the WS_EX_APPWINDOW style from the window, and that should do the trick.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|