home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Direkt 1995 #6
/
CDD_6_95.ISO
/
cdd
/
winanw
/
bardemo
/
bardemo.c
next >
Wrap
C/C++ Source or Header
|
1995-01-18
|
29KB
|
1,029 lines
// bardemo.c
#include "windows.h"
#include "commdlg.h"
#include "stdlib.h"
#include "string.h"
#include "resource.h"
#include "easybar.h"
typedef struct tagLONGSTRING
{
long id;
char *szName;
} LONGSTRING;
LONGSTRING g_styles[] =
{
BDF_LEFT,"Left"
,BDF_RIGHT, "Right"
,BDF_TOP, "Top"
,BDF_BOTTOM, "Bottom"
,BDF_CENTER, "Center"
,BDF_VCENTER, "VCenter"
,BDF_HIDEMAINTEXT, "HideMainText"
,BDF_HIDEADDONTEXT, "HideAddOnText"
,BDF_ADDONTEXTATTOP, "AddOnTextAtTop"
,BDF_ADDONTEXTATBOTTOM, "AddOnTextAtBottom"
,BDF_MAINTEXTATTOP, "MainTextAtTop"
,BDF_MAINTEXTATBOTTOM, "MainTextAtBottom"
,BDF_NOUPCSMALLFONT, "NoUpcSmallFont"
,BDF_NOSTRETCHTEXT, "NoStretchText"
,BDF_UNIBARHEIGHT, "UniBarHeight"
,BDF_RETAINASPECTRATIO, "RetainAspectRatio"
,BDF_NOPIXELALIGN, "NoPixelAlign"
,BDF_CALCSIZEONLY, "CalcSizeOnly"
};
HBARCODE g_hbar = 0;
RECT g_rcCanvas;
RECT g_rc;
int g_iOrient = 0;
DWORD g_style = 0;
int g_iType = 0;
LOGFONT g_logfont;
char g_tmp[100];
COLORREF g_clfFg;
COLORREF g_clfBg;
int g_iBkMode;
HGLOBAL g_hDevMode = 0;
HGLOBAL g_hDevNames = 0;
HDC g_hPrintDC = 0;
BOOL g_bUserAbort = FALSE;
HWND g_hPrintDlg = 0;
BOOL g_bInvalidData1 = FALSE;
BOOL g_bInvalidData2 = FALSE;
#define HT_INSIDE 1
#define HT_LEFT 2
#define HT_RIGHT 3
#define HT_TOP 4
#define HT_BOTTOM 5
#define HT_LEFTTOP 6
#define HT_RIGHTTOP 7
#define HT_RIGHTBOTTOM 8
#define HT_LEFTBOTTOM 9
long FAR PASCAL _export WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL FAR PASCAL _export AboutDlgProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam);
BOOL FAR PASCAL _export AdvancedDlgProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam);
BOOL FAR PASCAL _export AbortProc(HDC hdcPrint, short sCode);
BOOL FAR PASCAL _export PrintDlgProc(HWND hDlg, UINT msg,
WPARAM wParam, LPARAM lParam);
static void drawBarcode(HWND hwnd, HDC hdc, HDC hicTarget,
HBARCODE hBar, LPRECT lprc);
static void printBarcode(HWND hwnd, HDC hdcPrint,
HBARCODE hBar, LPRECT lprc);
static long cmdProc(HWND hwnd, WPARAM wParam, LPARAM lParam);
static void XORDottedFrame (HDC hdc, LPRECT prc);
static DWORD getStyle(HWND hwnd);
static int hitTest(int x, int y, LPRECT lprc);
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
static char szAppName[] = "Easybar";
HWND hwnd;
MSG msg;
if (!hPrevInstance)
{
WNDCLASS cs;
cs.style = CS_HREDRAW | CS_VREDRAW;
cs.lpfnWndProc = WndProc;
cs.cbClsExtra = 0;
cs.cbWndExtra = DLGWINDOWEXTRA;
cs.hInstance = hInstance;
cs.hIcon = LoadIcon(hInstance, "BARDEMO");
cs.hCursor = NULL; //LoadCursor(hInstance, IDC_ARROW);
cs.hbrBackground = COLOR_WINDOW + 1;
cs.lpszMenuName = NULL;
cs.lpszClassName = szAppName;
RegisterClass(&cs);
}
hwnd = CreateDialog(hInstance, szAppName, 0, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
if (!IsDialogMessage(hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
long FAR PASCAL _export WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
HWND hctl;
int iType;
int i, ind;
LPSTR lp;
PAINTSTRUCT ps;
HDC hdc;
HFONT hFont, hFont0;
HBRUSH hBrush;
static PRINTDLG pd;
static bInitialized = FALSE;
static nDrag = 0;
static POINT pt;
static RECT rcPrev;
static TEXTMETRIC tm;
switch(msg) {
case WM_CREATE:
memset(&pd, 0, sizeof(pd));
pd.lStructSize = sizeof(pd);
pd.hwndOwner = hwnd;
pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
if (PrintDlg(&pd))
{
g_hPrintDC = pd.hDC;
g_hDevMode = pd.hDevMode;
g_hDevNames = pd.hDevNames;
}
return 0;
case WM_MOVE:
if (bInitialized) break;
bInitialized = TRUE;
g_hbar = 0;
for (i = 0; (i = EnumBarcodeTypes(i, &iType, &lp)) != 0; )
{
ind = (int)SendDlgItemMessage(hwnd, IDC_BARCODE, CB_ADDSTRING,
0, (LONG)lp);
SendDlgItemMessage(hwnd, IDC_BARCODE, CB_SETITEMDATA,
ind, (LONG)iType);
}
SendDlgItemMessage(hwnd, IDC_BARCODE, CB_SETCURSEL, 0, 0);
iType = (int) SendDlgItemMessage(hwnd, IDC_BARCODE,
CB_GETITEMDATA, (WPARAM)0, (LPARAM)0);
g_hbar = BarCreate(iType, 0);
g_iType = iType;
BarGetData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
SendDlgItemMessage(hwnd, IDC_DATA, WM_SETTEXT, 0,
(LONG)(LPSTR)g_tmp);
BarGetAddOnData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
if (!g_tmp[0])
{
EnableWindow(GetDlgItem(hwnd, IDC_ADDONDATA), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_ADDONMESG), FALSE);
}
else
{
SendDlgItemMessage(hwnd, IDC_ADDONDATA, WM_SETTEXT, 0,
(LONG)(LPSTR)g_tmp);
}
SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"0");
SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"90");
SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"180");
SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"270");
SendDlgItemMessage(hwnd, IDC_ORIENT, CB_SETCURSEL, 0, 0);
g_iOrient = 0;
for (i = 0; i < sizeof(g_styles) / sizeof(g_styles[0]); i++)
{
ind = (int) SendDlgItemMessage(hwnd, IDC_STYLE, LB_ADDSTRING,
(WPARAM)0, (LONG)(LPSTR)(g_styles[i].szName));
SendDlgItemMessage(hwnd, IDC_STYLE, LB_SETITEMDATA,
(WPARAM)ind, (LPARAM)g_styles[i].id);
}
// init font
hdc = GetDC(hwnd);
hFont0 = SelectObject(hdc, GetStockObject(DEVICE_DEFAULT_FONT));
GetObject(hFont0, sizeof(g_logfont), (LPSTR)&g_logfont);
strcpy(g_logfont.lfFaceName, "Arial");
g_logfont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
g_logfont.lfClipPrecision = CLIP_TT_ALWAYS;
g_logfont.lfWidth = 0;
hFont = CreateFontIndirect(&g_logfont);
SelectObject(hdc, hFont);
GetTextFace(hdc, LF_FACESIZE, g_logfont.lfFaceName);
GetTextMetrics(hdc, &tm);
if (tm.tmHeight < 0)
i = tm.tmHeight;
else
i = -(tm.tmHeight - tm.tmInternalLeading);
g_logfont.lfHeight = i;
wsprintf(g_tmp, "%d", MulDiv(-i, 72, GetDeviceCaps(hdc, LOGPIXELSY)));
SetWindowText(GetDlgItem(hwnd, IDC_POINT), g_tmp);
SetWindowText(GetDlgItem(hwnd, IDC_FONTNAME), g_logfont.lfFaceName);
SelectObject(hdc, hFont0);
DeleteObject(hFont);
// init color
g_clfFg = GetTextColor(hdc);
g_clfBg = GetBkColor(hdc);
g_iBkMode = GetBkMode(hdc);
if (g_iBkMode == TRANSPARENT)
SendDlgItemMessage(hwnd, IDC_TRANSPARENT, BM_SETCHECK, 1, 0);
else
SendDlgItemMessage(hwnd, IDC_TRANSPARENT, BM_SETCHECK, 0, 0);
ReleaseDC(hwnd, hdc);
hctl = GetDlgItem(hwnd, IDC_CANVAS);
GetWindowRect(hctl, &g_rcCanvas);
g_rcCanvas.right += 5;
g_rcCanvas.bottom += 5;
ScreenToClient(hwnd, (LPPOINT)&g_rcCanvas);
ScreenToClient(hwnd, ((LPPOINT)&g_rcCanvas) + 1);
MoveWindow(hctl, g_rcCanvas.left, g_rcCanvas.top,
g_rcCanvas.right - g_rcCanvas.left,
g_rcCanvas.bottom - g_rcCanvas.top, FALSE);
InflateRect(&g_rcCanvas, -1, -1);
CopyRect(&g_rc, &g_rcCanvas);
InflateRect(&g_rc, -(g_rcCanvas.right - g_rcCanvas.left) / 8,
-(g_rcCanvas.bottom - g_rcCanvas.top) / 4);
InvalidateRect(hwnd, &g_rcCanvas, FALSE);
SetFocus(GetDlgItem(hwnd, IDC_BARCODE));
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
IntersectClipRect(hdc, g_rcCanvas.left, g_rcCanvas.top,
g_rcCanvas.right, g_rcCanvas.bottom);
// draw bg
hBrush = SelectObject(hdc,
CreateSolidBrush(RGB(255, 255, 232)));
PatBlt(hdc, g_rcCanvas.left, g_rcCanvas.top,
g_rcCanvas.right - g_rcCanvas.left,
g_rcCanvas.bottom - g_rcCanvas.top, PATCOPY);
DeleteObject(SelectObject(hdc, hBrush));
if (g_bInvalidData1 || g_bInvalidData2)
{
DrawText(hdc, "Invalid Data!", -1, &g_rcCanvas,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
else