Thread: how to make a windows application

  1. #1
    Performer
    Join Date
    Jan 2007
    Location
    Macedonia
    Posts
    54

    Post how to make a windows application

    i want to learn how to make a windows application. I use a Bloodsheed compiler and there is an option to make a windows application.
    When i choose that option on my screen appears a code like this
    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 Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        /* Register the window class, and if it fails 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;
    }
    my question is this
    where to put my code to make it a windows application with buttons and all
    pls answer me soon

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    You should go to www.winprog.org, the tutorials there are amazing and take you from the very beginning and do not suppose any knowledge other than C/C++. Looking at your post, I'm not really sure if you are ready for this though.

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Windows programming is a little more involved than putting code in the right place. You really have to revise that template for what you want from the start, but the Forger's tutorial should be helpful.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Location
    Colchester, Essex, United Kingdom.
    Posts
    31
    That code looks pretty bloated if it's just a template. I use this when beginning to write a Windows application:
    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
      switch(msg){
        case WM_DESTROY:
          PostQuitMessage(0);
          return 0;
      }
    
      return DefWindowProc(hwnd,msg,wParam,lParam);
    }
    
    int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR args,int nShow){
      MSG msg;
      WNDCLASS wc={0};
      wc.lpszClassName="Win32App";
      wc.hInstance=hInst;
      wc.hbrBackground=GetSysColorBrush(COLOR_3DFACE);
      wc.lpfnWndProc=WndProc;
      wc.hCursor=LoadCursor(0,IDC_ARROW);
    
      RegisterClass(&wc);
    
      CreateWindow(wc.lpszClassName,"Win32App",WS_OVERLAPPEDWINDOW|
        WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,400,400,0,0,hInst,0);
    
      while(GetMessage(&msg,0,0,0)){
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
    
      return (int)msg.wParam;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows Application OnPaint() Function
    By userpingz in forum Windows Programming
    Replies: 3
    Last Post: 06-15-2009, 03:08 AM
  2. (Gnome) X Windows Application Issue
    By stickdeoderant in forum Linux Programming
    Replies: 0
    Last Post: 05-21-2007, 10:41 AM
  3. what language(s) was used to make windows xp?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-10-2007, 04:44 AM
  4. a question about the windows application tutorial
    By JustPlay4Fun in forum Windows Programming
    Replies: 4
    Last Post: 01-17-2005, 01:09 PM
  5. Application Termination Problem in Windows XP
    By wasabee in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2003, 12:53 PM