Code:
#include <windows.h>
LRESULT CALLBACK WinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hiInst, HINSTANCE hPrevInst, LPSTR lpszArgs, int nWinMode)
{
WNDCLASS wcClass;
HWND Handle;
MSG msgMessage;
char pcClassName[] = "MDLN-GUI";
wcClass.hInstance = hiInst;
wcClass.lpszClassName = pcClassName;
wcClass.lpfnWndProc = WinProc;
wcClass.style = CS_DBLCLKS;
wcClass.hIcon = LoadIcon(0, "MW_ICON");
wcClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wcClass.lpszMenuName = NULL;
wcClass.cbClsExtra = 0;
wcClass.cbWndExtra = 0;
wcClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
if (RegisterClass(&wcClass) == 0)
{
return;
}
Handle = CreateWindow("MDLN-GUI", "", WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, NULL, NULL, hiInst, NULL);
UpdateWindow(Handle);
ShowWindow(Handle, SW_SHOW);
while(GetMessage(&msgMessage, NULL, 0, 0) != 0)
{
TranslateMessage(&msgMessage);
DispatchMessage(&msgMessage);
}
return 0;
}
LRESULT CALLBACK WinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
//case (WM_MOVE) :
case (WM_SIZE) :
{
InvalidateRect(hwnd, NULL, FALSE);
break;
}
case (WM_PAINT) :
{
PAINTSTRUCT sPaint;
RECT sRect;
LOGBRUSH sBrush;
HBRUSH hBrush;
BeginPaint(hwnd, &sPaint);
GetClientRect(hwnd, &sRect);
sBrush.lbStyle = BS_SOLID;
sBrush.lbColor = RGB(0, 255, 0);
sBrush.lbHatch = 0;
sRect.top += 25;
sRect.left += 25;
sRect.bottom -= 25;
sRect.right -= 25;
hBrush = CreateBrushIndirect(&sBrush);
FillRect(sPaint.hdc, &sRect, hBrush);
DeleteObject(hBrush);
sBrush.lbStyle = BS_SOLID;
sBrush.lbColor = RGB(0, 0, 255);
sBrush.lbHatch = 0;
sRect.top += 25;
sRect.left += 25;
sRect.bottom -= 25;
sRect.right -= 25;
hBrush = CreateBrushIndirect(&sBrush);
FillRect(sPaint.hdc, &sRect, hBrush);
DeleteObject(hBrush);
EndPaint(hwnd, &sPaint);
return 0;
}
case (WM_DESTROY) :
{
PostQuitMessage(0);
break;
}
default :
{
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
return 0;
}