|
|
my problem is like this,
1. when the user choose a menu item from the menu, a dialog box will be pop up
2. the dialog box contains some edit box which let the user input the value
3. after user input the value and click on the "view output" button, the dialog box will link to another window to show its output(diff input will have diff output)
i am now having problem on link the dialog box to another window which is going to show the output...
since i m new to mfc, can anyone helps me on that?? thanks..
|
|
|
|
|
Hi,
I want to custom draw a tree. The DrawItem only works for clistbox, clistctrl, buttons... Is there any method I can use for CTreeCtrl?
Thanks
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
Florin Ochiana wrote:
I want to custom draw a tree. The DrawItem only works for clistbox, clistctrl, buttons... Is there any method I can use for CTreeCtrl?
Have you looked at NM_CUSTOMDRAW. This may let you do what you want.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
This should be a simple one for everyone:
I have written a simple client server app to read in a string and send it across. I have implemented this with standard CSockets but want to port it in a simple manner to use CAsyncSockets. I am not familiar with the sequence of events that occur with these-I only know how the CSockets work:
Client<br />
create<br />
connect(IP,Port)<br />
CArchive.write(...)<br />
<br />
Server<br />
create(Port)<br />
listen<br />
CArchive.read(...)<br />
I know that the asyncs. don't use archives and that the read and write mechanisms are different; but the more serious problem that I have is that I have no idea how things are meant to be ordered. I have read a lot about overloading member functions and the like but am thoroughly confused. Anyone able to offer some hints? I have read and tried to disassemble the code for the AsyncProxySocket example that's on here somewhere and ended up bashing my head against the wall.
There doesn't seem to be a great deal in the msdn about them.
Thanks in advance
|
|
|
|
|
Hi,
Read this: http://www.codeproject.com/internet/winsockintro01.asp
And check into the Internet Section. There are other articles related to your problem.
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
I suggest taking a look into existing source code using CAsyncSocket ( e.g. older Gnucleus code).
The client side is pretty less work, but the server side has to take care about incoming socket and e.g. cleaning up socket objects when they die.
|
|
|
|
|
Thanks for taking the time to reply. I have attempted to go through some of the other code that uses the Async sockets, but I can't seem to follow what's going on. If I want to use them, I need to be able to override the OnAccept() and OnSend() etc. member functions; but when are these called?
If I define my own class derived from CAsyncSocket and override the member functions, what is the order of events that must occur for these functions to work?
<br />
class Mysocket : public CAsyncSocket<br />
{<br />
public:<br />
virtual void OnAccept(int nErrorCode);<br />
virtual void OnClose(int nErrorCode);<br />
}<br />
<br />
Mysocket::OnAccept(int nErrorCode)<br />
{
SleepEx(1000,FALSE);
CAsyncSocket::OnAccept(nErrorCode);<br />
}<br />
Say for instance that I have a function in an mfc document class that is meant to do the job of recieving, its code currently looks like this: (this code is what I have ported from a CSocket version which is why it looks a little funny)
<br />
int CAsyncItDoc::RecieveStuff()<br />
{<br />
int status =0;<br />
Mysocket Myskt;<br />
char theString[4096];<br />
if(Myskt.Create(5001) == 0)
{<br />
status = Myskt.GetLastError();<br />
return status;<br />
}<br />
if(Myskt.Listen() == 0)
{<br />
status = Myskt.GetLastError();<br />
return status;<br />
}<br />
Mysocket theRec;
if(Myskt.Accept(theRec) == 0)
{<br />
status = Myskt.GetLastError();<br />
return status;<br />
}<br />
ofstream outfile;<br />
outfile.open("igotthis.txt");<br />
while (theReciever.Receive(theString,4096) != 0)<br />
{<br />
outfile << theString <<endl;<br />
status++;<br />
}<br />
outfile.close();<br />
Myskt.Close();<br />
return status;<br />
}<br />
I realise this sounds awfully lazy but some of the other code uses CDialogs which I've never used, and all the overridden member functions end up really long and complex. All I'm after is a simple implementation and at the moment all I have is a good way of getting confused.
Thanks for any (further) advice.
|
|
|
|
|
Yes, you basically will override a few member functions. Remember, asynchronous sockets will not be polled or go into blocking mode... instead you get an event when something interesting happens and can handle it. For example OnConnect() will be called after a succesfull or failed Connect() call, have a look on examples.
|
|
|
|
|
Thanks Moak-I was failing to get the thing to accept a call properly but have cheated now:
<br />
while(true)<br />
{<br />
if(Myskt.Accept(RecSock)==0)<br />
{<br />
SleepEx(10,FALSE);<br />
}<br />
else<br />
{ <br />
Myskt.Onaccept();
break;<br />
}<br />
This is my OnAccept() function as it stands. The function doesn't seem to call it automatically when the if condition is not 0 (i.e the accept completes); instead I am invoking it manually. Can you see what it is that I am doing wrong?
<br />
void Mydamnsocket::OnAccept(int nErrorCode) <br />
{<br />
Mydamnsocket RecSock;<br />
Mydamnsocket::Accept(RecSock);<br />
char Acceptmsg[20]="Connected to server";<br />
Mydamnsocket::Send(Acceptmsg,20);<br />
} <br />
Is it necessary to stick another thread in to deal with this or something?
P.S. You mention about reading the examples section-can you recommend a particular one that contains an implementation of this that isn't too complex? Cheers!
|
|
|
|
|
Sorry, I dont have the time at the moment to search for a good example... actually I tried and didn't find one. Hmm, I remember that old Gnucleus code (1.4.x) used class CAsyncSocket and was a good starting point.
Some notes: You will not call OnAccept() manually, instead wait for it to be called. CAsyncSocket will handle everything in one thread context. So basically there's no need for polling, sleeping, multithreading with it.
Here is a little snippet from my code:
void CSocketServer::OnAccept(int nErrorCode)
{
if(m_nNodesConnected >= m_pref.m_nMaxSockets) return;
CSocketNodePICHAT* pSocket = new CSocketNodePICHAT(this);
if(Accept(*pSocket))
{
pSocket->SetStatus(SOCKET_CONNECTED);
m_NodesList.push_back(pSocket);
m_nNodesConnected++;
} else {
pSocket->SetStatus(SOCKET_DEAD);
delete pSocket;
}
}
Hope it helps
|
|
|
|
|
Ah ha-I can hear the penny finally beginning to drop Thanks for that. One thing though, say I have a simple app that starts my recieve function off when the user hits a button, and this creates a socket and starts to listen to the port. I realise now that onaccept will be called automatically when the client wants to connect to it on the right port#, but what do I do in the rest of the function? Should I simply set up the socket and make it listen; have my function return and then wait... then the program will do the job automatically? I take it that the rest of the functions get called automatically as well once the appropriate event occurs?
(I feel like I'm answering my own questions here-I hate it when that happens )
Thanks again for your help-I appreciate you've got better things to do. I'll let you have a metaphorical beer for all your efforts
|
|
|
|
|
chrisedgington wrote:
I take it that the rest of the functions get called automatically as well once the appropriate event occurs?
yup. fire your stuff and handlers will be called when necesarry.
Thanks for the , cheers!
|
|
|
|
|
That's ok. You sir have been a great help. If you feel like helping more; you might like to tell me why OnAccept and my other member functions are not being called? I have set up a beginsend and a beginreceive function in the document class, which do the following:
beginsend:
<br />
{<br />
int status=0;<br />
Mydamnsocket Myskt;<br />
int nPort = 5001;<br />
CString IPAddy="127.0.0.1";<br />
Myskt.Create();<br />
Myskt.Connect(IPAddy,nPort);<br />
return status;<br />
}<br />
beginrecieve:
<br />
{<br />
int status = 0;<br />
Mydamnsocket Myskt;<br />
Myskt.Create(5001);<br />
Myskt.Listen();<br />
return status;<br />
}<br />
So the user kindly runs up two of these apps and hits recieve in one and send in the other-thus calling these functions. If I watch developments in the Debugger with a few cleverly placed breakpoints (well actually, every darn line at the moment), I would expect to see the program jump into my Mydamnsocket class and the onaccept member function; but it doesn't-it just sits there. This is somewhat puzzling and is stopping me from getting anywhere. Once I can get the functions called I should pretty much be there with this.
Plenty beer for you if you can help?
|
|
|
|
|
Can anyone help me out a little with my tooltip under Win32?
I have created the control (called InitCommonControlsEx also) and filled in my TOOLINFO struct like so:
<br />
ti.cbSize = sizeof(TOOLINFO); <br />
ti.uFlags = TTF_IDISHWND; <br />
ti.hwnd = hwnd; <br />
ti.hinst = hInst; <br />
ti.uId = (UINT) hwndView; <br />
ti.lpszText = (LPSTR) szTool;<br />
hwndView is an owner drawn button btw
Then I added the tool with this message:
<br />
SendMessage(hwndTool, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);<br />
and I subclassed the button control and processing the WM_MOUSEMOVE message I sent the following message:
<br />
SendMessage(hwndTool, TTM_RELAYEVENT, 0, (LPARAM) (LPMSG) WM_MOUSEMOVE);<br />
Unfortunately as soon as the mouse enters the button's window the program crashes. What am I missing here? Some help or a link to some other code examples would be much appreciated. Thanks.
|
|
|
|
|
There isn't much I can tell from looking at this code. The first thing I would do is run the Debug build and inspect the crash in the debugger and work back from there.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
In Debug mode, as soon as I move the window over the control it crashes with the well know message:
Unhandled exception in ToolTest.exe (COMCTL32.DLL) 0xC0000005: Access Violation
with the yellow pointer pointing to this line:
77365F4F push dword ptr [eax+0Ch]
Unfortunately I am not to good at interpreting the debugger.
I have only posted this code because that is basically all I have. I am confused about whether or not I need a special CALLBACK function to take care of the TTM_RELAYEVENT message or is it handled internally by Windows?
P.S. I have neither set a timer or a hook for relaying of messages
|
|
|
|
|
I don't think you want nor need:
SendMessage(hwndTool, TTM_RELAYEVENT, 0, (LPARAM) (LPMSG) WM_MOUSEMOVE);
Have you tried removing this.
Also add:
memset( &ti, 0, sizeof( TOOLINFO ) );
before: ti.cbSize = sizeof(TOOLINFO);
Have a search around CP for articles which use Tooltips.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
Thanks for the help. I got it working by installing a message hook to take care of the message relaying and it works like a charm.
|
|
|
|
|
I know it's stupid but I'm new to UNICODE ...
So. In my code I want to call inet_addr which takes const char* as parameter, but my string which I want to pass is wchar_t . How do I squeeze it into that func?
This is what I get from compiler:
<br />
error C2664: 'inet_addr' : cannot convert parameter 1 from 'const wchar_t *' to 'const char *'<br />
Will it even be able to work with UNICODE string??? MSDN doesn't say a word about UNICODE for this func. I do have _UNICODE in my project defined and everything.
Thanks a lot.
|
|
|
|
|
You can convert the wchar_t * to char * with one of the following functions:
- wcstombs (include stdlib.h)
- WideCharToMultiByte (include winnls.h)
|
|
|
|
|
Use the WideCharToMultiByte() API. It's documented in MSDN. Set the cbMultiByte parameter to 0 to determine the length of the target (ASCII) buffer. Then allocate a char buffer and call the API again to do the actual conversion.
If a train station is where the train stops, what's a workstation...?
|
|
|
|
|
Hi,
I create a MCI control window with 'MCIWndCreate' to play an avi file.
I want to disable overlay to make a bitblt from the video to a static control.
With overlay activated (the default behaviour) I only get a black rectangle.
Is there a way to disable overlay or does another control allow frame grabbing ?
thx.
|
|
|
|
|
I have a combobox and a clistCtrl. In the listCtrl I have several items that are relevant to all the entries in the combobox. So for example I have file1 and file2 in the combo, and the values iI can set for these files are isted in the listctrl. Now in the OnItemCChanged I go and do stuff. THe only problem is that if the listCtrl had an item selected in it for the first file, file1, then when I switch to file2, and want to set its value for that same list item, the OnChanged doesnt fire since its really not changed. How can I "reset" the listctrl so that it responds to any item I click on when I'm gathering info for file2 , even if it happens to be the same one I last clicked on for file1. I need to start back afresh at the first item in the list....or with nothing as the selected item . How to make it forget soimething wasa selected, and behave as it does when running for the first time?
Appreciate your help,
ns
|
|
|
|
|
Seems that when you handle changes to the combo box, you want to repopulate the list control with entries that pertain to the combo box selection. In this case, DeleteAllItems() and add the new ones in the list control.
In the interests of user-friendliness, you may want to also preselect the first (or most appropriate) item in the list control after populating it.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|