|
Simple: recursion!
There is only one ntimes-variable (that's what staic means), and it is initialised only once when encountered the first time.
As long as it is below 100, recur() is calling itself, incrementing the variable.
When it reaches 100, a text is printed and all the pending recur()-function come to decrement ntimes.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
Thanks now i understand.. ^_^
~~~@@@###EZRA###@@@~~~
|
|
|
|
|
what don't you understand exactly ? the use of the static keyword, and how it works, of the principle of recursion ?
|
|
|
|
|
It is doing the same thing as the following:
int recur(int count)
{
if (100 <= count)
{
return count;
}
else
{
int c = count++;
printf("%d\n", recur(count));
return c;
}
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Alright, I have my GUI written in C and the other document is in command-line and written in C++. I'd like to the command-line code into my GUI on a click of a certain menu item(ID_CONVERT_DEAD) and I do not know how to do so.
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{<br />
switch(msg)<br />
{<br />
case WM_CREATE:
{<br />
HMENU hMenu, hSubMenu;<br />
HICON hIcon, hIconSm;<br />
<br />
hMenu = CreateMenu();<br />
<br />
hSubMenu = CreatePopupMenu();<br />
AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");<br />
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");<br />
<br />
<br />
hSubMenu = CreatePopupMenu();<br />
AppendMenu(hSubMenu, MF_STRING, ID_CONVERT_MM, "&MessengerMate");<br />
AppendMenu(hSubMenu, MF_STRING, ID_CONVERT_MIDDLE, "&Middle_Man(Coming Soon..)");<br />
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Convert to..");<br />
<br />
SetMenu(hwnd, hMenu);<br />
<br />
<br />
hIcon= LoadImage(NULL, "RidV.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);<br />
if(hIcon)<br />
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);<br />
else<br />
MessageBox(hwnd, "Could not load large icon!", "Error", MB_OK | MB_ICONERROR);<br />
<br />
hIconSm= LoadImage(NULL, "RidV16.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);<br />
if(hIconSm)<br />
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);<br />
else<br />
MessageBox(hwnd, "Could not load small icon!", "Error", MB_OK | MB_ICONERROR);<br />
}<br />
break;<br />
case WM_COMMAND:<br />
switch(LOWORD(wParam))<br />
{<br />
break;<br />
<br />
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);<br />
break;<br />
case ID_CONVERT_MM:<br />
<br />
break;<br />
case ID_CONVERT_MIDDLE:<br />
<br />
break;<br />
}<br />
<br />
break;<br />
case WM_CLOSE:
DestroyWindow(hwnd);<br />
break;<br />
case WM_DESTROY:
PostQuitMessage(0);<br />
break;<br />
default:<br />
return DefWindowProc(hwnd, msg, wParam, lParam);<br />
}<br />
return 0;<br />
}
All this info is just to give you an idea of what I want to do since I'm not too sure what the technical term for the procedure is. Also, whenever I move the installer out of the directory that the icons are in, it'll produce the errors and i'm wondering how to fix it to where no matter where the installer is, it shows the icons. I've already tried googling and searching through every C/C++ site out there on how about to do this but as I didn't know exactly what I was looking for I wasted hours so I decided to come to this message board for help.
Any help is greatly appreciated.
|
|
|
|
|
how's supposed to be called the command-line exe ?
can't you just use ::ShellExecute() ?
|
|
|
|
|
Alright, I'll try and make it clearer as I know my post probably didn't make much sense.
I don't want the command-line.exe, I want to incorporate the code that's in the command-line program into my GUI. I have the source files for the command-line program and would like to be able to put the source for the command-line into my GUI and be able to run the source I put from the command-line from a menu item(ID_CONVERT_DEAD). I just need to incorporate it into my GUI and Window app.
Does this clear it up a bit?
|
|
|
|
|
if you have the source, then what's the problem ?
can't you copy/paste the code you need in your new project ?
|
|
|
|
|
Can I show you the codes to everything?
Also, if I add all those I still don't know how to execute the certain commands on the menu item.
|
|
|
|
|
Hi, all.
I am encoutering some communication problem while using synchronous SOCKET.
I have a client which sends data to server with Gbps network in the speed of about 200kB/s. I invoke select function to judge whether I can send data everytime.If it fails I will re-create a socket to connect the server. But when I count the packets sent in client and received in server, I find they are not the same. why this happens? how to impove it?
|
|
|
|
|
What network protocol do u use?
Mohammad
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
|
From my little experience with winsock, I suggest that you do not re-create a socket everytime select fails (if 'fails' means that you cant write to the socket at the moment), but if 'fails' means that the connection fails, you should recreate a socket on the client AND put the socket on the server in listen mode.
I imagine that ur problem goes in the following scenario:
Client: Connect ,Server:OK
Client: Send ,Server: recv
Client: Send (fails) ,Server recv() no data
Client: Re-connect , Server (Still waiting for data) - not ready to welcome incoming connection
Regards,
Mohammad
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
I added a cbutton to a cstatusbar. the button comes with thick borders around it when viewed in xp style. how to remove the borders?(I have set noborders style to the status bar pane)
|
|
|
|
|
|
|
Is it possible to have a multi-document project and make one of the documents another executable from createprocess or shellexecute? I guess an example would be starting up the calculator inside a C++ MDI application AND have it be a child document.
Chris
|
|
|
|
|
Chris a "process" is NOT a "document". Please clarify.
led mike
|
|
|
|
|
I think I figured it out in a round about way. It looks like I am going to have to create a blank document and use createprocess to create a process and then position the process overtop the blank document to give a feel that it is inside the window. Ofcourse I am going to have to handle the size changes and the position changes but this is the only solution I have right now.
Chris
|
|
|
|
|
Chris, are you new to MFC? In MFC using the word "document" is associated to the CDocument class. CDocument is NOT a "window" or visual class but is designed to expose "data" elements of the application. It might be viewed as the "model" element of the Model View Controller design pattern.
chris175 wrote: position the process overtop the blank document to give a feel that it is inside the window
That sounds like a terrible hack and not advisable. Good luck with that solution.
led mike
|
|
|
|
|
I know it sounds like a terrible hack and I really cannot argue because it is a terrible hack, but if anyone has any better solutions, I would be greatly appreciative. My main goal is to be able to use C# Forms created in Visual Studio 8.0 in a C++ application in Visual Studio 6.0. I do not want to have to create an ActiveX control to do this.
Chris
|
|
|
|
|
chris175 wrote: My main goal is to be able to use C# Forms created in Visual Studio 8.0 in a C++ application in Visual Studio 6.0.
What? Why? What is the "business requirment" that calls for that implementation?
chris175 wrote: I do not want to have to create an ActiveX control to do this
Why not? That would be better than the other suggested solution.
led mike
|
|
|
|
|
led mike wrote: What? Why? What is the "business requirment" that calls for that implementation
The application I am working on needs to advance to the newer technology. The problem is that the project is so big that it cannot be upgraded at one time. That would take too long to fix, stop production for a time that isn't beneficial, and too many errors to fix.
led mike wrote: Why not? That would be better than the other suggested solution
I have never created an ActiveX control before. I think I remember reading or overheard someone saying that this may be a possible solution but I haven't found anything on the web to assist me with this option.
Do you know of a good link or tutorial as to how to do this with ActiveX and how to build one?
Chris
|
|
|
|
|
chris175 wrote: C# Forms created in Visual Studio 8.0 in a C++ application in Visual Studio 6.0.
Try this:
Create a mixed mode VC++ 8.0 DLL project with MFC support. This project will export a C++ class, in this discussion we call it "foo".
In the DLL You can create a window or dialog using things like CWinFormsView[^] or CWinFormsDialog etc.
Then in the VC6 project use the new DLL and import the C++ class "foo". Using the interface provided by "foo" the new VC8 DLL will create the window and collect the data from the user. The data can be exposed through the plain C++ class "foo" to communicate between the VC6 project and the VC8 DLL.
led mike
|
|
|
|
|
Very Interesting. I am going to try this. I really hope I am able to get it. I am guessing I can also create a VC8 C# DLL to do the same thing a VC8 C++ DLL can do with CWinFormsView? I really would like to use C# instead of C++. Its just easier.
Chris
|
|
|
|