EDN Admin
Well-known member
#include <windows.h>
#include <iostream>
int x=160;
int y=155;
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow );
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR szCmdLine,
int iCmdShow )
{
#pragma region part 1 - STARTUP STUFF
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject( OEM_FIXED_FONT );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = TEXT("ballmoving");
wc.lpszMenuName = 0;
wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass( &wc );
HWND hwnd = CreateWindow(TEXT("ballmoving"), TEXT("windows title!"), WS_OVERLAPPEDWINDOW, 10, 10, 600, 600, NULL, NULL, hInstance, NULL );
ShowWindow(hwnd, iCmdShow );
<span style="white-spacere UpdateWindow(hwnd);
#pragma endregion
#pragma region part 2 - ENTER A LOOP TO CONTINUALLY KEEP CHECKING WITH WIN O/S FOR USER INTERACTION
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
#pragma endregion
return msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
switch( message )
{
case WM_CREATE:
Beep( 50, 10 );
return 0;
break;
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
<span style="white-spacere HBRUSH NewBrush;
hdc = BeginPaint( hwnd, &ps );
<span style="white-spacere
<span style="white-spacere NewBrush = CreateSolidBrush(RGB(250, 25, 5));
<span style="white-spacere case WM_KEYDOWN:
<span style="white-spacere
<span style="white-spacere switch(wparam)
<span style="white-spacere {
<span style="white-spacere case VK_UP:
<span style="white-spacere y--;
<span style="white-spacere break;
<span style="white-spacere case VK_DOWN:
<span style="white-spacere y++;
<span style="white-spacere break;
<span style="white-spacere case VK_LEFT:
<span style="white-spacere x--;
<span style="white-spacere break;
<span style="white-spacere case VK_RIGHT:
<span style="white-spacere x++;
<span style="white-spacere break;
<span style="white-spacere }
SelectObject(hdc, NewBrush);
Ellipse( hdc, x, y, x+30, y+30 );
}
return 0;
break;
case WM_DESTROY:
PostQuitMessage( 0 ) ;
return 0;
break;
<span style="white-spacere
}
return DefWindowProc( hwnd, message, wparam, lparam );
}
<hr class="sig Navi
View the full article
#include <iostream>
int x=160;
int y=155;
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow );
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR szCmdLine,
int iCmdShow )
{
#pragma region part 1 - STARTUP STUFF
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject( OEM_FIXED_FONT );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = TEXT("ballmoving");
wc.lpszMenuName = 0;
wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass( &wc );
HWND hwnd = CreateWindow(TEXT("ballmoving"), TEXT("windows title!"), WS_OVERLAPPEDWINDOW, 10, 10, 600, 600, NULL, NULL, hInstance, NULL );
ShowWindow(hwnd, iCmdShow );
<span style="white-spacere UpdateWindow(hwnd);
#pragma endregion
#pragma region part 2 - ENTER A LOOP TO CONTINUALLY KEEP CHECKING WITH WIN O/S FOR USER INTERACTION
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
#pragma endregion
return msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
switch( message )
{
case WM_CREATE:
Beep( 50, 10 );
return 0;
break;
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
<span style="white-spacere HBRUSH NewBrush;
hdc = BeginPaint( hwnd, &ps );
<span style="white-spacere
<span style="white-spacere NewBrush = CreateSolidBrush(RGB(250, 25, 5));
<span style="white-spacere case WM_KEYDOWN:
<span style="white-spacere
<span style="white-spacere switch(wparam)
<span style="white-spacere {
<span style="white-spacere case VK_UP:
<span style="white-spacere y--;
<span style="white-spacere break;
<span style="white-spacere case VK_DOWN:
<span style="white-spacere y++;
<span style="white-spacere break;
<span style="white-spacere case VK_LEFT:
<span style="white-spacere x--;
<span style="white-spacere break;
<span style="white-spacere case VK_RIGHT:
<span style="white-spacere x++;
<span style="white-spacere break;
<span style="white-spacere }
SelectObject(hdc, NewBrush);
Ellipse( hdc, x, y, x+30, y+30 );
}
return 0;
break;
case WM_DESTROY:
PostQuitMessage( 0 ) ;
return 0;
break;
<span style="white-spacere
}
return DefWindowProc( hwnd, message, wparam, lparam );
}
<hr class="sig Navi
View the full article