regular C++ code in a windows application

This is a discussion on regular C++ code in a windows application within the Windows Programming forums, part of the Platform Specific Boards category; by windows application I mean a program that opens up a window and uses winProc etc. I have a code, ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    6

    regular C++ code in a windows application

    by windows application I mean a program that opens up a window and uses winProc etc.
    I have a code, but If I insert a main() function on its own, the program stops working.
    How can you use a regular C++ code in a window? For example, creating a random string variable and printing it in a dialogue box?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    Windows programming links
    Read some of the Win32 tutorials.

    Basically, Windows GUI programs are just event loops. You get an event (key press, mouse move, click, etc etc), and you perform some action in response to that.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by tinder View Post
    by windows application I mean a program that opens up a window and uses winProc etc.
    I have a code, but If I insert a main() function on its own, the program stops working.
    How can you use a regular C++ code in a window? For example, creating a random string variable and printing it in a dialogue box?
    In windows the entry point is WinMain... not Main. At minimum you need a message dispatcher and a message loop.

    You can use c or c++ in your code as easy as not... just don't try to create a program inside a program...


    The Forger's Win32 API Tutorial is probably your best place to start it's totally C based and makes things pretty easy...

    You will also want documentation on windows function calls. For this you can use either MSDN Online or to get a full set of headers and tools along with the documentation you can download the Windows SDK

    BTW... you do know that you can create windows and message boxes from a console program...

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    6
    I am already reading The Forger's tutorial. However, every time I change anything (one I only changed the name of a menu item), it stops working correctly. Also, it doesn't really explain what many of the things do, and especially how to do it on your own. I have thoroughly read, for example, the section on menus, and every time I try to do it the way he does it, but with different names for the menu items, it doesn't work. I know I'm doing something wrong, but for the life of me I can't figure out what it is. And in addition, he certainly doesn't mention regular C code at all in any of what I've read, which is up to and including the section on dialogue boxes. All it has given me to go on are some example source codes, and how bits of them work. I'm sorry if I'm ranting, but the complexity of it just takes my brain and repeatedly bludgeons it with a cow.

    I didn't know you could create windows and message boxes from a console program. And I don't know how.

    Maybe this whole thing just isn't for me. Maybe programming in general isn't for me. Gah, Bah, and humbug. I doubt you will have had the patience or indeed the boredom to read this. But if you have you will be enlightened with the knowledge that I am going to beat my face against the wall on my right.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    That tutorial is loaded with explaination and example code... you need to sit down and go through it section by section, do all the examples, play with them until you understand... by the time you finish the tutorial you should be ready to try your first program on your own.

    While you're doing that why don't you post this code you're playing with... in code tags... and lets see what you're up to...

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    Or perhaps you should just dump the Forger's tutorial and start off with some real C++ GUI programming. Try Qt. It is praised by many and cross platform, and fully C++. No need to mess with C at all.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Elysia View Post
    Or perhaps you should just dump the Forger's tutorial and start off with some real C++ GUI programming. Try Qt. It is praised by many and cross platform, and fully C++. No need to mess with C at all.
    Oh crap here we go again!

    The question asked specifically about Windows API... CreateWindow() and resource editing... The OP said he wanted to do it that way.

    Please don't start this "Windows API sucks" garbage again...

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by tinder View Post
    I didn't know you could create windows and message boxes from a console program. And I don't know how.
    Ok here's a real simple example you can try... set up your IDE with a console program and try this...

    Code:
    #include <windows.h>
    
    int main (void )
      { puts("Mixed mode example..."); // prints on console window
         puts("windows message box from console proggy");
    
         MessageBox(NULL,"Click ok to exit this program","Message",MB_TOPMOST);
    
         puts("Y'all come back now, Y'hear!");
         return 0; }
    Maybe this whole thing just isn't for me. Maybe programming in general isn't for me. Gah, Bah, and humbug. I doubt you will have had the patience or indeed the boredom to read this. But if you have you will be enlightened with the knowledge that I am going to beat my face against the wall on my right.
    It's about attitude... Start any new endeavour fearing that you will fail and guess what happens... On the other hand a small bit of "I can do this!" goes a very long way.

    It's not simple programming... take your time, repeat lessons if you need to, but it will sink in...

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    Quote Originally Posted by CommonTater View Post
    Oh crap here we go again!

    The question asked specifically about Windows API... CreateWindow() and resource editing... The OP said he wanted to do it that way.

    Please don't start this "Windows API sucks" garbage again...
    The OP said no such thing.
    In fact, all I have seen is "oh, this is so complex, gah, maybe programming isn't for me."
    And the reason for those statements are likely because the OP is trying to use the wrong tool for the job.
    Let the OP decide.

    Quote Originally Posted by CommonTater View Post
    Ok here's a real simple example you can try... set up your IDE with a console program and try this...
    And so you spoon-feed the OP with more C code despite the fact that it was clearly established that the OP uses C++. Well done.

    It's about attitude... Start any new endeavour fearing that you will fail and guess what happens... On the other hand a small bit of "I can do this!" goes a very long way.

    It's not simple programming... take your time, repeat lessons if you need to, but it will sink in...
    It's also a matter of using the right tool for the job. If you use the wrong tool, it will be difficult and frustrating, and you are encouraging this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Elysia View Post
    The OP said no such thing.
    In fact, all I have seen is "oh, this is so complex, gah, maybe programming isn't for me."
    And the reason for those statements are likely because the OP is trying to use the wrong tool for the job.
    No Elysia... that is simply a blatently lame excuse to bang the drum for your effed up third party libraries again.

    Have you considered prozac ... I hear it does wonders for OCD and other forms of repetative behavior disorders.

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    No CommonTater, it is a solution for your excuse to always use Windows API for everything.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  12. #12
    Registered User
    Join Date
    Sep 2010
    Posts
    69
    Quote Originally Posted by Elysia View Post
    No CommonTater, it is a solution for your excuse to always use Windows API for everything.
    Perhaps because everything "Windows" is based on the API.

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    Everything in our world is made of molecules, but you don't see me putting together things of molecules.
    Computer software is done via assembly, but you don't see me putting together programs in assembly.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Elysia View Post
    Everything in our world is made of molecules, but you don't see me putting together things of molecules.
    Computer software is done via assembly, but you don't see me putting together programs in assembly.
    What a shame you would deny yourself these skills... and a sin that you would deny them to others.

    Really... I get the distinct impression your hatred of Windows API programming comes from a simple source... you tried it and couldn't do it... so now your failure is the gong you bang everytime the subject comes up. Anger from failure... absolutely nothing new.
    Last edited by CommonTater; 04-19-2011 at 08:32 AM.

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    o_O
    Nonsense.

    I don't use Windows API because it's a ........ty piece-of-crap, good-for-nothing, overcomplicated, disgusting C API, not because I can't use it. There you go.
    I don't deny someone anything. But suggesting that newbies should learn Windows API right off the bat is just plainly wrong. It takes experience and patience. What is the point if you don't need it?
    Using the right tool from the beginning makes everything easier.

    That said, so long as they know their alternatives, they are free to choose whatever they want.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help in transfoming C++ code into regular ansi C..
    By transgalactic2 in forum C Programming
    Replies: 18
    Last Post: 12-08-2008, 03:50 AM
  2. Windows application
    By andypandy in forum Windows Programming
    Replies: 6
    Last Post: 07-10-2007, 10:39 AM
  3. Windows application
    By andypandy in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2007, 02:09 PM
  4. Windows form application and Windows application
    By |Wiz| in forum Windows Programming
    Replies: 5
    Last Post: 10-01-2005, 04:14 PM
  5. Replies: 1
    Last Post: 09-18-2005, 09:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21