Thread: Use windows API functions in a GTK+ program?

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    47

    Use windows API functions in a GTK+ program?

    Is it possible to write the interface of a program using GTK+ (I find Windows API really hard and have yet to find a good tutorial on it). So can I use windows functions such as kb_event(); alongside my GTK+ interface?

    Cheers,

    Jake

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I would be very surprised if the GTK+ framework is not calling WIN API functions (it looks like a wrapper around the WIN API similar, but less mature than MFC).

    So yes. There could be confilcts although depending on the 'version' of the WIN API GTK+ is developed against (and the version of the SDK you are developing with).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    Avoid GTK
    Win32 api is very simple.
    Read MSDN and Petzold and you can do everything.

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > Avoid GTK
    There is no good reason to. The win32 api is not portable and hence usually a poor choice.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Win32 is not very simple either.
    A good portable framework is to be preferred.
    Further, the API is C, so if using C++, the framework idea is even more preferred.
    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.

  6. #6
    Registered User
    Join Date
    Sep 2008
    Posts
    47
    I am using C. I'm not sure really which way to go. I'm not fussed about portability with this project as it focuses mainly on some windows users anyway. But as it's only a small program (a window with two buttons that start a loop when pressed), I would rather not have to increase it's size by 13mb (GTK+ runtime files) and also would like a standalone exe file for ease of use. It's a very small thing that shouldn't need to have it's own folder in the program files or anything.

    Windows API: Harder (for me at least) - No need to include runtime (I assume it's already on all windows PCs?).

    GTK+: Easier - Need to increase file size by 13mb and also make user download multiple files for the runtimes. I don't mind this on bigger applications but this is a bit of an annoyance.

  7. #7
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by Jake.c View Post
    I am using C. I'm not sure really which way to go. I'm not fussed about portability with this project as it focuses mainly on some windows users anyway. But as it's only a small program (a window with two buttons that start a loop when pressed), I would rather not have to increase it's size by 13mb (GTK+ runtime files) and also would like a standalone exe file for ease of use. It's a very small thing that shouldn't need to have it's own folder in the program files or anything.

    Windows API: Harder (for me at least) - No need to include runtime (I assume it's already on all windows PCs?).

    GTK+: Easier - Need to increase file size by 13mb and also make user download multiple files for the runtimes. I don't mind this on bigger applications but this is a bit of an annoyance.
    I support you fully in your avoidance of the native API.

    Of course, as with anything else related to programming, it's pretty simple when you get into it. However, the way the message system is designed and so on, it makes for huge source files and a lot of ugly code. For most windows, your code will consist of a huge message loop with one gigantic switch statement, and then a lot of code inside those switch statements to handle the different messages.

    This is fugly and creates what I would like to call bracer hell. Bunch of them parenthesis and bracers all over, and hard to keep track of what's what, even with exemplary indentation.

    I do have a suggestion, though. For small programs, simply using a dialog window will suffice. The window is created through resource files almost entirely, and what's better is that it can be visually designed with drag-n-drop for all controls in visual studio.

    For the larger ones, you would have to do it the normal way with the API, or use GTK for sexier code.

    P.S: Your "please enclose code in code tags" feature sucks @ Cboard.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by IceDane View Post
    Of course, as with anything else related to programming, it's pretty simple when you get into it. However, the way the message system is designed and so on, it makes for huge source files and a lot of ugly code. For most windows, your code will consist of a huge message loop with one gigantic switch statement, and then a lot of code inside those switch statements to handle the different messages.

    This is fugly and creates what I would like to call bracer hell. Bunch of them parenthesis and bracers all over, and hard to keep track of what's what, even with exemplary indentation.
    Why can't you simply make a function for every message and call them from the message loop. This way it would look pretty much the same as it does in frameworks. Next time think before you say something like this.

    If you want portability, then GTK is the way to go (or some other cross-platform wrapper). Otherwise, it is a matter of taste. I don't like people bringing stupid reasons for why using WinAPI directly is bad when actually the only reason is that they're not comfortable with it.
    Last edited by maxorator; 01-21-2009 at 11:00 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Do not consider having the runtime a negative thing; it only needs to be downloaded & installed once and should be on every machine.
    Then you can just build and send your GTK executables anytime, anywhere.
    Unless the ones who are going to use it cannot download big files for some reason (slow connection), I would suggest GTK or some other framework.
    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.

  10. #10
    Registered User
    Join Date
    Sep 2008
    Posts
    47
    The only problem is I'm not advanced enough to make installers (to create the folders and put the runtimes in etc.), and as far as I'm aware (please correct me if wrong) you cannot download folders unless in zip format? I just want to have the best ease of use for the end user. Which is why I would have ideally liked just one .exe file which they can run from a shortcut on the desktop.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Ideally, you would like an installer. There are plenty of tutorials on the web, I am sure. There are even free installers!
    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.

  12. #12
    Registered User
    Join Date
    Sep 2008
    Posts
    47
    I guess I could check that out. I just think if it was me I'd wonder why such a small application needed to install. But I will take you advice. So would the process be something like. this? Download installer.exe > Make Program folder > download myapplication.exe > Check for runtimes > download runtimes (if not present) > place both in folder.

    And any additional GTK+ applications will also have to be placed in that folder to take advantage of the runtimes?

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It won't matter where the applications are installed when the runtimes are installed. They are global--or should be, otherwise it's a waste.
    I always like installers--even for small applications, because it saves the trouble of extracting and possible making shortcuts and it also makes it much easier to uninstall the application. So why not use installers?
    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.

  14. #14
    Registered User
    Join Date
    Sep 2008
    Posts
    47
    When I look at it that way, it makes alot more sense. You are a truly enlightening person. Thankyou =).

  15. #15
    Registered User
    Join Date
    Sep 2008
    Posts
    47
    I've been searching for a tutorial on how to make an installer in C on google but have found nothing. Does anybody know of any material?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Limitations on Win32 API functions
    By csonx_p in forum Windows Programming
    Replies: 5
    Last Post: 04-09-2008, 04:09 AM
  2. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  3. windows api functions, not working. requirements?
    By Mr.Bit in forum Windows Programming
    Replies: 5
    Last Post: 10-10-2007, 08:20 AM
  4. Multithreading with the Windows API
    By Xzyx987X in forum Windows Programming
    Replies: 7
    Last Post: 11-07-2003, 12:22 AM
  5. How do you toggle keys like Scroll lock without Windows API?
    By animeaholic in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 07:02 PM