|
**********
*********
********
*******
******
*****
****
***
**
*
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
for (int r=1; r<10; r++)
{
for (int c=r; c>1; c--)
cout<<" ";
for (int j=r-1+1;j<=10;j++)
cout<<"*";
cout<<endl;
}
--------------------------------------
*
**
***
****
*****
******
*******
********
*********
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
for (int r=10; r>1; r--)
{
for (int c=r; c>1; c--)
cout<<" ";
for (int j=r-1+1;j<=10;j++)
cout<<"*";
cout<<endl;
}
return 0;
}
|
|
|
|
|
Read the guidelines[^] before making another post.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
Is there a question hidden in your post?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hello
I want to know how can i animate from triangle 1 to triangle 2 that we can see the movements.
i want to know how can i move characters that indicate that they moves.
tnx alot
|
|
|
|
|
:smacks-head: Of course, why didn't I understand that when I first saw your initial post?
Well, judging from your images, they're simply 10x10 blocks, with (the right-hand) 1/2 filled with characters. If you were to assume the windows co-ord system (the one your using when outputting to the console), where by (0,0) is at the top left of the screen, with (width-1, height-1) being at the bottom right you could view the problem like so:
Image 1: draw line from (0,0) to (9,9) - fill in any pixels to the right of this line up to X=9
Image 2: draw line from (9,0) to (0,0) - fill in any pixels to the right of this line up to X=9
You need to animate between the two.
---
(1) Since the block is 10 stars wide, you'll need 10 frames
(2) The middle frame would be - draw line from (4,0) to (4,9) - a vertical line.
Hmm perhaps we could run a 10 iter loop -
iterNum = 0 .. 9
x1 = iterNum
y1 = 0
x2 = 9-iterNum
y2 = 9
FillBetweenAndToRightOf(x1,y2, x2,y2)
endLoop
You'll obviously have to come up with the FillBetweenAndToRightOf function yourself.
Your above tricks won't work when it comes to determining how many spaces to print before you start printing * characters, this time you'll need to calculate the gradient of the line
Recall that gradient = rise/run.
For img1, your X pos varies by 10(from 0-9), as the Y pos changes by 10(from 0-9). Therefore the gradient is 10/10 = 1.
You can then multiply the gradient by the Y pos, add this to X1 to find the first * character on the line. E.g row 4 (0 based) 4*1 + 0 = 4.
For img2, your X pos varies by -10 as the Y pos changes by 10. This time the gradient is -10/10 = -1
E.g row 4 (0 based) 4*-1 + 9 = 5.
Simply draw the figure 10 times with changing values of x1 and x2, using the above formulas to calculate where to start and how many stars to draw on each line.
|
|
|
|
|
tnx alot for your help
i must work on it and tell you again.
tnx
|
|
|
|
|
Rotating on which axis?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
hello
in -X axis
tnx alot
|
|
|
|
|
X-axis meaning horizontal? Are wanting it to rotate top over bottom? Which of the 10 rows (of the triangle) will be the pivot point? How many rotations are there between triangle 1 and triangle 2?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
*********
********
*******
******
*****
****
***
**
*
#include <iostream>
using namespace std;
int main()
{
for (int r=10; r>1; r--)
{
for (int c=r; c>1; c--)
cout<<" ";
for(int p=r;p>1;p--)
cout<<"*";
cout<<endl;
}
|
|
|
|
|
Is there a question here someplace, or do you just randomly post code snippets for grins?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
So I thought I understood the wndproc, in which it loops and listens for WM messages. But I guess if you run a function, the wndproc stops looping until the function stops, and then the wndproc listens again.
So is that where callbacks come into play?. If I run a function, I have to have a callback, that's like a mini wndproc?
Which leads to threads,
If I call a function like downloading a file, I hand off the function process to a new thread, and let that worker do the tasks, and just forget about it until it done or the cancel button is clicked.
Now Threads, I tried this one first.
http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=1273[^]
I'm just lost on how to get the tread working, and test it to see if it really works. I'm missing a big piece to this here
CThread ct;
ct.CreateThread;
sleep for awhile
during sleep, I should be able to click my cancel button -> wndproc capture. Pop a message box off.
done - destoy thread.
|
|
|
|
|
jkirkerx wrote: But I guess if you run a function, the wndproc stops looping until the function stops, and then the wndproc listens again.
True.
jkirkerx wrote: If I run a function, I have to have a callback...
Search for message pump.
For more on threads, see here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Thanks Dave, Will look into the Message Pump,
The Thread lesson looks good.
|
|
|
|
|
Sticking just to threads:
Go to the basics, the Windows API first. The problem with classes is that they help you but you have to do it the way the class author wanted it done. That doesn't help you learn threads, only gives you some magic to make it work. Personally I hate magic and need to see behind the curtain.
All you need to start is one function,
long thread_id;
HANDLE h = _beginthreadex(NULL, 0, ActuallyGetStats, NULL, 0, (unsigned *)&thread_id);
and some code with the proper calling conventions
unsigned int __stdcall ActuallyGetStats(void *)
{
return ERROR_SUCCESS;
}
This will run as a separate thread. You can put some code in there to, let say, loop 10 times, sleeping for 10 seconds each time and printing / TRACE() a message saying "I'm alive". You can also set breakpoints in there.
Now you can do some tests on the returned HANDLE in the main code to see if it's done or you can do other things. In my case, that _beginthreadex() call is done when a button is pushed on the GUI, kind of like what you had in mind.
You can also pass parameters to the function that it can use to get pointers to objects that might tell it what to do. That would be in the 4th parameter, which I've set to NULL here because there are no arguments needed.
Anyway, this is the basic start of a thread. It might be easier to play with than figuring out somebody's conventions in a class.
|
|
|
|
|
I must concur on your standing of using other peoples code. That has always gotten me into trouble in the past and the present. That's why I wrote my own IBindCallbackStatus, and did not use the example code, and I fully understand how my code works - The WCHAR issue a couple of days ago.
I'll start 1 statement at a time, and build it up, and look into that message pump that Dave mentioned.
Oh, 1 question, at what point should I start the thread, at button click, or inside the function that is called with button click?
Button Click "Next"
call function - "Prepare" - adjust buttons and artwork, setup progress bar, setup cancel button, check previous
call function - "download" - Start bind callback - start URLFileDownload
Return to window
Thanks Chunk.
|
|
|
|
|
I start the thread in the processing of the button click, in the routine pointed to by ON_BN_CLICKED() entry in the message map.
Where you start yours is up to you but I like to keep the functions of the GUI in the GUI so if you have some "pretty up" work to do, I say do that in the GUI module and then fire up the thread to do the work.
As for the Message Pump, really, I don't think you need to look into that. Basically if the GUI thread is working normally, not freezing while you are doing other processing, etc then it is already using its own message pump and should you should *not* do one yourself. If you move the long running processes into another thread, then the GUI thread should remain responsive.
An alternative message pump is only necessary when you jam all sorts of processing into your message processing routines, like if you tried to do the download inside the routines called when the button was clicked. And, there are folks out there who will say that providing your own message pumps is a hack and should never be done (and you know who you are ) so I'd say hold off discussion on message pumps until you are in the mood to deal with the purists (for the record, I am not one and I do use message pumps when necessary, and no, they are not a hack )
|
|
|
|
|
I understand that other's code can be more confusing than helpful at times, with this in mind I'll present this simple example in the hope it's not confusing.
I've just created the most simple dialog app I can. There's a single dialog with a test button and a quit button. Hitting the test button starts 10 threads, each with a different timeout value. Upon timeout, the thread sends a message to the main window which then sounds a message beep.
Hope it's of use..
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <process.h>
#include "resource.h"
#include <stdio.h>
#define WM_THREAD_COMPLETE WM_USER+1
typedef void (*voidFuncPtr)(void*);
typedef struct
{
int delayMs;
int myThreadId;
voidFuncPtr callbackFunc;
long winThreadId;
uintptr_t handle;
} threadHeader_t;
HINSTANCE hInst;
HWND mainDlgHwnd;
threadHeader_t threadList[10];
unsigned int __stdcall myThreadFunc(void *data)
{
threadHeader_t *header;
header = (threadHeader_t *)data;
printf("In thread func %d, delay %dMs\n", header->myThreadId, header->delayMs);
Sleep(header->delayMs);
if (header->callbackFunc)
header->callbackFunc(header);
return ERROR_SUCCESS;
}
void myCompletionCallback(void *data)
{
threadHeader_t *header;
header = (threadHeader_t *)data;
PostMessage(mainDlgHwnd, WM_THREAD_COMPLETE, header->myThreadId, 0);
}
void onTestBtn()
{
int i;
for (i=0; i<10; i++)
{
threadList[i].callbackFunc = myCompletionCallback;
threadList[i].delayMs = (10-i)*1000;
threadList[i].myThreadId = i;
threadList[i].handle = _beginthreadex(NULL, 0, myThreadFunc, &threadList[i], 0, (unsigned *)&threadList[i].winThreadId);
}
}
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
mainDlgHwnd = hwndDlg;
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
case WM_THREAD_COMPLETE:
MessageBeep(MB_OK);
return true;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BTN_TEST:
onTestBtn();
return TRUE;
case IDC_BTN_QUIT:
EndDialog(hwndDlg, 0);
return TRUE;
}
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst = hInstance;
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}
|
|
|
|
|
An excellent sample, I may well have a use for it.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I still use beginthread() and beghinthreadex() alot, but have used CWinThread with MFC apps, it is pretty simple to use: http://msdn.microsoft.com/en-us/library/48xz4yz9(v=vs.80).aspx[^]
From a thread you can post progress info or completion info back to your main windows message handler specifying a WM_USER+xxx value (ie, a custom message).
==============================
Nothing to say.
|
|
|
|
|
That's food for thought.
I 'm not really sure what MFC is. I think it's a c++ with more pre-written wrappers, and puts in closer to vb or c-sharp in terms of ease of use.
I opted for the win32 to get a real feel for programming at a low level, and would prefer to stay away from MFC for a few more months. That way I'll have a better understanding of VB, CS, and MFC in the future.
I gonna work on exiting the thread today, in the normal state, and try to work out some sort of per-staging for canceling the loop, and exiting the thread. Then I just have to figure out the messaging.
Once I get this working, I'll try a dialog box with multiple downloads and threads, that gets all the pre-requisties for the program at once.
|
|
|
|
|
jkirkerx wrote: I 'm not really sure what MFC is
MFC is a set of classes writtn in C++ that wrap the WIn32 API.
I like it. It is easy to use, quick to develope, and effective.
If you are using the win32 api then just use the beginthread() func.
==============================
Nothing to say.
|
|
|
|
|
Does it make real windows programs?.
I wrote a one click app in vb, and it's a pain in the a** to maintain and deploy. The program I'm writing now is to replace the vb program I wrote. The program below. It's so hard to package and deploy that program, that it's not worth the effort.
http://www.ice5commerce.com/Applications/suWizard_2012/SetupWizard.html[^]
I made a huge mistake in the program, in which I tried to make it support XP and Vista, and it bombs on XP because I could not deploy the Microsoft.Web.admin.dll to XP. I had to rely on the web server dll to get the path to the website, so I can find the AppData Folder.
|
|
|
|
|
jkirkerx wrote: Does it make real windows programs?.
Of course.
I would suggest using MFC, but, you need to go through one of the MSDN tutorials first, it can be a little complex at first to get to know the tools.
==============================
Nothing to say.
|
|
|
|
|
I just don't want to load that c++ redistribute program
|
|
|
|
|