#include <windows.h>
LPSTR NazwaKlasy = "Klasa Okienka";
MSG Komunikat;
HWND g_hPrzycisk1, g_hPrzycisk2, g_hPrzycisk3, g_hPrzycisk4, g_hPrzycisk5, g_hPrzycisk6, g_hPrzycisk7, g_hPrzycisk8, g_hPrzycisk9, g_hPrzycisk10, g_hPrzycisk11, g_hPrzycisk12, g_hPrzycisk13, g_hPrzycisk14, g_hPrzycisk15, g_hPrzycisk16, hText;
char * szText;
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
WNDCLASSEX wc;
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 + 1 );
wc.lpszMenuName = NULL;
wc.lpszClassName = NazwaKlasy;
wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
if( !RegisterClassEx( & wc ) )
{
MessageBox( NULL, "Wysoka Komisja odmawia rejestracji tego okna!", "Niestety...", MB_ICONEXCLAMATION | MB_OK );
return 1;
}
HWND hwnd;
hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, NazwaKlasy, "Oto okienko", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, NULL, NULL, hInstance, NULL );
g_hPrzycisk1 = CreateWindowEx( 0, "BUTTON", "7", WS_CHILD | WS_VISIBLE, 100, 100, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk2 = CreateWindowEx( 0, "BUTTON", "4", WS_CHILD | WS_VISIBLE, 100, 140, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk3 = CreateWindowEx( 0, "BUTTON", "1", WS_CHILD | WS_VISIBLE, 100, 180, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk4 = CreateWindowEx( 0, "BUTTON", "8", WS_CHILD | WS_VISIBLE, 140, 100, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk5 = CreateWindowEx( 0, "BUTTON", "5", WS_CHILD | WS_VISIBLE, 140, 140, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk6 = CreateWindowEx( 0, "BUTTON", "2", WS_CHILD | WS_VISIBLE, 140, 180, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk7 = CreateWindowEx( 0, "BUTTON", "9", WS_CHILD | WS_VISIBLE, 180, 100, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk8 = CreateWindowEx( 0, "BUTTON", "6", WS_CHILD | WS_VISIBLE, 180, 140, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk9 = CreateWindowEx( 0, "BUTTON", "3", WS_CHILD | WS_VISIBLE, 180, 180, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk10 = CreateWindowEx( 0, "BUTTON", "+", WS_CHILD | WS_VISIBLE, 220, 60, 40, 120, hwnd, NULL, hInstance, NULL );
g_hPrzycisk11 = CreateWindowEx( 0, "BUTTON", "=", WS_CHILD | WS_VISIBLE, 220, 180, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk12 = CreateWindowEx( 0, "BUTTON", "/", WS_CHILD | WS_VISIBLE, 100, 60, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk13 = CreateWindowEx( 0, "BUTTON", "*", WS_CHILD | WS_VISIBLE, 140, 60, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk14 = CreateWindowEx( 0, "BUTTON", "-", WS_CHILD | WS_VISIBLE, 180, 60, 40, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk15 = CreateWindowEx( 0, "BUTTON", "0", WS_CHILD | WS_VISIBLE, 100, 220, 80, 40, hwnd, NULL, hInstance, NULL );
g_hPrzycisk16 = CreateWindowEx( 0, "BUTTON", "Del", WS_CHILD | WS_VISIBLE, 180, 220, 80, 40, hwnd, NULL, hInstance, NULL );
hText = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 100, 10, 160, 50, hwnd, NULL, hInstance, NULL );
SetWindowText( hText, "" );
if( hwnd == NULL )
{
MessageBox( NULL, "Okno odmówiło przyjścia na świat!", "Ale kicha...", MB_ICONEXCLAMATION );
return 1;
}
ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
while( GetMessage( & Komunikat, NULL, 0, 0 ) )
{
TranslateMessage( & Komunikat );
DispatchMessage( & Komunikat );
}
return Komunikat.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_COMMAND:
if(( HWND ) lParam == g_hPrzycisk1 )
{
int nTextLenght =( int ) SendMessage( hText, WM_GETTEXTLENGTH, 0, 0 );
SendMessage( hText, EM_SETSEL, nTextLenght, nTextLenght );
szText = "7";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk2 )
{
szText = "4";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk3 )
{
szText = "1";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk4 )
{
szText = "8";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk5 )
{
szText = "5";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk6 )
{
szText = "2";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk7 )
{
szText = "9";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk8 )
{
szText = "6";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk9 )
{
szText = "3";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk10 )
{
szText = "+";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk11 )
{
szText = "=";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk12 )
{
szText = "/";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk13 )
{
szText = "*";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk14 )
{
szText = "-";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk15 )
{
szText = "0";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
if(( HWND ) lParam == g_hPrzycisk16 )
{
szText = " ";
SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
}
break;
case WM_CLOSE:
DestroyWindow( hwnd );
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hwnd, msg, wParam, lParam );
}
return 0;
}
Zrobiłem taki kalkualtor wszytsko mi działa oprocz wykonywania działań np wcisne 2+2=.... i powinno mi pokazać 4 jak to zrobic? i jak zrobic kasowania jednego wciśnietego elemntu jesli ancisneimy Del??