App

This is a discussion on App within the Windows Programming forums, part of the Platform Specific Boards category; Could someone edit this code so there is a button in it that says something on it? I don't have ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    13

    App

    Could someone edit this code so there is a button in it that says something on it? I don't have graphics.h and couldn't find how to make one without it. Thnx.


    Code:
    #include <windows.h>
    
    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
    /* Make the class name into a global variable */
    char szClassName[ ] = "WindowsApp";
    int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof(WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL; /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use light-gray as the background of the window */
        wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
    
        /* Register the window class, if fail quit the program */
        if(!RegisterClassEx(&wincl)) return 0;
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx(
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",         /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow(hwnd, nFunsterStil);
        /* Run the message loop. It will run until GetMessage( ) returns 0 */
        while(GetMessage(&messages, NULL, 0, 0))
        {
               /* Translate virtual-key messages into character messages */
               TranslateMessage(&messages);
               /* Send message to WindowProcedure */
               DispatchMessage(&messages);
        }
    
        /* The program return-value is 0 - The value that PostQuitMessage( ) gave */
        return messages.wParam;
    }
    
    /* This function is called by the Windows function DispatchMessage( ) */
    LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
               case WM_DESTROY:
               PostQuitMessage(0);        /* send a WM_QUIT to the message queue */
               break;
               default:                   /* for messages that we don't deal with */
               return DefWindowProc(hwnd, message, wParam, lParam);
        }
        return 0;
    }

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb CreateWindow function ...

    In your window proc. function (WindowProcedure(...)) you need to call "CreateWindow(...)". In the "switch(message)" statement, add this code:

    First, create 2 globals (ex. under the "char szClassName[...] ..." line). Make them like this:

    Code:
    /*Make sure you remove "HWND hwnd;" from "WinMain" function first*/
    HWND hwnd;        // Main window
    HWND hButton;    // Handle for button
    Code:
    case WM_CREATE:
        hButton = CreateWindow("BUTTON", "MyText",
                                                  WS_CHILD | WS_VISIBLE,
                                                  100,      // 'X' position
                                                  100,      // 'Y' position
                                                  120,      // Width
                                                  20,        // Height
                                                  hwnd,   // Parent window handle
                                                  NULL,    // No menu
                                                  NULL,    // Don't need it I don't think
                                                  NULL);   // Don't need this
    break;
    That's all you need to do. I hope this helps.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    13
    thanks a lot, I've been searching but I couldn't find anything but files that use graphics lib.

  4. #4
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293
    Have you tried a beginner's tutorial? That would be the most logical place to start.

    As I see you are using a dev-cpp template I'll assume you are using the dev-cpp ide, so I recommend www.winprog.org which is a very dev-cpp friendly site as most of the code is just api based, however some of the things like with resources and setting up projects are msvc++ only.

    I don't know of any dev-cpp only tutorials yet, until mine are finished ... if ever.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 08:11 AM
  2. best program to start
    By gooddevil in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2004, 06:56 PM
  3. Need help migrating console app to windows app
    By DelphiGuy in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2004, 07:05 PM
  4. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 11:28 AM
  5. How do I make my Linux app standalone?
    By Joda in forum C++ Programming
    Replies: 2
    Last Post: 11-27-2002, 04:53 AM

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