|
I am animating a ball and I need something faster then what I'm getting with the form Timer() control.
Is there anything faster that I can use to speed up the animation?
Thanks.
|
|
|
|
|
You want less than a millisecond? Our eyes cannot even see such speed. I do not know of anything that is faster than a timer in .NET... If your animation is not running to subtle, maybe you should look for smaller pixels or move the image by more than a dot instead of faster images.
No idea how to do that though. Just saying speed might not be the problem.
It's an OO world.
|
|
|
|
|
I'm testing the collisions with a brick with pixel accuracy. It's the only way I could get the collision working properly.
|
|
|
|
|
Cyclone_S wrote: It's the only way I could get the collision working properly.
Obviously there are other ways. Here are a few ideas:
1. you don't need to draw anything to detect collisions, you could do it mathematically. That is modelling rather than animation. The model would generate the exact time and location of the collisions, animation would only be used to show the required frames.
2. even when collision detection is based on actual frames, you don't need to do it in real-time, you could calculate a number of new frames ahead of time (at the expense of more memory), and only show some of them, at the right pace.
Either way, you may choose to use floating-point for extra accuracy while calculating, and turn the relevant data into integers when calculating the actual frames.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
|
Try System.Diagnostics.Stopwatch
David Anton
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
|
|
|
|
|
|
Timer () only to 1 Ms fastest, write their own a Delay ().
|
|
|
|
|
I'm still new to programming in Windows, so don't kill me if the answer is obvious.
What I've attempted to do is write my own WinMain function. I've based it off of Visual's generated code with a little Programming Windows mixed in combined with my own code.
Well it doesn't work, but I can't spot why.
#include <Windows.h>
#include <strsafe.h>
ATOM RegisterMyClass(HINSTANCE, wchar_t*);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void ErrorExit(LPTSTR lpszFunction);
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hpInst, LPSTR cmd, int nCmdShow)
{
HWND hwnd;
MSG msg;
wchar_t myWndClass[] = L"AWindow";
wchar_t myWndTitle[] = L"My Window";
RegisterMyClass(hInst, myWndClass);
hwnd = CreateWindowW(myWndClass, myWndTitle, WS_OVERLAPPEDWINDOW,
10, 10, 300, 300, NULL, NULL, hInst, NULL);
if ( hwnd == NULL )
ErrorExit(L"CreateWindow");
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while ( GetMessage (&msg, NULL, 0, 0 ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
ATOM RegisterMyClass(HINSTANCE hInst, wchar_t* wndClass)
{
WNDCLASSEX w;
w.cbSize = sizeof(WNDCLASSEX);
w.style = CS_HREDRAW | CS_VREDRAW;
w.lpfnWndProc = WndProc;
w.cbClsExtra = 0;
w.cbWndExtra = 0;
w.hInstance = hInst;
w.hIcon = LoadIcon(NULL, IDI_APPLICATION);
w.hCursor = LoadCursor(NULL, IDC_ARROW);
w.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
w.lpszMenuName = NULL;
w.lpszClassName = wndClass;
w.hIconSm = NULL;
return RegisterClassEx(&w);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
HDC hdc;
PAINTSTRUCT ps;
switch (msg)
{
case WM_CREATE:
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hWnd, msg, wp, lp);
}
return 0;
}
void ErrorExit(LPTSTR lpszFunction)
{
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
ExitProcess(dw);
}
Using Microsofts own ErrorExit code, I get the following message when CreateWindow returns NULL:
CreateWindow failed with error 0: the operation completed successfully
What confuses me is that the MSDN documentation on CreateWindow() says that if the function fails, it returns NULL and to use GetLastError to find out what it was. Well, it returns a null, but then reports that there is no error.
I'm seriously boggled by this one.
|
|
|
|
|
Ah, so close....You've got a very subtle error in your WndProc.
Change your default handling to this:
default:
return DefWindowProc(hWnd, msg, wp, lp);
Your code was dropping the return code of DefWindowProc on the floor and returning zero which is bad news.
Returning zero from WM_NCCREATE instructs CreateWindow to stop the window creation. DefWindowProc will return 1 instead of 0 and allow the creation to proceed.
John
|
|
|
|
|
I knew it had to be something incredibly simple *smacks palm to forehead*. Thanks a bunch.
|
|
|
|
|
hi!
Help me to read data from Comport RS232:
My function to sent data to RS232:
private: public: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Random^ gen=gcnew Random;
serialPort1->Write(Convert::ToString(gen->Next(0,100)+"P"));
}
and my function to read data from RS232
public: System::Void serialPort1_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e) {
String^ st = serialPort1->ReadExisting();
button1->Text=st;
}
i can buid solution.After that i conect pin 2 and pin 3 of COMPORT.Next when run program had error nowbutton1->text=st;
|
|
|
|
|
Hi,
most if not all asynchronous events are handled by threads from the ThreadPool, not by the main thread, which means you can't touch GUI Controls right away from those handlers. You need to use InvokeRequired/Invoke, as I explain in this article[^] of mine (with C# and VB.NET examples, no C++/CLI, sorry, although the principles are exactly the same).
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
My friend, your code is written with what IDE? I have a VC6.0 example, but I don't know how to upload, you leave the email address, I send you a past
|
|
|
|
|
Thanks you LiangGuangLin ! my email: bqhoang89@gmail.com
|
|
|
|
|
Hi.
I want to statically link to a DLL, 'USBm.dll'(From USBMicro.com, a Hardware Interface that allows one to interface Relays etc. via a USB device they sell.)
I use VC5.00, so I require a Lib file to link with. My Compiler generates from a C-function named foo() the 'Decorated' name: '_foo' (it adds a leading Underscore). Unfortunately, the functions in the DLL are exported without such leading underscore. (The DLL has Borland Compiler suggestions in the way it was put together, I suspect that that's the compiler they (who wrote the DLL)use)
Normally I would create a DLL project with 'DoNothing' functions for each of the functions in the DLL Header. Discard the DLL, but, keep the Lib.
How do I convince My VC 5.00 compiler to emit obj files without decorating the function name. Is there an Obscure Command Line Switch
Regards,
Bram van Kampen
|
|
|
|
|
Hi Bram,
this sounds like a native C/C++ question, not a managed C++/CLI question, hence IMO you're in the wrong forum.
If your code is native C, I know of three ways to avoid C++ identifier decoration:
1. use the .c extension; that should be enough to tell the compiler it is not C++ code, it works for Visual Studio.
2. use some compiler switch, depends on the specific tool suite.
3. use the extern "C" keyword thingies, as in:
extern "C" {
}
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: this sounds like a native C/C++ question, not a managed C++/CLI question, hence
IMO you're in the wrong forum.
Well, the forum for C/CPP seems to have disappeared, to be replaced by a Question/Answer Message Board
Luc Pattyn wrote: extern "C" {
}
This Still decorates the names with a leading underscore
Bram van Kampen
|
|
|
|
|
Bram van Kampen wrote: C/CPP seems to have disappeared
I see it in the alphabetical list at the left, between ATL and C#.
Bram van Kampen wrote: This Still decorates the names...
It shouldn't. Anyway, I gave you three ways. If none of them work for you, I can only suggest you read the manual that came with your IDE.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi,
I just found a C# example for creating a word document using OpenXML format which I've linked below. Can you please help me write the same in C++/CLI or suggest me any links where I can find c++\cli openxml sdk creating a word doc examples or any tutorial related to this.
Creation of a Word 2007 document using the Open XML Format SDK[^]
thanks an advance
|
|
|
|
|
"OpenXML" is the format of the document.
That doesn't have anything to do with C++ nor C#.
Rather you write code to produce that. In either C++ or C#.
The basic format is XML. So any C++ library that allows you to output XML would assist you in writing XML allows you to do that.
Actually for the tutorial link given you do not even need a library. One can use simple output statements.
And that should be sufficient if you understand how to program in C++ and have a basic understanding of XML and are willing to learn the standard for OpenXML.
If not then you have a different problem. You certainly can't do anything if you do not have a basic grasp of C++. To use OpenXML you do need a basic understanding of XML and if you do not have it then attempting OpenXML is NOT the way to start. Additionally that is not the only way to create a Word doc if that is your actual requirement.
|
|
|
|
|
Hi,
I have launched a process (another exe) from my application using the following:
CreateProcess(NULL,pCmdLine,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi);
So now the requirement is that to pass different pCmdLine to the same process, if it's already running.
So how can I do this in VC++?
Please provide me some sample code.
|
|
|
|
|
If it's a console app then you can only pass parameters to it on invocation, i.e. in your CreateProcess() call. If it's a Windows app then you can use SendMessage() to send private messages to it.
The best things in life are not things.
|
|
|
|
|
Hi,
I have one linux cpp executable file. i want how to run this executable file in windows OS?.
please give any idea? or urls
Regards,
M.Mathivanan
|
|
|
|
|
Hi,
1.
you're in the wrong forum, C++ on Linux most likely will be "native C++", not be "managed .NET code".
2.
it has been many years ago I last did this, back then "cygwin" was the answer. Try Googling it.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|