Results 1 to 3 of 3
  1. #1
    Mr. Bond's Avatar
    Join Date
    Mar 2008
    Gender
    female
    Posts
    14
    Reputation
    10
    Thanks
    2

    [C++]Using Windows Application Programming Interface to Create a Window

    Yo, me again. We're going to create a window using Win API(Application programming interface)
    Big thanks to MSDN for referencing.

    THIS TUTORIAL ISN'T COMPLETE READ BOTTOM

    We're going to need the windows.h header file for this so at the top of your project add this~
    Code:
    #include <windows.h>
    const char g_szClassName[] = "WindowClass";
    You can use '#define WIN32_LEAN_AND_MEAN' to cut out all the crap that you don't need in windows.h; But I'm not going to do that in this tutorial. We will use g_szClassName later on

    After that add this~
    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    }
    The WinMain function is the entry point of our program.
    Parameters
    hInstance : Handle to the instance of our program;
    hPrevInstance : Won't go into too much detail, this parameter is always NULL unless you set it up properly;
    lpCmdLine : Holds the command line for our application;
    nCmdShow : Specifies how the window is shown, refer to MSDN for a list of values;

    Next Add:
    Code:
    WNDCLASSEX Window;
    HWND hWnd;
    MSG Msg;
    WNDCLASSEX Window : Main structure for our window, this holds information like what resources to add, the class name etc.
    HWND hWnd : We will use this to create our window
    MSG Msg : This is what we use to handle 'messages' (basically pressing buttons on the program, clicking etc.)

    Next we will fill our Window Structure, Add:
    Code:
    Window.cbSize = sizeof(WNDCLASSEX);
    Window.cbClsExtra = 0;
    Window.cbWndExtra = 0;
    Window.style = CS_HREDRAW | CS_VREDRAW;
    Window.hCursor = LoadCursor(NULL, IDC_ARROW);
    Window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    Window.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    Window.hInstance = hInstance;
    Window.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
    Window.lpfnWndProc = WndProc;
    Window.lpszClassName = g_szClassName;
    Window.lpszMenuName = NULL;
    Members of the structure:
    cbSize : The size of our structure, sizeof does this for us.
    cbClsExtra and cbWndExtra : Always set these to 0 for now. I might cover these in a later tutorial;
    style : Specifies the class style(s), refer to MSDN for a list of values;
    hCursor : Specifies what cursor to use for our application, refer to MSDN for a list of values to change 'IDC_ARROW' too;
    hIcon : The icon that will show for our program in explorer;
    hIconSm : The small icon that will show to the top left of our program;
    hInstance : Just always set this to hInstance for now, if it's not done in the WINAPI method then use GetModuleHandle(NULL); instead.
    hbrBackground : The background color of our program;
    lpfnWndProc : Reference to what will handle our messages;
    lpszClassName : The Windows class name;
    lpszMenuName : We can use this to add menus to our program.

    Now we've filled the Window struct we have to use RegisterClassEx to register it!
    Code:
    if(!RegisterClassEx(&Window))
    {
       MessageBox(NULL, "Error registering Window", "Error", MB_ICONWARNING);
       return 0;
    }
    This reads:
    If RegsterClassEx(&Window) returns false then Window was not registered so show message box and end program;
    Other then that you don't really need to know much about this function;

    Now we need to use CreateWindowEx to create our window then soon after showing it!

    Code:
    hWnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            g_szClassName,
            "The title of my window",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
            NULL, NULL, hInstance, NULL);
    I found a better explanation of this function compared to what i came up with so here it is Credits to theForger;

    "The first parameter (WS_EX_CLIENTEDGE) is the extended windows style, in this case I have set it to give it a sunken inner border around the window. Set it to 0 if you'd like to see the difference. Also play with other values to see what they do.

    Next we have the class name (g_szClassName), this tells the system what kind of window to create. Since we want to create a window from the class we just registered, we use the name of that class. After that we specify our window name or title which is the text that will be displayed in the Caption, or Title Bar on our window.

    The parameter we have as WS_OVERLAPPEDWINDOW is the Window Style parameter. There are quite a few of these and you should look them up and experiment to find out what they do. These will be covered more later.

    The next four parameters (CW_USEDEFAULT, CW_USEDEFAULT, 320, 240) are the X and Y co-ordinates for the top left corner of your window, and the width and height of the window. I've set the X and Y values to CW_USEDEFAULT to let windows choose where on the screen to put the window. Remeber that the left of the screen is an X value of zero and it increases to the right; The top of the screen is a Y value of zero which increases towards the bottom. The units are pixels, which is the smallest unit a screen can display at a given resolution.

    Next (NULL, NULL, g_hInst, NULL) we have the Parent Window handle, the menu handle, the application instance handle, and a pointer to window creation data. In windows, the windows on your screen are arranged in a heirarchy of parent and child windows. When you see a button on a window, the button is the Child and it is contained within the window that is it's Parent. In this example, the parent handle is NULL because we have no parent, this is our main or Top Level window. The menu is NULL for now since we don't have one yet. The instance handle is set to the value that is passed in as the first parameter to WinMain(). The creation data (which I almost never use) that can be used to send additional data to the window that is being created is also NULL.

    If you're wondering what this magic NULL is, it's simply defined as 0 (zero). Actually, in C it's defined as ((void*)0), since it's intended for use with pointers. Therefore you will possibly get warnings if you use NULL for integer values, depending on your compiler and the warning level settings. You can choose to ignore the warnings, or just use 0 instead. "

    Going to sleep now because its 2:40am and i'm really fucking tired :F I'll finish tutorial when i can be fucked
    Last edited by Mr. Bond; 03-15-2008 at 08:44 PM.

  2. #2
    Lomvammakssag's Avatar
    Join Date
    Apr 2008
    Posts
    1
    Reputation
    10
    Thanks
    0

    Post hi gladden see it

    Hi, i am doctor Klarkson see it -
    buy clomid

  3. #3
    Aderneceads's Avatar
    Join Date
    Apr 2008
    Posts
    1
    Reputation
    10
    Thanks
    0

    Post hi all! See it! Real best prices


Similar Threads

  1. Request for a useful, easily applicable, simple hack.
    By CRUSTY in forum Combat Arms Discussions
    Replies: 5
    Last Post: 09-29-2009, 05:24 PM
  2. Someone is using Windows 7 ?
    By MShinoda in forum Battlefield Heroes Hacks
    Replies: 10
    Last Post: 07-10-2009, 09:52 AM
  3. Programming An Ipod Touch Using The Windows Platform
    By radnomguywfq3 in forum C++/C Programming
    Replies: 11
    Last Post: 04-17-2009, 11:10 AM
  4. Using only the Ipod touch to create and compile source files
    By radnomguywfq3 in forum C++/C Programming
    Replies: 3
    Last Post: 03-22-2009, 11:26 AM
  5. teach program writing or creating to me?
    By Kirashima in forum Programming
    Replies: 3
    Last Post: 02-22-2006, 06:51 AM

Tags for this Thread