|
hi iam samo
i need help in this question
how i convert all this if statement in c++ to for loop and i want from user to determine how many level he wants and analysis to stage i try it please help me this is the codejust convert if statment to for loop and please send it to my e-mail : samo_jack2000@yahoo.com it's important for me)
#include
#include
int size;
void main(){
char symbol[10 ];
int level;
int i;
//******************************************************************//
cout<<"ENTER SIZE OF YOUR CHARACTER :";
cin>>size;
cout<<"*ENTER CHARACTER/ALAPHBET : ";
for( i=0;i
{
cin>>symbol[i];
}
//******************************************************************//
cout<<"*ENTER HOW MANY LEVEL YOU WANT : ";
cin>>level;
cout<<endl;
if(level>8)
cout<<"PLEASE ENTER NUMBER BETWEEN 1 TO 8"<
|
|
|
|
|
Sorry for blowing off steam like this but...
Why is it when I use a MFC GUI control it just does not do what a normal naive programmer would think it would do !!!
I pop in a static text control, humm lets see lets change the text color...what? Not there...Ok lets change this windows background color what? what? what? I have to code all of this !!
I can understand if you want to do something out of the ordinary but I think colors and fonts are not all that special... It's 2007
I would think that the base classes would have been updated by now!
Am I missing something ? I am spending more time coding stuff like color, font, button effects than what the application is supposed to be doing ! Are you guys using a library or something for GUI controls?
I know codeproject has a couple of nice ones that work great but I feel I need to reinvent the wheel every time !
Could codeproject start an official GUI library, pick out the best controls from it's project bank and integrate them into the library ????
Just a though.
Sorry for the steam blowing...
Chris
|
|
|
|
|
Feel better now?
You can blame MFC for many things but windows and controls (which are windows) are part of the
operating system. MFC wraps the handles to these OS objects in an object-oriented way. There
may seem to be more functionality with all the MFC methods but most of the methods end up
calling OS APIs or combining calls to several APIs.
Depending on one's UI needs, this could be practically useless or very useful.
If you don't need an OO wrapper for the GUI APIs then MFC is useless.
If you do choose to use MFC you have a couple advantages right off the bat:
1) Windows are already subclassed for you.
2) Because it's implemented in C++, it's easy to derive classes and create your own library
which better suits your needs.
They could have added all kinds of functionality...then many of us would be blowing off steam
about how overbloated MFC with wasted code we never use.
If you find that you are using customized controls and windows alot in your projects then take
advantage of OO C++ and create your own library of code that can be reused.
I think that's the main spirit of MFC. Any claims that MFC is supposed to make Windows progamming
easier or less complex I've always thought were BS. Not only does one still need to know and
understand Windows programming, MFC adds the complexity of understanding C++ as well.
There's nothing wrong with not using MFC1 All the same functionality can be implemented a
different way (within the limits imposed by the OS).
Just my 2 cents...
Cheers!
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Yeah I doo feel better.
I can understand that MFC did this to be light weight and all, but it seems every new programmer starting off with MFC has to create their own library of code ! Effectively reinventing the wheel, while cursing the gods
Should they not have a repository or something ? I mean the old VB 6.0 GUI controls had more options than MFC, limited but basic stuff was there.
As for the bloated code doesn't the compiler remove code that is not being used at compile time ?
Anyway I think an opensource / free library of OO C++ classes that people have come up with would be a very useful resource to have.
Thanks for the comment.
Chris
|
|
|
|
|
Go ahead blow, it is good for the soul!
ChrisRibe wrote: Why is it when I use a MFC GUI control it just does not do what a normal naive programmer would think it would do !!!
Because a normal naïve programmer today thinks that someone else should have already done it for them. MFC is a wrapper around native API calls used to provide basic windows look and feel support. The MS IDE provides some class wizards to simplify some of the programming, but that is all. If you wish to provide more than that, then you need to add the code to support it or get a 3rd party library.
This is C++, which does not depend on the IDE, and not some language that normally hides behind a bunch of interfaces, that where probably written in C++ or C to begin with.
The above is just my opinion at the moment and could change without notice.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Sounds like you want to use C#/WPF instead.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
We have applications (MFC/C++) that use both "views" or "frames" that are always behind our HTML Help windows, but regular modal dialogs can sit in front of the Help.
Is there a way to specify for the "views" to come in front of the HTML Help window?
Thanks.
|
|
|
|
|
Hello,
My project is an MFC application; i am running into an application crash when user tries to select an object from the browse window. This does not happened when the user tries to do it with a single click, this happens only when user tries to drag the object a little bit while selecting. I have an option of making a copy of the object when the user tries to drag and drop it, but if the right click and drag is bit fast then the application crashes. My call stack shows these messages.,
> mfc71d.dll!AfxAssertValidObject(const CObject * pOb=0x00000000, const char * lpszFileName=0x7c142b9c, int nLine=33) Line 75 C++
mfc71d.dll!AfxOleGetMessageFilter() Line 33 + 0x15 C++
Util.dll!CInstanceListCtrl::OnBegindrag(tagNMHDR * __formal=0x03f5a9ac, long * pResult=0x03f5a664) Line 2590 + 0x5 C++
mfc71d.dll!_AfxDispatchCmdMsg(CCmdTarget * pTarget=0x03f5c444, unsigned int nID=0, int nCode=65427, void (void)* pfn=0x0072db00, void * pExtra=0x03f5a3d0, unsigned int nSig=57, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 119 C++
mfc71d.dll!CCmdTarget::OnCmdMsg(unsigned int nID=0, int nCode=65427, void * pExtra=0x03f5a3d0, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 396 + 0x27 C++
mfc71d.dll!CWnd::ReflectChildNotify(unsigned int uMsg=78, unsigned int wParam=1024, long lParam=66431404, long * pResult=0x03f5a664) Line 3251 + 0x23 C++
mfc71d.dll!CWnd::OnChildNotify(unsigned int uMsg=78, unsigned int wParam=1024, long lParam=66431404, long * pResult=0x03f5a664) Line 3205 C++
mfc71d.dll!CListCtrl::OnChildNotify(unsigned int message=78, unsigned int wParam=1024, long lParam=66431404, long * pResult=0x03f5a664) Line 606 + 0x18 C++
mfc71d.dll!CWnd::SendChildNotifyLastMsg(long * pResult=0x03f5a664) Line 3145 C++
mfc71d.dll!CWnd::ReflectLastMsg(HWND__ * hWndChild=0x000307b8, long * pResult=0x03f5a664) Line 3183 C++
mfc71d.dll!CWnd::OnNotify(unsigned int __formal=1024, long lParam=66431404, long * pResult=0x03f5a664) Line 2569 + 0xd C++
SelDlg.dll!0136999e()
mfc71d.dll!CWnd::OnWndMsg(unsigned int message=78, unsigned int wParam=1024, long lParam=66431404, long * pResult=0x03f5a698) Line 1771 + 0x28 C++
mfc71d.dll!CWnd::WindowProc(unsigned int message=78, unsigned int wParam=1024, long lParam=66431404) Line 1745 + 0x1e C++
mfc71d.dll!AfxCallWndProc(CWnd * pWnd=0x03f5b0b4, HWND__ * hWnd=0x000307de, unsigned int nMsg=78, unsigned int wParam=1024, long lParam=66431404) Line 241 + 0x1a C++
mfc71d.dll!AfxWndProc(HWND__ * hWnd=0x000307de, unsigned int nMsg=78, unsigned int wParam=1024, long lParam=66431404) Line 389 C++
Please suggest me in handling this crash.
With Rgds,
Anil
|
|
|
|
|
AnilUnni wrote: Util.dll!CInstanceListCtrl::OnBegindrag(
This shows that, you are doing some thing wrong in this function. Can you show code of this function?
|
|
|
|
|
This is my code prasad,
void CInstanceListCtrl::OnBegindrag(NMHDR* /*pNMHDR*/, LRESULT* pResult)
{
//NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
*pResult = 0;
// If no drop effects are allowed then just exit.
if (0 == m_dropEffectAllowed) return;
// Create an item list for all of the selected objects.
CPyrItemList* ppil = CreateSelectedItemList (m_fIgnoreClassFoldersInLists);
if (NULL == ppil) return;
// If we drag the data to another process and it takes a long time
// to complete the drop, it's possible for us to get "server busy"
// dialogs while we're waiting for the other process. So we want
// to turn off those dialogs now.
DISABLEOLEWARNINGBOXS;
// Create a data source to do the drag-drop and then do the
// drag-drop.
CPyrItemListDataSource DataSource;
DataSource.Create (*ppil);
/*DROPEFFECT dropEffect = */ DataSource.DoDragDrop (m_dropEffectAllowed);
delete ppil;
}
With Rgds,
Anil
|
|
|
|
|
At which line exactly does crash occurs ?
|
|
|
|
|
This crash refered in the stack is Line 2590 and this refers to a #define
DISABLEOLEWARNINGBOXS;
// Shut off both of the OLE not ready type dialogs (error dialogs)
// The busy dialog comes up at least when the app receives some window messages and
// is in an Automation call. These two calls will shut off the dialogs.
//
#define DISABLEOLEWARNINGBOXS \
COleMessageFilter* pfilter = ::AfxOleGetMessageFilter (); \
if (NULL != pfilter) \
{ \
pfilter->EnableBusyDialog(FALSE); \
pfilter->EnableNotRespondingDialog(FALSE); \
}
With rgds,
Anil
|
|
|
|
|
Hi,
I am adding a simple client program for my MFC GUI App using(or trying to use) CAsyncSocket. I am new to socket programming in general so naturally I would have some trouble. I have no control over the server app except to start it and tell it to start sending me data. I have tried this using CSocket first but I couldn't make the receive work and/so I want to use CAsyncSocket anyway because I think it would benefit me down the road. BTW...I am using VC++ 2005. Ok...so my problem is that when using the CASyncSocket object the OnConnect() and OnReceive() notifications aren't being called as far as I can tell.(I setup my object to only give those notifications) I have overidden them in my class derived from CAsyncSocket. I know my object is connecting to the server but the weird thing is that the connect fails but then it CONNECTS ANYWAY. Then I can send a command to it and the server begins sending data packets to me(I know this because I am watching the server print these statements to my command window.) The server is DOS executable. So...
1. The connect function fails but the OnConnect() does not get called...I think it should even if there was an error...but the connect really did happen just not before the connect function returned an error!? UPDATE: Every once in a while the OnConnectFunction does get called with an error code of 0.
So, the client is connected and as far as I know the server program is working and has been tested and says that is sending data but I am not getting any OnReceive() notifications. I still have to figure out exactly what to do once I get the notifications but I would be happy to see that I am getting them for now.
2. No OnReceive() when I am pretty sure I should be getting them.
So I am just wondering if I am doing something dumb...any ideas? Thanks in advance!
Code below....
<br />
CMySocket * m_pDASsocket;<br />
<br />
m_pDASsocket = new CMySocket;<br />
m_pDASsocket->Create(0,SOCK_STREAM,FD_READ | FD_CONNECT);<br />
<br />
<br />
char startstream = 100;<br />
<br />
if(m_pDASsocket->Connect("127.0.0.1", 1101) != 0)<br />
{<br />
m_pDASsocket->Send(&startstream,1); <br />
<br />
}<br />
else<br />
{<br />
Sleep(200);<br />
m_pDASsocket->Send(&startstream,1);<br />
<br />
}<br />
<br />
<br />
<br />
char stopchar = 0;<br />
<br />
if(m_pDASsocket->Connect("127.0.0.1", 1101) != 0)<br />
{<br />
m_pDASsocket->Send(&stopchar,1); <br />
m_pDASsocket->Close();<br />
}<br />
else<br />
{<br />
Sleep(100);<br />
m_pDASsocket->Send(&stopchar,1);<br />
m_pDASsocket->Close();<br />
}<br />
<br />
<br />
<br />
void CMySocket::OnReceive(int nErrorCode)<br />
{<br />
<br />
AfxMessageBox("OnReceive");
<br />
<br />
static int i=0;<br />
<br />
i++;<br />
<br />
TCHAR buff[4096];<br />
int nRead;<br />
nRead = Receive(buff, 4096); <br />
<br />
switch (nRead)<br />
{<br />
case 0:<br />
Close();<br />
break;<br />
case SOCKET_ERROR:<br />
if (GetLastError() != WSAEWOULDBLOCK) <br />
{<br />
AfxMessageBox ("Error occurred");<br />
Close();<br />
}<br />
break;<br />
default:<br />
buff[nRead] = 0;
CString szTemp(buff);<br />
m_strRecv += szTemp;
AfxMessageBox(m_strRecv);<br />
<br />
<br />
if (szTemp.CompareNoCase("bye") == 0 ) ShutDown();<br />
}<br />
CAsyncSocket::OnReceive(nErrorCode);<br />
<br />
<br />
}<br />
<br />
<br />
Clint Smith
|
|
|
|
|
1) ALWAYS check return values from socket calls.
2) Refer to #1 above
First of all - Lots of stuff that will help immensely can be found here[^]
With that out of the way...
By using the CAsyncSocket class and specifying FD_READ | FD_CONNECT in your Create() call you are
requesting the socket be created in non-blocking mode and that you want to receive notifications
on completed connect requests and when there's data available for receiving from the socket.
When a socket is in non-blocking mode, an error is returned from almost every call involving
network operations - connect/recv/send/etc. BUT, the error is WSAEWOULDBLOCK, which just means
the operation couldn't be completed immediately and is still in progress. You don't know of
success/failure until you receive a notification. In CAsyncSocket, the notification for
FD_CONNECT gets mapped to a call to OnConnect(). When data becomes available (is sent to the
socket) then your OnReceive() will be called.
So, starting at the top of your code:
m_pDASsocket = new CMySocket;
m_pDASsocket->Create(0,SOCK_STREAM,FD_READ | FD_CONNECT);
You've created your socket - cool. As mentioned above the socket is now non-blocking.
Next you connect to your socket.
Cool. Now it's time to check error codes, something like:
if(m_pDASsocket->Connect("127.0.0.1", 1101) != 0)
{
m_pDASsocket->Send(&stopchar,1);
m_pDASsocket->Close();
}
else
{
int nErrCode = m_pDASsocket->GetLastError();
if (nErrCode == WSAEWOULDBLOCK)
{
}
else
{
m_pDASsocket->Close();
}
}
By the way, the Sleep() call, although it may have worked when connecting to the local machine,
was a really bad idea, and totally negates the purpose of asynchronous sockets. It can often take
much longer than 200ms to connect
Note that you can't call Send() until the connect completes, indicated by OnConnect() being
called with error code 0:
void CMySocket::OnConnect(int nErrorCode)
{
if (0 == nErrorCode)
{
Send(&stopchar,1);
}
else
{
}
}
Make sense?
Hopefully that will help get started with connecting properly.
I'll reply again with more about the OnReceive() code.
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Hey Mark...thanks so much for your help. What your saying is making alot of sense. It seems like OnConnect() notification is working now. I haven't had a chance to try to receive anything but I wanted to thank you for your help. I will keep posting as I progress along.
Clint
csmithmaui
"Turn My Headphones Up!"
|
|
|
|
|
You're welcome.
C++ no ka oi
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Mark Salsbery wrote: You're welcome.
C++ no ka oi
Hey Mark...have you been to Maui before?
csmithmaui
"Turn My Headphones Up!"
|
|
|
|
|
Sadly, not yet.
My dad lives in Lahaina.
Maybe this year I'll finally get over there!
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Oh cool...yeah...it's great over here. Hope you get to come out!
Clint
csmithmaui
"Turn My Headphones Up!"
|
|
|
|
|
I want to! I'm a long time surfer. I gave up the corporate life to do my own project so I
could hopefully have time to travel and surf. I also stopped surfing so I could focus. That was
5 years ago LOL. I'm almost done thank goodness!
I have to get some place tropical. California definitely is not
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
All the stuff in my previous post applies to the "client" side of the connection.
You never mention a listening socket or using Accept() to accept a connection on the server.
Are you calling connect from both ends (if so, this won't work)?
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Mark...I am not calling from both ends as far as I know. The server is "listening" on the port. This is the only code that I have from the server. I didn't write it.
#define CMDSERVERPORT 1101
#define CMDSERVER_MAX_CONNECTIONS 4
struct sockaddr_in sockaddrinServer;
sockaddrinServer.sin_family = AF_INET;
sockaddrinServer.sin_port = htons(CMDSERVERPORT);
sockaddrinServer.sin_addr.s_addr = htonl(INADDR_ANY);
WSAStartup(MAKEWORD(1, 1), &wsadataSocket)
g_socketServerCommand = socket(AF_INET, SOCK_STREAM, 0))
bind(g_socketServerCommand, (struct sockaddr *)&sockaddrinServer, sizeof(struct sockaddr_in)))
listen(g_socketServerCommand, CMDSERVER_MAX_CONNECTIONS)
csmithmaui
"Turn My Headphones Up!"
|
|
|
|
|
Ok, thanks. I was looking at your posted code again and realized you had two sets of connect
code there
I hope the author of the server code understands that the second param to listen() just sets the
number of possible pending connections (default is 5), not the total max connections possible.
Setting it to 4 seems kind of....unnecessary
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
About the receive code...
From what I see above you are connecting, sending some data, and closing the socket. In that
case you are never going to get a FD_READ notification to trigger the OnReceive() call unless the
server happens to send some data fast enough at connect time. Unlikely.
There's two issues I see with your OnReceive handler, assuming it does get called before the
socket is closed:
1) You've maybe assumed you will receive the entire string in one call to Receive(). This is
not always the case. A successful recv() on a socket will return 1 or more bytes, up to the
number of bytes requested. If you receive one byte and you are expecting 10 bytes then you'll
need to handle that.
2) You are requesting 4096 bytes to receive. This is only ok (in your sample code) if you have a
communication protocol where the other end sends 4096 byte "packets" or you only plan on receiving
once before closing the socket. Generally with TCP you should know how many bytes to expect and
only receive that many, unless you cache received data and parse it later (or maybe on another
thread).
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
I receive the following error when doing the build:
Cannot open include file: 'Resource.h': No such file or directory
The resource.h file is physically located within the proper directory with the other source files. This just started happening. I was able to build with no problems prioor to this message. This is VC++ 6.0
Thanks
John P.
|
|
|
|
|