|
// ServerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Server.h"
#include "ServerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CServerDlg dialog
CServerDlg::CServerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CServerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CServerDlg)
m_sStatus = _T("");
m_sPort = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CServerDlg:oDataExchange(CDataExchange* pDX)
{
CDialog:oDataExchange(pDX);
//{{AFX_DATA_MAP(CServerDlg)
DDX_Control(pDX, IDC_cmdStop, m_bStop);
DDX_Control(pDX, IDC_cmdListen, m_bListen);
DDX_Control(pDX, IDC_cmdDisconnect, m_bDisconnect);
DDX_Text(pDX, IDC_Status, m_sStatus);
DDX_Text(pDX, IDC_Port, m_sPort);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CServerDlg, CDialog)
//{{AFX_MSG_MAP(CServerDlg)
ON_WM_HELPINFO()
ON_BN_CLICKED(IDC_cmdDisconnect, OncmdDisconnect)
ON_BN_CLICKED(IDC_cmdListen, OncmdListen)
ON_BN_CLICKED(IDC_cmdStop, OncmdStop)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CServerDlg message handlers
BOOL CServerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
State = 0;
GetDlgItem(IDC_cmdDisconnect) -> ShowWindow(FALSE);
GetDlgItem(IDC_cmdStop) -> EnableWindow(FALSE);
GetDlgItem(IDC_cmdListen) -> ShowWindow(TRUE);
screen.Empty();
SPacket.packetno = 0;
return TRUE; // return TRUE unless you set the focus to a control
}
void CServerDlg::OnHelpInfo()
{
MessageBox(_T("Help"));
}
//Listen Function
void CServerDlg::OncmdListen()
{
UpdateData(TRUE);
lSocket = new CListenSocket(this);
int Port;
Port = m_sPort;
//char* txtPort;
//int i = m_sPort;
//_itoa(i, txtPort, 10);
//MessageBox(txtPort,NULL,MB_OK);
//If cannot create port
if (!lSocket->Create(Port))
{
MessageBox(_T("No port Created!"), NULL, MB_OK);
return;
}
else
{
}
//If cannot listen
if (!lSocket->Listen())
{
MessageBox(_T("Cannot listen"), NULL, MB_OK);
return;
}
else
{
MessageBox(_T("Listening"), NULL, MB_OK);
GetDlgItem(IDC_cmdListen) -> EnableWindow(FALSE);
GetDlgItem(IDC_cmdStop) -> EnableWindow(TRUE);
State = 1;
}
}
//Accept Function
void CServerDlg::pAccept(void)
{
eSocket = new CLinkSocket(this);
if (lSocket->Accept(*eSocket))
{
State = 2;
MessageBox(_T("Connection Accepted!"), NULL, MB_OK);
GetDlgItem(IDC_cmdStop) -> ShowWindow(FALSE);
GetDlgItem(IDC_cmdDisconnect) -> ShowWindow(TRUE);
}
else
{
MessageBox(_T("Connection not Accepted!"), NULL, MB_OK);
delete eSocket;
}
}
// Read Function
void CServerDlg::Read(CLinkSocket* eSocket)
{
CString strcommand;
int pRead = eSocket->Receive(&RPacket, sizeof(Packet));
if (pRead > 0)
{
if (RPacket.cstatus == 0)
{
OncmdDisconnect();
}
else
{
//command = mbstowcs(buffer, RPacket.Message, 100)
}
}
}
void CServerDlg::OncmdStop()
{
GetDlgItem(IDC_cmdListen) -> EnableWindow(TRUE);
GetDlgItem(IDC_cmdDisconnect) -> EnableWindow(FALSE);
SPacket.cstatus = 0;
lSocket->Close();
delete lSocket;
GetDlgItem(IDC_cmdListen) -> EnableWindow(TRUE);
GetDlgItem(IDC_cmdStop)-> EnableWindow(FALSE);
State = 0;
}
// Disconnect Function
void CServerDlg::OncmdDisconnect()
{
SPacket.cstatus = 0;
eSocket->Close();
lSocket->Close();
delete eSocket;
delete lSocket;
GetDlgItem(IDC_cmdDisconnect) -> ShowWindow(FALSE);
GetDlgItem(IDC_cmdStop) -> ShowWindow(TRUE);
State = 1;
}
|
|
|
|
|
How can develop (using c++) the multiple clipboard Like Word...?
Thanks
Multiple Clipboard
|
|
|
|
|
Maybe you can save the content of clipboard into variable every time the clipboard is accessed
<italic>Work hard and a bit of luck is the key to success.
|
|
|
|
|
If you're using VC++ 7.x the IDE already has this feature. Use Ctrl+Shift+V to cycle though and paste the items. If you're using VC++ 6 there's a macro that does it. It's either here at codeproject or at codeguru. It looks like this...
' Three simple macros to implement a secondary clipboard
' Global to act as clipboard
Dim gSecondClipBoard
gSecondClipBoard = ""
Sub SecondaryClipBoardCut()
'DESCRIPTION: Performs a cut of current selection to a secondary clipboard.
gSecondClipBoard = ActiveDocument.Selection.Text
ActiveDocument.Selection.Text = ""
End Sub
Sub SecondaryClipBoardCopy()
'DESCRIPTION: Performs a copy of current selection to a secondary clipboard.
gSecondClipBoard = ActiveDocument.Selection
End Sub
Sub SecondaryClipBoardPaste()
'DESCRIPTION: Performs a paste of secondary clipboard to the current selection.
ActiveDocument.Selection = gSecondClipBoard
End Sub
Kevin
|
|
|
|
|
Did anybody know ?
Without function gethostbyaddr() please
---Ranger---
|
|
|
|
|
In my application, i need to open a dialog box which will input a path(i.e C:\xyz, etc) from the user. How do i do it. How do i detect that whatever the user had input is a valid path or not? is there any existing file dialog that supports this?
|
|
|
|
|
I think you seacrhing for CFileDialog this will solve you r problem,for reference see MSDN abt CFileDialog
-----------------------------
"I Think It will Work"
Formerly Known As "Alok The Programmer" at CP
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
I think you want a select folder dialog box. This can be done using the SHBrowseForFolder api function.
See http://www.codeproject.com/shell/cxsbrowsefolder.asp for a class that encapsulates this function
|
|
|
|
|
Can anyone pls tell me how to make a coloumn invisible in the datagrid during run time. This is the first time I am using datagrid. Thanks..
Jaya
|
|
|
|
|
Hello, do you guys know of any better replacement for strtok function.
(No MFC and no .NET String)
thanks
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
|
Ivan Cachicatari wrote:
You can use the CStringTokenizer class...
Which uses MFC.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
|
Hi i've got these two data structures:
obj *pObj1 = new obj[10000];
obj **pobj2 = new (*obj)[10000];
for (int i=0;i<10000;++i);
pobj2[i]=new obj;
which are the advantages and disadvantages from each one of them?
i know it's an exam question, but it seems to be interesting. i can't think of many.. first, i think the first one is easier to use, but the second one is more like ordered.
i'll really appreciate your help!!
thanks!
|
|
|
|
|
1. The first is much easier to understand for most people
2. The second is useful when you might have to use a 2D array.
3. The first method allocates memory for the objects in one big allocation. If there is not enough contiguous memory left it will fail. The second method is good when memory is fragmented as it allocates individual chunks of memory for each object.
4. The second is useful if two items in the array must actually point to the same object - in the first case, each array element is unique.
Those are a few to get started
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
1) static: you can't change the size of your array.
2) dynamic you can create and destroy your array using new and delete.
This comes in quite handy when you need a flexible array
example of the second for a 2 dimensional array:
temp = new CString*[nrofrows];<br />
for(int y = 0; y < nrofrows; y++){<br />
temp[y] = new CString[nrofcols];<br />
for(int z = 0; z < nrofcols; z++){<br />
temp[y][z] = "";<br />
}
}
AND (VERY VERY IMPORTANT!)
for(short x = 0; x < nrofrows; x++){<br />
delete []temp[x];<br />
}
delete []temp;<br />
temp = NULL;
hope this helps.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
2. if obj is large, or otherwise expensive to create, then if you wrap access to the array you can defer creation until first access.
2. allows array of obj* or any derived class objects, 1. only allows obj.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
The first consumes 10000 * sizeof(obj) bytes of the heap while the second consumes 10000 * sizeof(obj*) + 10000 * sizeof(obj) bytes of the heap. That could be a 40000-byte disadvantage. It all depends on the application, however.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
in a regular old console program using the main function
main( int argc, char argv[] )
how do you detect if there is a previous instance of the program?
|
|
|
|
|
If you are going to run on Windows, then the same way every one else does - you use some combination of Mutex or Event checking. See the articles on this website, they would still apply to a Windows console application.
|
|
|
|
|
ok, lately i have been writing function for strings
like SubString, StrFind, etc.
i want to make a StrReplace but i cant really come up with a good way to do it, so does anyone have an example such a function (StrReplace)
(note im not really using any classes in this)
|
|
|
|
|
You could try out memmove or memcpy but these functions need to be handled with care.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Well, last night sometime after i got off the net i had a revelation on how to do it, sat down and in 15 minutes i had it. it works quite good too, i owuld post it it but uses two other functions i made, and they other functions, so i would end up having to post my entire header file that im making.
|
|
|
|
|
(Sorry for the spam, but here's a proper version without the <> getting eaten.)
I'm trying to store boost::shared_ptrs in a std::map with a const std::string as the key.
The trouble arises when I need to find a value. Using find() yields an iterator, but VC2003 doesn't like it:
error C2440: 'initializing' : cannot convert from 'std::allocator<_Ty>::value_type' to 'boost::shared_ptr<T>'
with
[
_Ty=std::pair<const std::string,boost::shared_ptr<Sprite>>
]
and
[
T=Sprite
]
And here's the bit of code that causes this reaction:
map<const string, shared_ptr<Sprite> >::iterator frameSet = mysprite.find("animationName");
What I had hoped was that frameSet would be an iterator that I could dereference to call member functions on the Sprite object. But, alas.
Anyone have any suggestions?
tentons
|
|
|
|
|
I'm trying to store boost::shared_ptrs in a std::map with a const std::string as the key.
The trouble arises when I need to find a value. Using find() yields an iterator, but VC2003 doesn't like it:
error C2440: 'initializing' : cannot convert from 'std::allocator<_Ty>::value_type' to 'boost::shared_ptr<t>'
with
[
_Ty=std::pair<const std::string,boost::shared_ptr<sprite="">>
]
and
[
T=Sprite
]
And here's the bit of code that causes this reaction:
map<const string,="" shared_ptr<sprite=""> >::iterator frameSet = mysprite.find("animationName");
What I had hoped was that frameSet would be an iterator that I could dereference to call member functions on the Sprite object. But, alas.
Anyone have any suggestions?
tentons
|
|
|
|