Adding colour & bmps to a Win 32 Window??

This is a discussion on Adding colour & bmps to a Win 32 Window?? within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I am a real newbie with C, and am making a game with my friends as part of a ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    3

    Question Adding colour & bmps to a Win 32 Window??

    Hi. I am a real newbie with C, and am making a game with my friends as part of a school project. We though it would be a good idea if we made a character guide that gives a description of all of the characters, and a brief run-down of the game. I found a demo window program on DEV C++ (works with C as well) and here is the code:

    Code:
    /*
     * A basic example of Win32 programmiwng in C.
     *
     * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
     *
     * Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
     */
    
    #include <windows.h>
    #include <string.h>
    #include <iostream>
    
    /*
     * This is the window function for the main window. Whenever a message is
     * dispatched using DispatchMessage (or sent with SendMessage) this function
     * gets called with the contents of the message.
     */
    LRESULT CALLBACK
    MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
    {
    /* The window handle for the "Click Me" button. */
    static HWND hwndButton = 0;
    static int cx, cy;/* Height and width of our button. */
    
    HDC hdc;/* A device context used for drawing */
    PAINTSTRUCT ps;/* Also used during window drawing */
    RECT rc;/* A rectangle used during drawing */
    /*
     * Perform processing based on what kind of message we got.
     */
    switch (nMsg)
    {
    case WM_CREATE:
    {
    /* The window is being created. Create our button
     * window now. */
    TEXTMETRIC tm;
    
    /* First we use the system fixed font size to choose
     * a nice button size. */
    hdc = GetDC (hwnd);
    SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
    GetTextMetrics (hdc, &tm);
    cx = tm.tmAveCharWidth * 30;
    cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
    ReleaseDC (hwnd, hdc);
    
    /* Now create the button */
    hwndButton = CreateWindow (
    "button",/* Builtin button class */
    "Close",
    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
    0, 0, cx, cy,
    hwnd,/* Parent is this window. */
    (HMENU) 1,/* Control ID: 1 */
    ((LPCREATESTRUCT) lParam)->hInstance,
    NULL
    );
    
    return 0;
    break;
    }
    
    case WM_DESTROY:
    /* The window is being destroyed, close the application
     * (the child button gets destroyed automatically). */
    PostQuitMessage (0);
    return 0;
    break;
    
    case WM_PAINT:
    /* The window needs to be painted (redrawn). */
    hdc = BeginPaint (hwnd, &ps);
    GetClientRect (hwnd, &rc);
    
    /* Draw "Hello, World" in the middle of the upper
     * half of the window. */
    rc.bottom = rc.bottom / 2;
    DrawText (hdc, "Little Fighter Elite Character Guide- By Carey Sizer", -1, &rc,
    DT_SINGLELINE | DT_CENTER | DT_VCENTER);
    
    EndPaint (hwnd, &ps);
    return 0;
    break;
    
    case WM_SIZE:
    /* The window size is changing. If the button exists
     * then place it in the center of the bottom half of
     * the window. */
    if (hwndButton &&
    (wParam == SIZEFULLSCREEN ||
     wParam == SIZENORMAL)
       )
    {
    rc.left = (LOWORD(lParam) - cx) / 2;
    rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;
    MoveWindow (
    hwndButton,
    rc.left, rc.top, cx, cy, TRUE);
    }
    break;
    
    case WM_COMMAND:
    /* Check the control ID, notification code and
     * control handle to see if this is a button click
     * message from our child button. */
    if (LOWORD(wParam) == 1 &&
        HIWORD(wParam) == BN_CLICKED &&
        (HWND) lParam == hwndButton)
    {
    /* Our button was clicked. Close the window. */
    DestroyWindow (hwnd);
    }
    return 0;
    break;
    }
    
    /* If we don't handle a message completely we hand it to the system
     * provided default window function. */
    return DefWindowProc (hwnd, nMsg, wParam, lParam);
    }
    
    
    int STDCALL
    WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
    {
    HWND hwndMain;/* Handle for the main window. */
    MSG msg;/* A Win32 message structure. */
    WNDCLASSEX wndclass;/* A window class structure. */
    char*szMainWndClass = "WinTestWin";
    /* The name of the main window class */
    
    /*
     * First we create a window class for our main window.
     */
    
    /* Initialize the entire structure to zero. */
    memset (&wndclass, 0, sizeof(WNDCLASSEX));
    
    /* This class is called WinTestWin */
    wndclass.lpszClassName = szMainWndClass;
    
    /* cbSize gives the size of the structure for extensibility. */
    wndclass.cbSize = sizeof(WNDCLASSEX);
    
    /* All windows of this class redraw when resized. */
    wndclass.style = CS_HREDRAW | CS_VREDRAW;
    
    /* All windows of this class use the MainWndProc window function. */
    wndclass.lpfnWndProc = MainWndProc;
    
    /* This class is used with the current program instance. */
    wndclass.hInstance = hInst;
    
    /* Use standard application icon and arrow cursor provided by the OS */
    wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
    
    /* Color the background white */
    wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
    
    /*
     * Now register the window class for use.
     */
    RegisterClassEx (&wndclass);
    
    /*
     * Create our main window using that window class.
     */
    hwndMain = CreateWindow (
    szMainWndClass,/* Class name */
    "Hello",/* Caption */
    WS_OVERLAPPEDWINDOW,/* Style */
    CW_USEDEFAULT,/* Initial x (use default) */
    CW_USEDEFAULT,/* Initial y (use default) */
    CW_USEDEFAULT,/* Initial x size (use default) */
    CW_USEDEFAULT,/* Initial y size (use default) */
    NULL,/* No parent window */
    NULL,/* No menu */
    hInst,/* This program instance */
    NULL/* Creation parameters */
    );
    
    /*
     * Display the window which we just created (using the nShow
     * passed by the OS, which allows for start minimized and that
     * sort of thing).
     */
    ShowWindow (hwndMain, nShow);
    UpdateWindow (hwndMain);
    
    /*
     * The main message loop. All messages being sent to the windows
     * of the application (or at least the primary thread) are retrieved
     * by the GetMessage call, then translated (mainly for keyboard
     * messages) and dispatched to the appropriate window procedure.
     * This is the simplest kind of message loop. More complex loops
     * are required for idle processing or handling modeless dialog
     * boxes. When one of the windows calls PostQuitMessage GetMessage
     * will return zero and the wParam of the message will be filled
     * with the argument to PostQuitMessage. The loop will end and
     * the application will close.
             */
    while (GetMessage (&msg, NULL, 0, 0))
    {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
    }
    return msg.wParam;
    }


    What I want to do is: Add about 15 buttons in the main window that have the characters names on them, and when you click them it opens a mini window- like 150px by 250. These also need a little bmp of the character in them, and a bold title with a blurb about them. It would be handy if they had a scroll bar as well.

    We want the colour scheme to a dark blue, and all of the text white. (the buttons as well). I also need to insert a bitmap as a title in the main window.

    If you can help me out with doing this, we will put your name + website (or whatever u want- email?) in the credits for the game, and you can add your name in the bottom of the character guide.

    Any help is much appreciated!
    Last edited by Salem; 09-04-2004 at 12:50 AM. Reason: code tagging

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    welcome to the boards!

    1) read the FAQ before posting anything else.
    2) always use code tags.
    3) only post code that is relevant to the specific question.
    4) make sure you are posting questions to the correct forum.

    >> What I want to do is:

    figure it out for yourself and post questions here when you get stuck. that's how it works here.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Your task sounds like an ideal candidate to implement as a web page rather than a windows program.

    Web page advantages:
    • Much easier to implement.
    • Will look better (unless you are an exceptionally good GDI programmer or an exceptionally bad web programmer).
    • Much easier to change look or details.
    • Can be made available on the web as a teaser for potential users.
    • Works on all platforms - less work if you decide to port your game to other platforms.
    • User or potential user is much more likely to browse a web page than take the risky step of executing a program.
    • Likely that you or someone else on your project already have the skills to create a web page.
    • More likely that a low vision or disAbled user can access the content.
    Last edited by anonytmouse; 09-04-2004 at 12:53 PM.

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Yeah, the only way I would advise creating an actual program is if they were 3d characters, and you wnted to be able to view them and or edit them.

    And you can put a web page online and you could look at it from any computer (with internet).

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    3

    So, how is that done?

    I know html quite well, and other web languages also. So that might be an option, but when we put our game onto a disk (it's nor commercial or anything) but we just wanna give it out to friends and stuff, so would we be able to include an exe file, that has pre-set characters, and descriptions (in a html files, which are shown in the program) and then there is an option to update from the web as we make more characters, which just downloads a new html file- a bit like norton. Is this possible with C?

    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  2. internet
    By yeah in forum C Programming
    Replies: 16
    Last Post: 02-12-2005, 10:37 PM
  3. Problem with creating new window, from another window
    By Garfield in forum Windows Programming
    Replies: 6
    Last Post: 01-11-2004, 02:10 PM
  4. OpenGL with WIN 32
    By Gravedigga in forum Windows Programming
    Replies: 3
    Last Post: 11-01-2003, 02:54 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 05:10 AM

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