Code:
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInstGlobal;
HWND hEdit;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) // nShowCmd???
{
hInstGlobal = hInstance;
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
WndClass.lpszMenuName = 0;
WndClass.lpszClassName = "WinProg";
RegisterClass(&WndClass);
HWND hWindow;
hWindow = CreateWindow("WinProg", "Edit Field",
WS_OVERLAPPED,
0,0,640,400,NULL,NULL,
hInstance, NULL);
ShowWindow (hWindow, nCmdShow);
UpdateWindow (hWindow);
MSG Message;
while (GetMessage(&Message, NULL, 0, 0))
{
DispatchMessage(&Message);
}
return (Message.wParam);
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)
{
switch(uiMessage)
{
case WM_CREATE:
HWND hButton, hButtonExit;
hButton = CreateWindow("BUTTON","SYSTEM_FONT",
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON, // BS_PUSHBUTTON returns BN_CLICKED
10,320,140,20,
hWnd, (HMENU) 1,
hInstGlobal, NULL);
hButtonExit = CreateWindow("BUTTON","EXIT",
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON,
160,320,140,20,
hWnd, (HMENU) 2,
hInstGlobal, NULL);
hEdit = CreateWindow("EDIT","SYSTEM_FONT",
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
10,340,120,20,
hWnd, (HMENU) 1,
hInstGlobal, NULL);
return 0;
case WM_COMMAND:
if(HIWORD(wParam) == BN_CLICKED) // BN = Button Notification. BS_PUSHBUTTON returns BN_CLICKED
{
if(LOWORD(wParam) == 1)
{
HDC hdc;
hdc = GetDC (GetParent((HWND) lParam));
HFONT hFont;
hFont = (HFONT) GetStockObject(SYSTEM_FONT);
char *string1;
string1 = new char[255];
SendMessage (hEdit, WM_GETTEXT, 256,(LPARAM) string1);
bool FontDa;
FontDa =0;
if (lstrcmp (string1,"SYSTEM_FONT") == 0)
{
hFont = (HFONT) GetStockObject(SYSTEM_FONT);
FontDa = 1;
}
if (lstrcmp (string1,"SYSTEM_FIXED_FONT") == 0)
{
hFont = (HFONT) GetStockObject(SYSTEM_FIXED_FONT);
FontDa = 1;
}
if (lstrcmp (string1,"OEM_FIXED_FONT") == 0)
{
hFont = (HFONT) GetStockObject(OEM_FIXED_FONT);
FontDa = 1;
}
if (lstrcmp (string1,"ANSI_VAR_FONT") == 0)
{
hFont = (HFONT) GetStockObject(ANSI_VAR_FONT);
FontDa = 1;
}
if (lstrcmp (string1,"ANSI_FIXED_FONT") == 0)
{
hFont = (HFONT) GetStockObject(ANSI_FIXED_FONT);
FontDa = 1;
}
if (lstrcmp (string1,"DEFAULT_GUI_FONT") == 0)
{
hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
FontDa = 1;
}
if (FontDa == 0)
{
hFont = (HFONT) GetStockObject(SYSTEM_FONT);
lstrcpy (string1, "SYSTEM_FONT");
}
SelectObject (hdc, hFont);
RECT rect;
SetRect (&rect, 0,0,480,280);
HBRUSH hBrush;
hBrush = CreateSolidBrush(RGB(255,255,255));
FillRect (hdc, &rect, hBrush);
TextOut (hdc, 340,10,string1, lstrlen(string1));
delete [] string1;
TEXTMETRIC tm;
GetTextMetrics (hdc, &tm);
int i;
int ix,iy;
ix = 0;
iy = 0;
char *string;
string = new char[2];
string[1] = 0;
for(i=0;i<=255;i++)
{
string[0] = i;
TextOut (hdc, ix, iy, string, lstrlen(string));
iy = iy + tm.tmHeight;
if ((iy/tm.tmHeight)==16)
{
iy = 0;
ix = ix + 20;
}
}
ReleaseDC (GetParent((HWND) lParam), hdc);
delete [] string1;
}
if (LOWORD(wParam) == 2)
{
SendMessage (GetParent((HWND) lParam), // hWnd is the handle of a window object to which the message is sent.
WM_DESTROY ,0 ,0); // Msg is the value which identifies the message.
} // wParam is the first parameter of the
message.
} // lParam is the second parameter of the
message.
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc (hWnd, uiMessage, wParam, lParam);
}
}
Compiling...