Results 1 to 24 of 24

Thread: Code

  1. #1

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407

    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:
    1. Public Declare Function GetTickCount Lib "kernel32" () As Long
    2. Public Sub Pause(Interval As Long)
    3.     Dim Start
    4.     Start = GetTickCount
    5.     Do While GetTickCount < Start + Interval
    6.     DoEvents
    7.     Loop
    8. End Sub

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    There is no DoEvents() in C++....so its going to get very complicated

  3. #3

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    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.

  4. #4
    Zaei
    Guest
    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.

  5. #5

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    cool thanks

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Nifty
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    what should i put for hWnd though? I am making a console app....

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  9. #9

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    then what can i put in there to simulate the same effect as the VB code that i posted above.

  10. #10
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    What exactly are you trying to do? Like your code, why do you need this in there?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    well..at first i just wanted to know now i just want to put it in there to blink something..thats all.

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  13. #13
    Zaei
    Guest
    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.

  14. #14

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    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.

  15. #15
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  16. #16

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    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?

  17. #17
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  18. #18

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    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?

  19. #19
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  20. #20

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    I'm not in college, i'm in high school......or are you just saying that...

  21. #21
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  22. #22

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    so it's like a webpage...everything is done by code. Doesn't the MFC make programming a windows program much easier and faster?

  23. #23
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I suppose, but it also makes you include a bunch of dependencies. I like the API way.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  24. #24
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width