1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
///Headers
#include <windows.h>
#include <mmsystem.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"
#define FILE_MENU_OPEN 1
#define FILE_MENU_EXIT 2
#define FILE_MENU_HELP 3
#define FILE_MENU_SAVE 4
#define FILE_MENU_ABOUT 5
/// --> Window Procedure callback function the placeholder,
/// for the application-defined function name.
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
void AddMenus(HWND);
void AddControls(HWND);
void registerDialogClass(HINSTANCE);
void displayDialog(HWND);
void registerACWClass(HINSTANCE);
void displayACW(HWND);
void loadImages();
HWND hMainWindow, hEdit, hStatic, aLogo, hLogo, hHelp;
HMENU hMenu;
HBITMAP aLogoImage, hLogoImage, hButtonImage;
///Creation of the Main Window
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE pRevInst, LPSTR args, int nCmdShow)
{
WNDCLASSW wc = {0};
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = hInst;
wc.lpszClassName = L"myWindowClass";
wc.lpfnWndProc = WindowProcedure;
if(!RegisterClassW(&wc))
return -1;
registerDialogClass(hInst);
registerACWClass(hInst);
hMainWindow = CreateWindowW(L"myWindowClass", L"Name it",
WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, // -> Window style
250, 90, 900, 600,
NULL, NULL, NULL, NULL);
MSG msg = {0};
// Main message loop:
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg); // -> returns when a WM_QUIT message appears
DispatchMessage(&msg); // -> calls the static WindowProcedure function
}
return 0;
}
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
int val;
switch(msg)
{
case WM_PAINT: // background image
{
//Project/build options/linker settings -> add libcomdlg32.a
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
HDC hdc_x = CreateCompatibleDC(NULL);
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "wallpaper.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
SelectObject(hdc_x, hBitmap);
RECT rect;
GetWindowRect(hWnd, &rect);
BitBlt(hdc, 0, 0, rect.right - rect.left, 600, hdc_x, 0, 0, SRCCOPY);
EndPaint(hWnd, &ps);
break;
}
case WM_COMMAND:
{
switch(wp)
{
case FILE_MENU_OPEN:
open_file(hWnd);
break;
case FILE_MENU_SAVE:
save_file(hWnd);
break;
case FILE_MENU_EXIT:
val = MessageBoxW(hWnd, L"Are you sure you want to exit the application ?",
L"Warning !", MB_YESNO | MB_ICONEXCLAMATION);
if(val == IDYES)
{
DestroyWindow(hWnd);
}
break;
case FILE_MENU_HELP:
displayDialog(hWnd);
PlaySound(TEXT("nvg_off.wav"), NULL, SND_SYNC);
break;
case FILE_MENU_ABOUT:
PlaySound(TEXT("nvg_off.wav"), NULL, SND_SYNC);
displayACW(hWnd);
break;
}
}
case WM_CREATE:
loadImages();
AddMenus(hWnd);
AddControls(hWnd);
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hWnd, msg, wp, lp);
}
return 0;
}
|