~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/templates/win32/win32-main.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <windows.h>
 
2
 
 
3
/*  Declare Windows procedure  */
 
4
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
 
5
 
 
6
/*  Make the class name into a global variable  */
 
7
char szClassName[ ] = "CodeBlocksWindowsApp";
 
8
 
 
9
int WINAPI WinMain (HINSTANCE hThisInstance,
 
10
                     HINSTANCE hPrevInstance,
 
11
                     LPSTR lpszArgument,
 
12
                     int nCmdShow)
 
13
{
 
14
    HWND hwnd;               /* This is the handle for our window */
 
15
    MSG messages;            /* Here messages to the application are saved */
 
16
    WNDCLASSEX wincl;        /* Data structure for the windowclass */
 
17
 
 
18
    /* The Window structure */
 
19
    wincl.hInstance = hThisInstance;
 
20
    wincl.lpszClassName = szClassName;
 
21
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
 
22
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
 
23
    wincl.cbSize = sizeof (WNDCLASSEX);
 
24
 
 
25
    /* Use default icon and mouse-pointer */
 
26
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
 
27
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
 
28
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
 
29
    wincl.lpszMenuName = NULL;                 /* No menu */
 
30
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
 
31
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
 
32
    /* Use Windows's default colour as the background of the window */
 
33
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
 
34
 
 
35
    /* Register the window class, and if it fails quit the program */
 
36
    if (!RegisterClassEx (&wincl))
 
37
        return 0;
 
38
 
 
39
    /* The class is registered, let's create the program*/
 
40
    hwnd = CreateWindowEx (
 
41
           0,                   /* Extended possibilites for variation */
 
42
           szClassName,         /* Classname */
 
43
           "Code::Blocks Template Windows App",       /* Title Text */
 
44
           WS_OVERLAPPEDWINDOW, /* default window */
 
45
           CW_USEDEFAULT,       /* Windows decides the position */
 
46
           CW_USEDEFAULT,       /* where the window ends up on the screen */
 
47
           544,                 /* The programs width */
 
48
           375,                 /* and height in pixels */
 
49
           HWND_DESKTOP,        /* The window is a child-window to desktop */
 
50
           NULL,                /* No menu */
 
51
           hThisInstance,       /* Program Instance handler */
 
52
           NULL                 /* No Window Creation data */
 
53
           );
 
54
 
 
55
    /* Make the window visible on the screen */
 
56
    ShowWindow (hwnd, nCmdShow);
 
57
 
 
58
    /* Run the message loop. It will run until GetMessage() returns 0 */
 
59
    while (GetMessage (&messages, NULL, 0, 0))
 
60
    {
 
61
        /* Translate virtual-key messages into character messages */
 
62
        TranslateMessage(&messages);
 
63
        /* Send message to WindowProcedure */
 
64
        DispatchMessage(&messages);
 
65
    }
 
66
 
 
67
    /* The program return-value is 0 - The value that PostQuitMessage() gave */
 
68
    return messages.wParam;
 
69
}
 
70
 
 
71
 
 
72
/*  This function is called by the Windows function DispatchMessage()  */
 
73
 
 
74
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
75
{
 
76
    switch (message)                  /* handle the messages */
 
77
    {
 
78
        case WM_DESTROY:
 
79
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
 
80
            break;
 
81
        default:                      /* for messages that we don't deal with */
 
82
            return DefWindowProc (hwnd, message, wParam, lParam);
 
83
    }
 
84
 
 
85
    return 0;
 
86
}