Code:
#include <windows.h>
#include "resource.h"
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK SplashWndProc (HWND, UINT, WPARAM, LPARAM);
HWND hMainWnd;
HWND hSplashWnd;
HWND hWndButton;
HBITMAP hSplashBMP;
HDC hSplashDC;
HDC hMemoryDC;
LONG BitmapWidth, BitmapHeight;
char szClassName[ ] = "WindowsApp";
char SplashClassName[] = "SplashWindowClass";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
MSG messages;
WNDCLASSEX wincl;
WNDCLASSEX splashwincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (hThisInstance, MAKEINTRESOURCE(IDI_ICON));
wincl.hIconSm = LoadIcon (hThisInstance, MAKEINTRESOURCE(IDI_ICON));
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
splashwincl.cbSize = sizeof(WNDCLASSEX);
splashwincl.style = 0;
splashwincl.lpfnWndProc = (WNDPROC)SplashWndProc;
splashwincl.cbClsExtra = 0;
splashwincl.cbWndExtra = 0;
splashwincl.hInstance = hThisInstance;
splashwincl.hIcon = NULL;
splashwincl.hIconSm = NULL;
splashwincl.hCursor = LoadCursor(NULL, IDC_ARROW);
splashwincl.hbrBackground = NULL;
splashwincl.lpszMenuName = NULL;
splashwincl.lpszClassName = SplashClassName;
if (!RegisterClassEx(&splashwincl))
{
MessageBox(NULL, "Failed To Register The Splash Window Class.", "Error", MB_OK | MB_ICONERROR);
return 0;
}
RECT DesktopRect;
GetWindowRect(GetDesktopWindow(), &DesktopRect);
int mainWinRows = 256;
int mainWinCols = 256;
hMainWnd = CreateWindowEx (
WS_EX_CLIENTEDGE, /* Extended possibilites for variation */
szClassName, /* Classname */
"Pinzas v2.0", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
1, /* Windows decides the position *///(DesktopRect.right - mainWinRows) / 2
1, /* where the window ends up on the screen *///(DesktopRect.bottom - mainWinCols) / 2
mainWinCols, /* The programs width */
mainWinRows, /* 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 */
);
if (!hMainWnd)
{
MessageBox(NULL, "Window Creation Failed.", "Error", MB_OK | MB_ICONERROR);
return 0;
}
hSplashBMP = LoadBitmap(hThisInstance, MAKEINTRESOURCE(BITMAP_ID));
if (!hSplashBMP)
{
MessageBox(NULL, "Failed To Load Bitmap", "Error", MB_OK | MB_ICONERROR);
return 0;
}
BITMAP Bitmap;
GetObject(hSplashBMP, sizeof(BITMAP), &Bitmap);
BitmapWidth = Bitmap.bmWidth;
BitmapHeight = Bitmap.bmHeight;
HWND hSplashWnd = CreateWindowEx(
0,
SplashClassName,
"Modulator",
WS_POPUP,
(DesktopRect.right - BitmapWidth) / 2,
(DesktopRect.bottom - BitmapHeight) / 2,
Bitmap.bmWidth,
Bitmap.bmHeight,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL);
if (!hSplashWnd)
{
MessageBox(NULL, "Splash Window Creation Failed.", "Error", MB_OK | MB_ICONERROR);
return 0;
}
hSplashDC = GetDC(hSplashWnd);
hMemoryDC = CreateCompatibleDC(hSplashDC);
SelectObject(hMemoryDC, (HGDIOBJ)hSplashBMP);
ShowWindow (hMainWnd, SW_SHOW);
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
// Free memory for the bitmap
DeleteObject(hSplashBMP);
ReleaseDC(hSplashWnd, hSplashDC);
ReleaseDC(hSplashWnd, hMemoryDC);
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
{
HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
hWndButton = CreateWindowEx(
0,
"BUTTON",
"Plot",
WS_VISIBLE | WS_CHILD,
10,
50,
80,
20,
hwnd,
(HMENU) IDB_BUTTON,
hInstance,
NULL);
}
break;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDB_BUTTON:
{
switch (HIWORD(wParam))
{
case BN_CLICKED:
//MessageBox(NULL, "Selected Button", "Success", MB_OK | MB_ICONINFORMATION);
// Load the splash to the screen
ShowWindow (hSplashWnd, SW_SHOWNORMAL);
break;
}
}
break;
case IDM_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case IDM_ITEM:
ShowWindow (hSplashWnd, SW_SHOWNORMAL);
break;
}
return 0;
}
break;
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;
}
LRESULT CALLBACK SplashWndProc( HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam )
{
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
BitBlt(hdc, 0, 0, BitmapWidth, BitmapHeight, hMemoryDC, 0, 0, SRCCOPY);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default:
return (DefWindowProc(hwnd, message, wParam, lParam));
}
return 0;
}