Code:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <commdlg.h>
#define ID_EDIT 100
BOOL siachcolor(HWND hwnd); // header for choosecolor common dlg
BOOL ChooseFont(HWND hwnd); //choose font
void releasef(void);
void Initialize(HWND hwnd);
HFONT SetFont(HWND hwnd);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static char szAppName[] = TEXT ("Hello Lovely Sara, Experimental all in one Programm") ;
HWND hwnd ;
MSG msg ;
WNDCLASSEX wndclass ;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wndclass);
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The, Hello Lovely Sara, Experimental all in one programm"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HBRUSH hbrush;
PAINTSTRUCT ps ;
HDC hdc;
static int cxchar, cychar, cxcaps, cxclient, cyclient, i = 0,j = 0, y = 0, x = 0,x1 = 0, cxbuffer, cybuffer;
TEXTMETRIC tm;
HMENU hmenu;
static HWND hwndedit;
HINSTANCE hInstance;
HFONT hfont;
static char *ptextbuff = NULL;
static char ptext[300];
static char achar;
switch (message)
{
case WM_CREATE:
hwndedit = CreateWindow (TEXT ("edit Box Sara Writes Here"), NULL,
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
WS_BORDER | ES_LEFT | ES_MULTILINE |
ES_AUTOHSCROLL | ES_AUTOVSCROLL,
0, 0, 0, 0, hwnd, (HMENU) ID_EDIT,
((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
hInstance = ((LPCREATESTRUCT )lParam)->hInstance;
hmenu = LoadMenu(hInstance, TEXT ("sia0016"));
SetMenu(hwnd, hmenu);
Initialize(hwnd);
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
cxchar = tm.tmAveCharWidth;
cychar = tm.tmHeight + tm.tmExternalLeading;
cxcaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxchar / 2;
ptextbuff = (char *)malloc(200 * sizeof(char));
ReleaseDC(hwnd, hdc);
return 0;
case WM_SIZE:
cxclient = LOWORD (lParam) ;
cyclient = HIWORD (lParam) ;
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_SETFOCUS:
SetFocus(hwndedit);
return 0;
case WM_KILLFOCUS:
SetFocus(hwndedit);
return 0;
case WM_COMMAND:
// if (LOWORD (wParam) == ID_EDIT)
//if (HIWORD (wParam) == EN_ERRSPACE ||
// HIWORD (wParam) == EN_MAXTEXT) // code about edit box
//MessageBox (hwnd, TEXT ("Edit control out of space."),
//"memory shortage", MB_OK | MB_ICONSTOP) ;*/
switch(LOWORD (wParam))
{
case 31:
hbrush = CreateSolidBrush(siachcolor(hwnd));
SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)hbrush); // code about choosecolor
InvalidateRect(hwnd, NULL, TRUE);
return 0;
case 41:
hdc = GetDC(hwnd);
if(ChooseFont(hwnd))
SelectObject(hdc, tSetFont(hwnd)); //code about choosefont
ReleaseDC(hwnd, hdc);
return 0;
case 51: //menue id
MoveWindow(hwndedit, 0, 0, 200, 500, FALSE);
SetFocus(hwndedit);
return 0;
}
break;
case WM_CHAR:
hdc = GetDC(hwnd);
*(pbuffer + x) = (char) wParam;
*(pbuffer + x + 1) = '\0';
TextOut(hdc, i * cxchar, j * cychar , pbuffer + x, 1);
i++;
x++;
if((char) wParam == '\r'){
j++;
i = 0;
}
ReleaseDC(hwnd, hdc);
return 0;
case WM_DESTROY:
hdc = GetDC(hwnd);
DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
ReleaseDC(hwnd, hdc);
// DeleteObject(hfont);
if(ptextbuff)
free(ptextbuffer);
DeleteObject(hbrush);
releasef();
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}