Results 1 to 3 of 3

Thread: Win32 Under the hood

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Posts
    282

    Win32 Under the hood

    Win32 Under the hood::

    Sequal to http://www.antionline.com/showthread...419#post645419

    Lets pop the hood and see what makes Windows tick. While keeping things simple. At this point we will use the C language to look at examples, Its easyer to folow for beginers then a bunch of C++ classes. The requirements is that you have a C/C++ compiler, suports 32bit and check to see you have a windows.h inside your include folder.

    Grab a copy of win32.hlp file from http://www.vinaeus.com/resource.htm
    Read this as your Bible to win32. Refer to this always, if you dont know what a function does, or what its parameters are or how to use it, look it up

    The first of your programs will always #include <windows.h>, this is what gives you access to the Win32API. Some compilers may require a linker option.

    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>

    We define WIN32_LEAN_AND_MEAN because this will exclude extra headder files that windows.h would normaly include. As your first few Win32 programs will have no need for these extras. As your programs advance you will undoubtably need to remove the ofending line.

    As most would be familiar, main() is the entery point for a DOS or console application. Native Win32 apps begine executation at WinMain. In DOS we passed command line arguments, these argv I believe were arguments passed to main(). In case of Win32 Windows fills in the arguments to WinMain:

    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShow);

    First we gasp at WINAPI, this is a calling convetion, basicaly has to do with memory, stack and how functions are called. This is the least of our wories. HINSTANCE and LPSTR may apear as new data types to you however they are just an alias for standard C types

    typedef char * LPSTR
    typedef void * HINSTANCE

    They get included by windows.h. hInst is a pointer or handle to our executable. hPrevInst is nolonger used, its left over from 16bit Windows. lpCmdLine is a command line, this is optional and ads functionality to your app. nShow indicates to your application the way your window is suposed to start out, minimized, maximized...When you create a shortcut on your desktop, this is controlled in properties.

    Windows takes care of filling in these parameters. So now we need to do something with this knowledge. Well lets start with a easy to use and understand function MessageBox.

    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShow){

    MessageBox(NULL, "This is a message box!", "Title", MB_OK);

    return 0;
    }

    The first argument, is suposed to be a handle to our parent window but we dont have one. Next a pointer to a null terminated string containing our message text, and another containing the title. MB_OK says we want an ok button in our message box. MB_OK is define as a macro inside winuser.h included by windows.h

    #define MB_OK 0x00000000L

    If you compile, and you get not compiler or linker errors you should see a nice message box.

    }

  2. #2
    Senior Member
    Join Date
    Jan 2002
    Posts
    1,207
    Hardly "Under the hood" though is it?

    More like "Where to put the petrol in"

    Slarty

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Posts
    282
    very true, always have dificulties generating titles.

    Gona lay off the Win32 tuts for a while don't want to get caryed away. Thanks BTW for helping to fill in more on the portablility of Win32 in Linux for me in the other tut.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •