|
Did you know that the "Quote Selected Text" button doesn't work when replying to your posts? I think it may be related to the > character in your signature. Would you mind removing or at least escaping it? Instead of > you can write > and it will still show the same way. Hopefully, that will fix the problem.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
hi all..I'm making a program using CListCtrl that has a find feature(so if I enter a string in edit box and click the find button, it search the CListCtrl attributes with the same string, and then set the selection mark into the attributes). What function that I should use?(I already try SetSelectionMark,but it doesn't work)
pls help...
thx
|
|
|
|
|
According to MSDN[^], I think SetItem is what you want.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
thx..but how to make the previous item is not selected(because when I try to use the find function twice or more, the previous selected item is still highlighted/selected)
thx...
|
|
|
|
|
You need to call the same method to clear the selected state, just the flag you pass in changes. I don't see any other way of doing it on MSDN.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
what flag that I should use, because I didn't find any suitable flag? Pls help
thx..
|
|
|
|
|
firebolt77 wrote:
what flag that I should use, because I didn't find any suitable flag? Pls help
Here is What MSDN State for your problem :-
stateMask
Value specifying which bits of the state member will be retrieved or modified. For example, setting this member to LVIS_SELECTED will cause only the item's selection state to be retrieved.
This member allows you to modify one or more item states without having to retrieve all of the item states first. For example, setting this member to LVIS_SELECTED and state to zero will cause the item's selection state to be cleared, but none of the other states will be affected.
To retrieve or modify all of the states, set this member to (UINT)-1.
You can use the macro ListView_SetItemState both to set and to clear bits.
-----------End MSDN Specific data-----------------------------
I have marked statement your required with BOLD
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
thx...it's work now...but why the view of ClistCtrl didn't scroll automatically to the attributes(for example the ClistCtrl only preview 10 attributes,but the attributes that I want is in index 20. When I try to run the find function, although the selection mark is in index 20,but the view still previewing 1-10). How to handle this problem?
thx...
|
|
|
|
|
firebolt77 wrote:
although the selection mark is in index 20,but the view still previewing 1-10). How to handle this problem?
use CListCtrl::Scroll(...) or CListCtrl::SetSelectionMark(...) Function
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi guys,
I am using an Access database in my application.
The problem arises then when I try to update or edit a field corresponding to another field in the data base.
Consider the database contains 2 fields,namely m_NameE2 and m_NameB2.
Now I try searching out the m_NameE2 field for a given text,if found then I go for updating the corresponding m_NameB2 field.But it gives like such errors
"CRecordset is read-only"-when I use rs.Edit(),or "Attempt to Update or delete failed" for rs.Update();
I use the following code:
<br />
CString ss,gg;<br />
int present=0;<br />
GetDlgItemText(IDC_EDIT1,ss);<br />
gg=m_gedit.Get_Text();<br />
if(ss!="" && gg!="")<br />
{<br />
CDatabase db;<br />
db.OpenEx(_T("DSN=ForeignName"),CDatabase::noOdbcDialog);<br />
if(db.CanUpdate()==TRUE)<br />
{<br />
CNameRecords rs(&db);<br />
rs.Open(CRecordset::dynaset);<br />
rs.MoveFirst();<br />
<br />
do<br />
{<br />
if(rs.m_NameE2==ss)<br />
{<br />
present=1;<br />
AfxMessageBox("Data found and will be tried for modifying");<br />
break;<br />
}<br />
rs.MoveNext();<br />
}while(rs.IsEOF()!=TRUE);<br />
<br />
if(present==0)<br />
{<br />
AfxMessageBox("Data not found in English Name column !!");<br />
<br />
}<br />
<br />
else<br />
{<br />
<br />
rs.Edit();<br />
rs.m_NameB2=gg;<br />
<br />
rs.Update();<br />
<br />
SetDlgItemText(IDC_EDIT2,rs.m_Sex2);<br />
SetDlgItemText(IDC_EDIT3,rs.m_Origin2);<br />
AfxMessageBox("Data is saved successfully");<br />
<br />
}<br />
rs.Close();<br />
}<br />
else<br />
AfxMessageBox("Data is not saved,because data can't be appended in database file !!!!... ");<br />
db.Close();<br />
}<br />
else<br />
{<br />
AfxMessageBox("Data is not saved,because the fields are partially or not filled at all !!!!... ");<br />
}<br />
<br />
<br />
Please help...
|
|
|
|
|
This may or may not be related to your problem, but
joy007 wrote:
if(db.CanUpdate()==TRUE)
The documentation says CDatabase::CanUpdate returns "nonzero if the CDatabase object allows updates".
"Nonzero" doesn't mean neccesarily TRUE, which is 1. You should always write your tests this way to be on the safe side:
if (db.CanUpdate() != FALSE)
{
}
You could also check rs.CanUpdate
Besides, shouldn't you use a SELECT statement instead of traversing all the recordset looking for a record by yourself?
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Ok, I am creating a c++ application that recieves files from a c# application.
The c++ code is what I am having problems with, the application tends to crash after transfering 300k of a 15 meg file (which takes about 20 seconds). Here is the c++ code:
<br />
void RecieveFile()<br />
{<br />
XBNetwork xbns;<br />
WSADATA WsaData;<br />
if(WSAStartup(MAKEWORD(2,2), &WsaData) != 0)<br />
Debug("Winsock Statup Error\n");<br />
<br />
SOCKET ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);<br />
if(ListenSocket == INVALID_SOCKET)<br />
Debug("Socket Creation Error\n");<br />
<br />
struct sockaddr_in ServerAddress, ClientAddress;<br />
ServerAddress.sin_family = AF_INET;<br />
ServerAddress.sin_addr.s_addr = htonl(INADDR_ANY);<br />
ServerAddress.sin_port = htons(6969);<br />
<br />
if(bind(ListenSocket, (struct sockaddr *) &ServerAddress, sizeof(ServerAddress)) == SOCKET_ERROR)<br />
Debug("Socket Binding Error\n");<br />
<br />
if(Listen(ListenSocket, 5) == SOCKET_ERROR)<br />
Debug("Socket Listening Error\n");<br />
<br />
char xrec[2049];<br />
memset(xrec, 0x0, 2049);<br />
<br />
while(true)<br />
{<br />
int ClientAddressLength = sizeof(ClientAddress);<br />
<br />
SOCKET ClientSocket = accept(ListenSocket, (struct sockaddr *) &ClientAddress, &ClientAddressLength);<br />
if(ClientSocket == INVALID_SOCKET)<br />
Debug("Socket Accepting Error");<br />
<br />
while(recv(ClientSocket, xrec, 2048, 0) > 0)<br />
{<br />
<br />
FILE *fp;<br />
fp = fopen("C:\\TestFile.dat", "ab");<br />
fprintf(fp, xrec);<br />
fclose(fp);<br />
<br />
memset(xrec, 0x0, 1025);<br />
}<br />
}<br />
}<br />
Here is the c# code:
<br />
public void SendFile()<br />
{<br />
Socket so = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);<br />
IPHostEntry localHostEntry = Dns.GetHostByName(Dns.GetHostName());<br />
IPEndPoint localIpEndPoint = new IPEndPoint(localHostEntry.AddressList[0], 0);<br />
so.Bind(localIpEndPoint);<br />
<br />
IPHostEntry remoteHostEntry = Dns.GetHostByName("192.168.1.49");<br />
IPEndPoint remoteIpEndPoint = new IPEndPoint(remoteHostEntry.AddressList[0], 6969);<br />
so.Connect(remoteIpEndPoint);<br />
<br />
BinaryReader br = new BinaryReader(new FileStream("D:\\thefile.dat", FileMode.Open, FileAccess.Read, FileShare.None));<br />
<br />
for(int x = 0; x < br.BaseStream.Length / 2048; x++)<br />
{<br />
Byte[] BytesToSend = br.ReadBytes(2048);<br />
so.Send(BytesToSend);<br />
}<br />
<br />
br.Close();<br />
so.Close();<br />
}<br />
Thanks!!!
|
|
|
|
|
farklem@gmail.com wrote:
the application tends to crash
"Tends to crash" is a bit vague What's the error exactly? An exception? What exception? Where?
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I get the error: "Access violation reading location 0xcccccccc"
Its really not the error that bothers me but the time it takes to transfer such a small amount. I don't know of a proper way to write this code because I haven't found any good examples of something like this.
|
|
|
|
|
farklem@gmail.com wrote:
I get the error: "Access violation reading location 0xcccccccc"
Which still doesn't give us much information...
What happens when you break into the debugger after the exception? What is shown in the call stack? At what point in your code was the problem?
In any case, looking again at your code, I noticed this:
while(recv(ClientSocket, xrec, 2048, 0) > 0)
{
FILE *fp;
fp = fopen("C:\\TestFile.dat", "ab");
fprintf(fp, xrec);
fclose(fp);
memset(xrec, 0x0, 1025);
}
If you are receiving binary data, it doesn't make sense to use fprintf , which will treat xrec as a null-terminated char string. It will stop at the first byte with zero. It may encounter a zero way before the end of the buffer, or worse, way after the end. Further, if it happens to find what it thinks is a format specification (e.g.: %d, %s, etc.) it will try to extract an additional parameter from the stack and very bad things could happen. Even if you are using this for text files, I don't think recv will put a null terminator after each fragment it reads.
You should a) use the return value from the recv function to know exactly how many bytes were copied to the buffer (and so how many to write to the local file), and b) write to the file with a function that can handle binary data, like fwrite(xrec, 1, nBytesReceivedWithRecvFunction, fp) .
Also, avoid using "magic numbers" (like 2048, 1025, etc.), specially if you use them more than once in the code. Use defines, or better yet, const int variables. That way, if you need to change a value, you can be sure the new value will be used everywhere it's needed. For example, why are you reading from the socket up to 2048 bytes in each iterations and then resetting the memory for the first 1025? I don't think you need to reset the buffer before each read, but if you actually needed it, you would be doing it wrong. Seems like you changed the buffer size and forgot to update the resetting?
Those problems can be avoided if you simply declare a const int nBufLen = 2048; and use nBufLen wherever you need to refer to the buffer size.
Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Thank you so so much!!! BTW, the reason I didn't post the entire error code is because this is running on an xbox and it confuses lots of people to see the errors when they aren't used to them. Here is what I changed based on your recomendations:
#define BufLen 2048
FILE *fp;
fp = fopen("D:\\wow.map", "wb");
int BytesRecieved = 1;
while(BytesRecieved)
{
BytesRecieved = recv(ClientSocket, xrec, BufLen, 0);
fwrite(xrec, 1, BytesRecieved, fp);
memset(xrec, 0x0, BufLen);
}
fclose(fp);
I'm not sure if you have any recomendations for making this faster but i'm open to suggestions. Currently it takes about 30 seconds to send a 15 mb file (thats not too bad but there are going to be lots of 400 meg file transferes going on).
|
|
|
|
|
Actually the code is basicly just fine, it has something to do with the way i'm doing it on the xbox I guess. I made a console app on the PC using the exact same code and it takes less than 2 seconds to transfere to another computer even though it takes over 35 seconds for the xbox to recieve the file.
Again thanks for the help
|
|
|
|
|
can anyone teach me how to use a listbox using GLUI and how to get the item from a listbox.
|
|
|
|
|
|
Hello,
Can anybody help me to create a list control with a tree view support?
Thank you!
|
|
|
|
|
|
I need to create a text link to a site in a dialog box. I have seen in many windows aplications it is a blue text and on mouse press an iexplorer window opens with the link in the address bar.
I know how to open an explorer window but I don't know how to create the text and the event listener that will underline the text and will listen to mouse clicks.
Any help will be apreciated.
I have a dialog based application in visual studio 6.
Thanks,
dragulceo.
|
|
|
|
|
|
Thank you very much ... that's what i'm looking for!
|
|
|
|
|
|