Code:
#include <windows.h>
#include "resource.h"
int mb_result = 0; // For quit message.
const char g_szClassName[] = "WindowClass";
BOOL RemoveMenu(HMENU hMenu, UINT uPosition, UINT uFlags); // For system menu editing.
HBITMAP g_hbmBall = NULL;
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
HMENU hSysMenu; // System menu handle.
case WM_CREATE:
{
////////////////////////////////////////////////////////////////////
//////////////////////////// BMP Stuff /////////////////////////////
////////////////////////////////////////////////////////////////////
g_hbmBall = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BALL));
if( g_hbmBall == NULL )
{
MessageBox(hwnd, "Could not load bitmap!", "Error", MB_OK | MB_ICONEXCLAMATION);
}
////////////////////////////////////////////////////////////////////
hSysMenu = GetSystemMenu(hwnd, FALSE);
RemoveMenu(hSysMenu, 1, MF_BYPOSITION);
hSysMenu = GetSystemMenu(hwnd, FALSE);
RemoveMenu(hSysMenu, 2, MF_BYPOSITION);
hSysMenu = GetSystemMenu(hwnd, FALSE);
RemoveMenu(hSysMenu, 3, MF_BYPOSITION); // Get rid of system menu items.
hSysMenu = GetSystemMenu(hwnd, FALSE);
RemoveMenu(hSysMenu, 4, MF_BYPOSITION);
hSysMenu = GetSystemMenu(hwnd, FALSE);
RemoveMenu(hSysMenu, 5, MF_BYPOSITION);
hSysMenu = GetSystemMenu(hwnd, FALSE);
RemoveMenu(hSysMenu, 6, MF_BYPOSITION);
}
break;
case WM_PAINT:
{
BITMAP bm;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = ( HBITMAP ) SelectObject(hdcMem, g_hbmBall);
GetObject(g_hbmBall, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
}
break;
////////////////////////////// Menu Actions ////////////////////////////
case WM_COMMAND: // Menu was pressed:
switch(LOWORD(wParam)) //
{
case ID_FILE_EXIT: // ID_FILE_EXIT is pressed:
{
PostMessage(hwnd, WM_CLOSE, 0, 0); // Exit.
}
break;
case ID_EXECUTE_RUN:
{
MessageBox(NULL, "This is where you'd put your 'Run' code.", "Test", MB_OK);
}
break;
}
break;
////////////////////////////////////////////////////////////////////////
case WM_CLOSE:
mb_result = MessageBox ( NULL, " Do you wish to exit the program ? ", " Exit", MB_YESNO | MB_ICONEXCLAMATION );
if ( mb_result == IDYES )
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
DeleteObject(g_hbmBall);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
HMENU GetSystemMenu(HWND hWnd, BOOL bRevert); // Handle for system menu menu.
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 2 );
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", " Error!", MB_ICONERROR | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
0,
g_szClassName,
"Win32",
WS_BORDER | WS_CAPTION | WS_SYSMENU,
0, 0, 250, 250,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", " Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, SW_MAXIMIZE);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Here's resource.h :