|
-
Jun 7th, 2002, 06:17 PM
#1
Thread Starter
Frenzied Member
Code
Is there a way that i can convert this code from VB to C++? I am asking this in both the C++ and VB forum.
VB Code:
Public Declare Function GetTickCount Lib "kernel32" () As Long
Public Sub Pause(Interval As Long)
Dim Start
Start = GetTickCount
Do While GetTickCount < Start + Interval
DoEvents
Loop
End Sub
-
Jun 7th, 2002, 06:24 PM
#2
Frenzied Member
There is no DoEvents() in C++....so its going to get very complicated
-
Jun 7th, 2002, 06:25 PM
#3
Thread Starter
Frenzied Member
thats what i thought....i wasnt sure if it was gonna be as simple as VB....if anyone knows how to do it...that would be great.
-
Jun 7th, 2002, 07:41 PM
#4
It would look like this:
Code:
void Pause(HWND hWnd, unsigned long interval) {
unsigned long start = GetTickCount();
MSG msg;
while(start + interval > GetTickCount()){
if(PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg); DispatchMessage(&msg);}
}
}
The PeekMessage(), Translate- and DispatchMessage() calls act as DoEvents.
Z.
-
Jun 7th, 2002, 07:43 PM
#5
Thread Starter
Frenzied Member
-
Jun 7th, 2002, 07:48 PM
#6
-
Jun 7th, 2002, 08:57 PM
#7
Thread Starter
Frenzied Member
what should i put for hWnd though? I am making a console app....
-
Jun 7th, 2002, 09:08 PM
#8
Monday Morning Lunatic
In a console program you don't need DoEvents or its equivalent since it doesn't receive any (useful) events.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 7th, 2002, 09:09 PM
#9
Thread Starter
Frenzied Member
then what can i put in there to simulate the same effect as the VB code that i posted above.
-
Jun 7th, 2002, 09:11 PM
#10
Stuck in the 80s
What exactly are you trying to do? Like your code, why do you need this in there?
-
Jun 7th, 2002, 09:13 PM
#11
Thread Starter
Frenzied Member
well..at first i just wanted to know now i just want to put it in there to blink something..thats all.
-
Jun 7th, 2002, 09:13 PM
#12
Monday Morning Lunatic
To pause for a certain length of time in a console app, the easiest way is to #include <windows.h>, then call Sleep(milliseconds).
On POSIX systems there's usleep or nanosleep or something
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 7th, 2002, 09:15 PM
#13
Ah, didnt know it was a console app. In that case, Sleep() is good, or you can simply convert your code straight over, without the DoEvents at all.
Z.
-
Jun 7th, 2002, 09:18 PM
#14
Thread Starter
Frenzied Member
Sorry, I should have told you at first...most people using C++ make Win32 but since i am just starting out, i am gonna make simple console apps.
Also, if you make a Win32 Window using the CreateWindow API, what the form is called?
Like, in VB you'd have form1 and form2 and so on...how do you know what the form name is in C++ if you dont use the MFC.
-
Jun 7th, 2002, 09:20 PM
#15
Monday Morning Lunatic
Forms don't exist even as a concept. In VB a form is an abstract type which consists of a window and an associated set of VB code...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 7th, 2002, 09:46 PM
#16
Thread Starter
Frenzied Member
Well, in VB when you type Form2.Label1.Caption = "Hello World!", VB knows to go to Form2, how does C++ know which form to go to?
-
Jun 7th, 2002, 09:49 PM
#17
Monday Morning Lunatic
You can't do "Form.Label1.Caption" using the API.
It's all windows. For example, a button is a window, which is a child of a larger window.
Just forget any VB programming stuff right now if you want to do it in C++, trust me
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 7th, 2002, 09:55 PM
#18
Thread Starter
Frenzied Member
Should I keep learning console apps before i go into win32 programming or start learning Win32 programming?
If so, what are some good books for Win32 Programming and/or tutorials online?
-
Jun 7th, 2002, 09:58 PM
#19
Monday Morning Lunatic
Learn the language first, then move onto making Windows programs 
The winprog.org tutorial is probably the best
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 9th, 2002, 10:37 AM
#20
Thread Starter
Frenzied Member
I'm not in college, i'm in high school......or are you just saying that...
-
Jun 9th, 2002, 01:29 PM
#21
Stuck in the 80s
He's just saying that. Visual Basic does alot of things for you that it shouldn't. Windows are created automatically without you doing a thing, and properties are referenced in a nice manner. In C++, you have to create everything yourself. You have to specify the caption as you create the window. If you need to change it later, you use the SetWindowText() API. Everything is done through API.
So you're going to have to drop your concept of forms before you can start understanding. Did you look through the tutorials at the top of this forum?
-
Jun 9th, 2002, 07:15 PM
#22
Thread Starter
Frenzied Member
so it's like a webpage...everything is done by code. Doesn't the MFC make programming a windows program much easier and faster?
-
Jun 9th, 2002, 07:39 PM
#23
Stuck in the 80s
I suppose, but it also makes you include a bunch of dependencies. I like the API way.
-
Jun 10th, 2002, 02:36 PM
#24
And you shouldn't use it unless you know the API. You might get lost. No, you will get lost.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|