home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
wint1_92
/
petzold
/
drawing.c
next >
Wrap
C/C++ Source or Header
|
1991-11-06
|
2KB
|
82 lines
/*----------------------------------------
DRAWING.C -- Drawing on the Dialog Box
(c) Charles Petzold, 1991
----------------------------------------*/
#include <windows.h>
#include <string.h>
#include "drawing.h"
BOOL FAR PASCAL DlgProc (HWND, WORD, WORD, LONG) ;
char szAppName [] = "Drawing" ;
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
DialogBox (hInstance, szAppName, NULL,
MakeProcInstance (DlgProc, hInstance)) ;
return 0 ;
}
BOOL FAR PASCAL DlgProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
{
static char szBuffer [32] ;
static int cxFont, cyFont ;
static RECT rect ;
DWORD dwDlgBaseUnits ;
HDC hdc ;
HWND hwndRect ;
PAINTSTRUCT ps ;
switch (message)
{
case WM_INITDIALOG:
dwDlgBaseUnits = GetDialogBaseUnits () ;
cxFont = LOWORD (dwDlgBaseUnits) ;
cyFont = HIWORD (dwDlgBaseUnits) ;
wsprintf (szBuffer, "Base Units: %d x %d", cxFont, cyFont) ;
SetDlgItemText (hwnd, ID_TEXT, szBuffer) ;
hwndRect = GetDlgItem (hwnd, ID_RECT) ;
GetWindowRect (hwndRect, &rect) ;
ScreenToClient (hwnd, (LPPOINT) &rect.left) ;
ScreenToClient (hwnd, (LPPOINT) &rect.right) ;
SetWindowLong (hwndRect, GWL_STYLE, ~WS_VISIBLE &
GetWindowLong (hwndRect, GWL_STYLE)) ;
return TRUE ;
case WM_ERASEBKGND:
if (IsIconic (hwnd))
return TRUE ;
break ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
if (IsIconic (hwnd))
{
DrawIcon (hdc, 0, 0, LoadIcon (NULL, IDI_APPLICATION)) ;
}
else
{
TextOut (hdc, 2 * cxFont, cyFont, szBuffer,
strlen (szBuffer)) ;
DrawText (hdc, szBuffer, -1, &rect, DT_CENTER) ;
}
EndPaint (hwnd, &ps) ;
return TRUE ;
case WM_CLOSE:
EndDialog (hwnd, 0) ;
return TRUE ;
}
return FALSE ;
}