|
DrawText is too slow when string is long enough and without "\n" among the string charaters.any body knows another way instead DrawText?
thanks regards.
|
|
|
|
|
TextOut()
It's frustrating being a genius and living the life of a moron!!!
|
|
|
|
|
Great! But I have a problem with multiline text,I want to text it like a multiline edit control does. I don't know when should I break up the line and start a new line to text. in another word:
I need a method to cauculate one character's width, it isn't only limited in english characters. thanks,so much
life is like a box of chocolate,you never know what you r going to get.
-- modified at 1:42 Wednesday 19th October, 2005
|
|
|
|
|
I think you need GetTextExtent
Dr.pi
|
|
|
|
|
hi all, i am making an multithread client that connects to differents servers using differents threads.
in the main window the user select the numbers of connections that the program will start.
To make make this i created the threads inside a loop like this:
GetDlgItemText(IDC_SIMULTANEOS, n);
int a = _ttoi(n.GetBuffer(n.GetLength()));
for(LONG i=0; i<a; i++)="" {
="" m_servername.gettext(i,="" str);
...
....
="" pthread-="">ResumeThread();
}
The program creates succefully the number of connections to the server specified in a, for example it creates 2 threads.
Now, i need to do read operations on the different threads created.
I can see theat write and read operations works only on the last process(thread, connection) created.(sniffing packets i
realize that the data pushed are in the higher port number of the two established connections on my local machine to the
second server on the list).
How can i identify the different threads created in the loop and make write and read operations on them??
Thanx in advance.
|
|
|
|
|
|
U have created a message with wrong tag
insted of the code tag u selected the link tab
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Hi, i'm setting up a winsock connection with client and server code. The server code seems to work fine, and so does most of the the client code. However, I'm having difficulty connecting to the host. I've tried gethostbyname("www.something.com"); but I don't have a site or something where it's hosted. I figure that if there's some way to find the IP of the socket as the host creates it, the host person could tell the client person what the IP is and have them input it. I'm sure there's a better was, though, and i'm sure you guys know it. Here's the code, I've marked where the error is, but it is in the second half of the code inside the else{}, meaning that the user wants to be a client. You may also notice that this code is from an online tutorial; I had hand-written it, but there was some extremely hard-to-find error and I figured I'd use this instead of re-write. It works fine except for my incompetence. lol. Anyway, thanks in advance. Here's the code:
//--------------------------------start the winsock Connection---------------------------------
cout << "Initializing WinSock..."<<endl;
cout << "will you be joining a previously created server? [y/n] (no means you will create a new server) : ";
cin >> joining;
WORD sockVersion;
WSADATA wsaData;
int nret;
sockVersion = MAKEWORD(1, 1);
// Initialize Winsock as before
WSAStartup(sockVersion, &wsaData);
// Store information about the server
LPHOSTENT hostEntry;
// Create the socket
SOCKET theSocket;
// Wait for a client
SOCKET theClient;
SOCKET listeningSocket;
// Use a SOCKADDR_IN struct to fill in address information
SOCKADDR_IN serverInfo;
cout << "All variables initialized..."<<endl;
if(joining != 'y')
{
listeningSocket = socket(AF_INET, // Go over TCP/IP
SOCK_STREAM, // This is a stream-oriented socket
IPPROTO_TCP); // Use TCP rather than UDP
if (listeningSocket == INVALID_SOCKET) {
nret = WSAGetLastError(); // Get a more detailed error
ReportError(nret, "socket()"); // Report the error with our custom function
WSACleanup(); // Shutdown Winsock
return NETWORK_ERROR; // Return an error value
}
cout << "Set up connection..."<<endl;
serverInfo.sin_family = AF_INET;
serverInfo.sin_addr.s_addr = INADDR_ANY; // Since this socket is listening for connections,
// any local address will do
serverInfo.sin_port = htons(8888); // Convert integer 8888 to network-byte order
// and insert into the port field
cout << "Setup host info..."<<endl;
// Bind the socket to our local server address
nret = bind(listeningSocket, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr));
if (nret == SOCKET_ERROR) {
nret = WSAGetLastError();
ReportError(nret, "bind()");
WSACleanup();
return NETWORK_ERROR;
}
//print the IP of the socket that was created
cout << "Socket successfulyl bound..."<<endl;
// Make the socket listen
nret = listen(listeningSocket, 10); // Up to 10 connections may wait at any
// one time to be accept()'ed
if (nret == SOCKET_ERROR) {
nret = WSAGetLastError();
ReportError(nret, "listen()");
WSACleanup();
return NETWORK_ERROR;
}
cout << "Listening for connections..."<<endl;
theClient = accept(listeningSocket,
NULL, // Address of a sockaddr structure (see explanation below)
NULL); // Address of a variable containing size of sockaddr struct
cout << "Recieved connection... \nAccepting connection..."<<endl;
if (theClient == INVALID_SOCKET) {
nret = WSAGetLastError();
ReportError(nret, "accept()");
WSACleanup();
return NETWORK_ERROR;
}
cout << "All steps completed..."<<endl;
}
else
{
cout << "Getting host..."<<endl;
//------------ERROR---------------------------------------------------------------!!!!!!!!!!
//I don't know if there's some way I can use one of these or what
/*option 1:
LPHOSTENT hostEntry;
in_addr iaHost;
iaHost.s_addr = inet_addr("204.52.135.52");
hostEntry = gethostbyaddr((const char *)&iaHost, sizeof(struct in_addr), AF_INET);
*/
//option 2: hostEntry = gethostbyname("www..com");
//-------------END ERROR---------------------------------------------------------!!!!!!!!!!!
if (!hostEntry) {
nret = WSAGetLastError();
ReportError(nret, "gethostbyname()"); // Report the error as before
WSACleanup();
return NETWORK_ERROR;
}
cout << "Host successfully retrieved..."<<endl;
theSocket = socket(AF_INET, // Go over TCP/IP
SOCK_STREAM, // This is a stream-oriented socket
IPPROTO_TCP); // Use TCP rather than UDP
if (theSocket == INVALID_SOCKET) {
nret = WSAGetLastError();
ReportError(nret, "socket()");
WSACleanup();
return NETWORK_ERROR;
}
cout << "Socket successfully created..."<<endl;
serverInfo.sin_family = AF_INET;
// At this point, we've successfully retrieved vital information about the server,
// including its hostname, aliases, and IP addresses. Wait; how could a single
// computer have multiple addresses, and exactly what is the following line doing?
// See the explanation below.
serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
serverInfo.sin_port = htons(80); // Change to network-byte order and
// insert into port field
cout << "Set host info..."<<endl;
// Connect to the server
nret = connect(theSocket,
(LPSOCKADDR)&serverInfo,
sizeof(struct sockaddr));
if (nret == SOCKET_ERROR) {
nret = WSAGetLastError();
ReportError(nret, "connect()");
WSACleanup();
return NETWORK_ERROR;
}
cout << "Connected..."<<endl;
}
send(theSocket, "hey", 4, 0);
char readin[4];
recv(theSocket, readin, 4, 0);
cout << readin;
//-----------------------------------------------------end WinSock code-----------------------------------------------
--------------------------------------------Signature-------------------------------------------------
-How are you gentlemen!! All your base are belong to us. You have no chance to survive make your time.
-What you say!!
|
|
|
|
|
hello
i have used directly the socket i want to use the
socket ActiveX available ("WinSock").
Do have any idea.
the main reason behind using an acitveX is that the
response from the client is not guranteed , so when
do listen(client); many times my application hangs-up
any solution do u know
thank you
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
I want to write a program that supports mutilanguage. so I read strings
in a ini file. who can help me ?
Just relax
|
|
|
|
|
I ve got a socket listening and accepting on another socket, how would I copy 2nd socket to a 3rd socket, so I would be able to close the 2nd socket...
// create temp and permanent sockets
CSocket tSocket, pSocket;
// accept listening onto temp socket
m_pListenSocket->Accept(*tSocket);
tSocket->Init();
// copy temp to perm
pSocket->Attach(*tSocket); or pSocket=tSocket;
produces the same.
pSocket->Init();
pSocket will pass data now,
// close the temp socket
tSocket->Close();
now pSocket won't pass data.
any helps always appreciated.
shotgun
|
|
|
|
|
afaik u would have to send a message to the client telling it to disconnect from the current socket and reconnect at a socket u pass to it in the message ... that way u can hand off clients to arbitrary servers and sockets
this is usually how i write servers who accept the client connection and authenticate them before handing them over for the actual data transfer
hth
"there is no spoon" {biz stuff} {about me}
-- modified at 23:52 Tuesday 18th October, 2005
|
|
|
|
|
CSocket pSocket,tSocket;
//This will Attach the Socket handle
pSocket.Attach(tSocket.m_hSocket);
//Donot Do any other operation b/w these 2 Lines on the Socket
//This will detach the Socket Handle in the m_hSocket data member of tSocket and set to NULL
Socket handle=tSocket.Detach();
|
|
|
|
|
hello
i have used directly the socket i want to use the
socket ActiveX available ("WinSock").
Do have any idea.
the main reason behind using an acitveX is that the
response from the client is not guranteed , so when
do listen(client); many times my application hangs-up
any solution do u know
thank you
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Hi,
I had the following code to close my dialog application when ESC key is pressed. But WM_KEYDOWN is not invoking at all.
What am I missing here....
case WM_KEYDOWN:
{
switch (wParam)
{
case VK_ESCAPE:
ExitApp(hDialog);
break;
}
return TRUE;
}
|
|
|
|
|
I think WM_CHAR is the only one that recieves the ESCAPE key.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ann66 wrote: I had the following code to close my dialog application when ESC key is pressed.
Doesn't the Esc key do this by default?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I have an OnPaint function and it's being called over and over and after a while, it throws a resource exception by simply saying:
A required resource was unavailable.
I have no idea what that means beyond what it says but it's happening sometime in the OnPaint function after it's run a couple thousand times. I only get the "CPaintDC dc(this);" at the top of the try block (to catch exceptions) and then I draw or not draw with if statements later. Am I allocating the drawing context without deallocating it, do I need to release the 'dc' variable or something to the system?
Under the CPaintDC constructor, it says this as a remark:
An exception (of type CResourceException) is thrown if the Windows GetDC call fails. A device context may not be available if Windows has already allocated all of its available device contexts. Your application competes for the five common display contexts available at any given time under Windows.
Is that affecting me? If so, how I do rectify this?
|
|
|
|
|
It sounds to me like your paint handler is leaking resources. Could you post the code ? Do you clean up the brushes/bitmaps/DCs etc that you use ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The code is complex, but here's the short of it:
try {<br />
CPaintDC dc(this);<br />
if ((thread == NULL) && (files != NULL)) {<br />
dc.Rectangle(x, y, x + 300, y + nTextHeight + 4);<br />
COLORREF OldColor = dc.SetTextColor (RGB(192, 192, 192));<br />
dc.SelectObject (new CBrush(RGB(192, 192, 192)));<br />
sMsg.Format("%s, %s", obj->GetName(), obj->GetStringFilesize());<br />
dc.TextOut(x + 2, y + 2, (LPCTSTR) sMsg);<br />
dc.SetTextColor(OldColor);<br />
dc.SelectObject (new CBrush (RGB(255, 255, 255)));<br />
}<br />
<2 more sections like the above exist with different if statement tests><br />
} catch (CResourceException * e) {<br />
e->Delete();<br />
thread->SuspendThread();<br />
char * lpszMessage = new char[128];<br />
e->GetErrorMessage(lpszMessage, 128, NULL);<br />
MessageBox(lpszMessage, "Critical Error", MB_ICONSTOP);<br />
delete[] lpszMessage;<br />
thread->ResumeThread();<br />
}
That's the gist (and most complex) part of it. I have 3 blocks like the if statement above, the first two are rarely used, but the third is heavily used when a particular thread is running. The heavily used if statement is similar in layout to the above but it draws a text element and pie, both correspond to a progress display of the thread the code mentions. I was handling the CBrush's by new'ing and delete'ing them manually but it threw runtime errors when delete'ing the CBrush's, it said a "pure virtual function call" or something like that. I don't do any clean up, I just get the dc from CPaintDC and then draw, that's it. I figured I didn't need to deallocate the drawing context because I was using it in this method, instead of using a handle to a drawing context with GetDC/ReleaseDC.
|
|
|
|
|
LighthouseJ wrote: dc.SelectObject (new CBrush(RGB(192, 192, 192)));
This is a resource leak. you need to create a brush as a variable, and when you call selectobject, you need to grab the brush it returns. Then you need to restore the original brush, and destroy the brush you created.
LighthouseJ wrote: dc.SelectObject (new CBrush (RGB(255, 255, 255)));
Ditto. I assume this is supposed to restore the original brush color, but you need to actually restore the original brush.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I actually did that originally but I got the aforementioned error because I was trying to free memory from another threads heap. I changed it like below and no error shows up so I guess it's cleared up but I have to clean up the code more because it was opened up to try and fix this with other methods.
CBrush * grey = new CBrush (RGB(192, 192, 192));<br />
CBrush * black = new CBrush (RGB(255, 255, 255));<br />
dc.SelectObject (grey);<br />
<br />
< drawing done here ><br />
<br />
dc.SelectObject(black);<br />
<br />
delete grey;<br />
delete black;
|
|
|
|
|
LighthouseJ wrote: I actually did that originally but I got the aforementioned error because I was trying to free memory from another threads heap.
Well, it's the way it needs to be done, you need to work out those threading issues, I guess..
LighthouseJ wrote: CBrush * grey = new CBrush (RGB(192, 192, 192));
CBrush * black = new CBrush (RGB(255, 255, 255));
dc.SelectObject (grey);
< drawing done here >
dc.SelectObject(black);
delete grey;
delete black;
This is wrong.
CBrush * grey = new CBrush (RGB(192, 192, 192));
CBrush * black = dc.SelectObject (grey);
< drawing done here >
dc.SelectObject(black);
delete grey;
You need to grab the brush that SelectObject returns, and put it back when you're done.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I was trying to capture the outgoing brush but when I delete it, I got the error saying the memory I was deallocating wasn't mine. So, I just don't delete the black brush? Isn't that leaking memory?
|
|
|
|
|
LighthouseJ wrote: I was trying to capture the outgoing brush but when I delete it, I got the error saying the memory I was deallocating wasn't mine.
Correct. You can't delete it, you need to select it back into the DC in order to avoid a leak.
LighthouseJ wrote: So, I just don't delete the black brush? Isn't that leaking memory?
No, because you don't create a black brush, and because the brush in question is left in the control of the DC, as it was at the start.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|