|
Thats what my code looks like exactly except for a TRACE I did on Position to Check for NULL.
However, I did use your code exactly and my problem still remains. I am only deleteing every other
Item that is selected, SO if I am deleteing item 123456 which are all selected using that code above leaves
246 intact and still selected. Am I a BOOB? This is irking me especially since its one of my last bugs, and I cant implement anything else until this is solved.
Here Ill even copy out my code for you.
I really need help on this.
void CChildView::OnRemItems()
{
POSITION pos = m_SpewWnd.QueueView.GetFirstSelectedItemPosition();
while (pos != NULL)
{
int nItem=m_SpewWnd.QueueView.GetNextSelectedItem(pos);
m_SpewWnd.QueueView.DeleteItem(nItem);
}
Invalidate();
}
Maybe you could also tell me how to get that code selected while posting..
=)
recurse.org - Recusion For the Rest Of Us.
|
|
|
|
|
I am only deleteing every other Item that is selected, SO if I am deleteing item 123456 which are all selected using that code above leaves 246 intact and still selected.
That's because when you delete item 1, the result is that 12345 are selected (2-6 shift down to 1-5), so the next time through your loop you skip the new item 1, item 2 (previously 3) gets deleted, and so on.
Easy way to fix: In your loop, get the first selected item and delete it. Then get the first selected item again and delete it. Repeat until there are no more selected items. This may be slow if your list is big, though.
Snazzier way to fix: Loop thru and make a list of the indexes of all selected items. Then delete them working from the highest index to the lowest.
--Mike--
http://home.inreach.com/mdunn/
All your base are belong to ME~!
|
|
|
|
|
The post Below this describes how to do this Task Recursively, but that has a lot of overhead if your list of selected Items is really large. I figured out the "mIchael Dunn" method sometime this morning and that works very well. Using GetFirstSelected() over and over. The List Method is probably the best way to go however.
Thanks EVERYONE.
recurse.org - Recusion For the Rest Of Us.
|
|
|
|
|
Mike,
Can you give a bit more info regarding the "Snazzier way to fix". I need to implement this and i'm having the same problems.
Thanks,
Frank
|
|
|
|
|
Okay, I got it working, BUt this is how.. good old recursion.
All I did was read to the end of the selected list and then recursively delete from there.. heres the code:
Does anyone have a better IDEA ?
void CChildView::OnRemItems()
{
POSITION pos = m_SpewWnd.QueueView.GetFirstSelectedItemPosition();
DelQ(pos);
Invalidate();
}
void CChildView::DelQ(POSITION pos)
{
while (pos != NULL)
{
int nItem=m_SpewWnd.QueueView.GetNextSelectedItem(pos);
DelQ(pos);
m_SpewWnd.QueueView.DeleteItem(nItem);
}
}
Is this the asinine way to do this? I like recursion But I dont think MS had this in Mind at all.
recurse.org - Recusion For the Rest Of Us.
|
|
|
|
|
i have a wince 2.11 application that needs to detect if it has just come out of hybernation.
i have no idea how to do this and i would really really appreciate any help.
|
|
|
|
|
Well, the only way to this is to write a device-driver...
Win CE does not notify applications when it's powered on/wakes from hybernation, it only notifies drivers.
I did it, for test/fun, last year, if you have too much trouble, mail me at am@nimo.dk and I can send you the project.
Who knows, maybe we could write an article about it...
- Anders
|
|
|
|
|
I want to read my HD's boot sector and dump it to a file on my w2k system, is there a way to do this?
Have a good one,
-Ben
"Its funny when you stop doing things not because they’re wrong, but because you might get caught." - Unknown
|
|
|
|
|
Check out the docs on CreateFile() - you can pass "\\.\C:" as the file name (which would actually be "\\\\.\\C:" in C code) to get a handle which can read sectors of the C: drive. The first sector is the boot sector, so you can use ReadFile() and read 512 bytes to get the contents of the boot sector. This requires admin privs, for obvious reasons.
HANDLE hDevice;
BYTE byBuffer[512];
DWORD dwBytesRead;
hDevice = CreateFile ( _T("\\\\.\\C:", GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0, OPEN_EXISTING, 0, NULL );
SetFilePointer ( hDevice, 0, 0, FILE_BEGIN );
ReadFile ( hDevice, byBuffer, 512, &dwBytesRead, NULL );
CloseHandle ( hDevice ); You obviously need error handling in there, but I left that out for clarity.
--Mike--
http://home.inreach.com/mdunn/
All your base are belong to ME~!
|
|
|
|
|
Thanks!
Have a good one,
-Ben
"Its funny when you stop doing things not because they’re wrong, but because you might get caught." - Unknown
|
|
|
|
|
CFile and my class
some problem when I use Cfile to write and read my class
I write this class :
class omega
{
public:
CString o_str;
omega();
virtual ~omega();
};
after that (write work) in functio with button control :
void CMyDialog::OnButWrite()
{
char name[]="mydata.dat";
CFile cfl(name,CFile::modeCreate | CFile::modeWrite);
omega om;
om.o_str = "OMEGA";
cfl.Write(&om,sizeof(om));
cfl.Close();
}
then (read work) in functio with button control :
void CMyDialog::OnButRead()
{
char name[]="mydata.dat";
CFile cfl(name,CFile::modeRead);
omega om ;
cfl.Read(&om,sizeof(om));
MessageBox(om.om2.o_str,"DATA FROM mydata.dat " );
}
now the problem here ...
the program was compiled without any errors
but in run time , when you do write work and then read work
error message apeare and tell me that :
that's caused an error in MSVCRTD.DLL
then another message apeare and tell me that :
Debug Assertion Failed!
FILE:dbgheap.c
LINE:1017
Expression : _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
this problem is apeare when I use CString in my calss and didn't
apear when I use base types like char,int...etc
any one can helpe me...
AHMAD ALWASHALI
|
|
|
|
|
Why don't you use a CArchive to read/write from/to your class?
You can easily use WriteString then (be sure to add a newline while writing to a CArchive)
See MSDN Library, topic CArchive (and Serialize) for more info.
--
Alex Marbus
www.marbus.net
But then again, I could be wrong.
|
|
|
|
|
Your problem is that a CString object does not contain the string itself, only a pointer to the string. When you write your omega object to the file, you only write the pointer, which is then invalid when you read the object back in and try to use it.
--Mike--
http://home.inreach.com/mdunn/
All your base are belong to ME~!
|
|
|
|
|
How does MFC create a CHttpConnection object on the calling processes heap
via the CInternetSession::GetHttpConnection method call? I am trying to
accomplish something similar using my own DLL and all of the object I return
get created on the DLL's heap and when the calling process deletes the object
I get access violations. Anyone know how MFC does this?
Thanks
Brad
|
|
|
|
|
A DLL doesn't have a separate heap. The heap belongs to the process, which is your EXE and all DLLs (and other modules like OCXs) that are loaded as well. So just allocate objects with new.
--Mike--
http://home.inreach.com/mdunn/
All your base are belong to ME~!
|
|
|
|
|
I believe you are wrong. I have a very simple DLL with the following two
classes and code:
#ifdef BF_EXPORTS
#define BF_API __declspec(dllexport)
#else
#define BF_API __declspec(dllimport)
#endif
class BF_API CBar {
public:
CBar( void ) {
m_bFlag = true;
}
private:
bool m_bFlag;
};
class BF_API CFoo {
public:
CFoo( void ) {
}
CBar * MakeBar( void ) {
CBar * cResult = new CBar();
return cResult;
}
};
I have a very simple console application that uses these two classes and
then deletes the new'd objects:
#include <stdio.h>
#include "BF.h"
int main(int argc, char* argv[])
{
CFoo * foo = new CFoo;
CBar * bar = foo->MakeBar();
delete bar;
delete foo;
return 0;
}
When built and run Debug, an assert generated in HeapValidate via
_CrtIsValidHeapPointer when the delete of bar is performed.
Brad
|
|
|
|
|
From the MSDN article "Using the C Run-Time":
[snip]
Section 4: Problems Encountered When Using Multiple CRT Libraries
If an application that makes C Run-time calls links to a DLL that also
makes C Run-time calls, be aware that if they are both linked with one of
the statically-linked C Run-time libraries (LIBC.LIB or LIBCMT.LIB), the
.EXE and DLL will have separate copies of all C Run-time functions and
global variables. This means that C Run-time data cannot be shared between
the .EXE and the DLL. Some of the problems that can occur as a result are:
- Passing buffered stream handles from the .EXE/DLL to the other module
- Allocating memory with a C Run-time call in the .EXE/DLL and
reallocating or freeing it in the other module
- Checking or setting the value of the global errno variable in the
.EXE/DLL and expecting it to be the same in the other module. A related
problem is calling perror() in the opposite module from where the C Run-
time error occurred, since perror() uses errno.
To avoid these problems, link both the .EXE and DLL with CRTDLL.LIB or
MSVCRT.LIB, which allows both the .EXE and DLL to use the common set of
functions and data contained within CRT in a DLL, and C Run-time data such
as stream handles can then be shared by both the .EXE and DLL.
[end snip]
I found that if I compiled the DLL adding the MSVCRT.DLL to the Object/Library modules list in the link General settings, and selected Ignore all default libraries, the problem went away.
|
|
|
|
|
Does anyone know how to combine DirectDraw and CView?
So that I have a CView in which I can use DirectDraw functions.
|
|
|
|
|
How can I convert a CString, to a char* ? Or what is the CString equivalent of the function isDigit()
|
|
|
|
|
CString myCString("1N3");
char* MyStringPointer = (LPCTSTR)myCString;
isdigit(MyStringPointer[0]); // true
isdigit(((LPCTSTR)myCString)[1]); // false
isdigit(myCstring.GetAt(2)); // true
If you want to be ansi/unicode agnostic then use _istdigit.
Endless ways.
-Erik
|
|
|
|
|
none of those worked on my VCPP, and I have the 3rd service pack. It says cannot convert const char* to char*.
|
|
|
|
|
Drake,
It's best to learn C/C++ before trying to program in MFC.
Since all you are doing is checking is digit and not modifying the string, you can put const in front of your char* declaration and the compiler will not complain.
const char* strPtr = (LPCTSTR)myCString;
-Erik
|
|
|
|
|
See CString::GetBuffer(..).
Be sure to call ReleaseBuffer when you're done.
--
Alex Marbus
www.marbus.net
But then again, I could be wrong.
|
|
|
|
|
Hee now than i saw your message..
prev, I got the same problem with the isDigit() function
so I got and create a iIsNum(CString string) function
using VC++ ver 6
BOOL iIsNum(CString string)
{
int strLenght = string.GetLength();
bool _isnum;
CString chr;
for (int i = 0; i < strLenght ; i++)
{
chr = string.Mid(i,1);
if(chr >= "0" && chr <= "9")
_isnum = TRUE;
else
{
_isnum = FALSE;
break; // no use search for other char
}
}
return _isnum;
}
Hope you still can use this function
~~~
|
|
|
|
|
How can I convert a CString, to a char* ?
|
|
|
|