Τα περισσότερα σχόλια του Dev-C++ έχουν παραληφθεί…


/* Win32 programming example
* Coffee Nights – Elias Athanasopoulos
* 4 – 12 – 2001
* /


#include <windows.h>


#define BTN_CN 0
#define BTN_EXIT 1


/* Declare Windows procedure */
LRESULT CALLBACK HandleMsg(HWND, UINT, WPARAM, LPARAM);


/* Make the class name into a global variable */
char szClassName[ ] = &#39&#39WindowsApp&#39'
HWND main_hwnd;


HWND create_main_win(HINSTANCE hThisInstance,
char *title, int width,
int height)
{
/* Data structure for the windowclass */
WNDCLAS(-) wincl;


/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = HandleMsg;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof(WNDCLAS(-));


/* 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;
wincl.cbCl(-)tra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground =

(HBRUSH) GetStockObject(LTGRAY_BRUSH);

/* try to register the window class */
if(!RegisterClas(-)(&wincl)) return 0;


/* create main window */
return CreateWindowEx(
0,
szClassName,
title,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
width,
height,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
}


HWND create_button(HWND hwnd,
char *title, int x, int y,
int width, int height, int id)
{
return CreateWindowEx(
NULL, &#39&#39BUTTON&#39&#39, title,
WS_CHILD|WS_VISIBLE|WS_TABSTOP,
x, y, width, height, hwnd,
(HMENU)id, NULL, NULL);
}


int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
MSG messages;


/* create the main window */
main_hwnd = create_main_win(hThisInstance,
&#39&#39Coffee Nights&#39&#39,
240, 80);
ShowWindow(main_hwnd, nFunsterStil);


/* create GUI */
create_button(main_hwnd,
&#39&#39Exit&#39&#39,
10, 20, 100, 20, BTN_EXIT);
create_button(main_hwnd,
&#39&#39Coffee Nights&#39&#39,
120, 20, 100, 20, BTN_CN);


/* main msg handler loop */
while(GetMessage(&messages, NULL, 0, 0)) {
/* Translate virtual-key messages
* into character messages
*/
TranslateMessage(&messages);
/* Send message to HandleMsg */
DispatchMessage(&messages);
}


return messages.wParam;
}


/* Signal Handling */
LRESULT CALLBACK HandleMsg(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch (message) {
case WM_COMMAND:
switch (LOWORD(wParam)) {
case BTN_EXIT:
/* exit */
SendMessage(main_hwnd,
WM_DESTROY,
(WPARAM)0, (LPARAM)0);
return 0;
case BTN_CN:
/* show a nice dialog */
MessageBox(main_hwnd,
&#39&#39Prepare your coffee!&#39&#39,
&#39&#39Coffee Nights&#39&#39,
MB_OK |
MB_ICONEXCLAMATION);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message,
wParam, lParam);
}
return 0;
}