home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
windows
/
getbitmp.zip
/
GETBITMP.C
< prev
next >
Wrap
Text File
|
1988-01-05
|
16KB
|
476 lines
/* Getbitmp.c
Les consultants génicom
Copyright (c) Les consultants génicom 1987 1988
Programmé Par Bernard de Champlain */
#include "windows.h"
#include "winexp.h"
#include "io.h"
#include "getbitmp.h"
HANDLE hInst;
HBITMAP hBitmap = NULL;
BOOL AutoAbort = TRUE, SaveEnable = FALSE;
FARPROC lpprocAbout, lpprocSize, lpprocSave;
short Horizontal, Vertical, BltMode;
char szAppName[20];
char szAbout[20];
char szWindowTitle[40];
char szCliplock[40];
char szNotBit[40];
char szClipClose[40];
char szClipMemory[40];
long FAR PASCAL GetbitmpWndProc(HWND, unsigned, WORD, LONG);
BOOL FAR PASCAL GetbitmpAbout(hDlg, message, wParam, lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{
switch (message)
{
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_KILLFOCUS:
case WM_KEYDOWN:
if (!AutoAbort)
break;
case WM_COMMAND:
if (AutoAbort)
ReleaseCapture();
EndDialog(hDlg, TRUE);
return(TRUE);
break;
case WM_INITDIALOG:
if (AutoAbort)
SetCapture(hDlg);
return(TRUE);
break;
}
return(FALSE);
}
BOOL FAR PASCAL GetbitmpSize(hDlg, message, wParam, lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{
unsigned char Buf[10];
int sprintf(unsigned char *, unsigned char *, );
short atoi(unsigned char *);
switch (message)
{
case WM_INITDIALOG:
sprintf(Buf, "%4d", Horizontal);
SetDlgItemText(hDlg, IDHORIZ, (LPSTR)Buf);
sprintf(Buf, "%4d", Vertical);
SetDlgItemText(hDlg, IDVERTI, (LPSTR)Buf);
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
if (BltMode == WHITEONBLACK)
CheckRadioButton(hDlg, IDOR, IDCUT, IDOR);
else
if (BltMode == BLACKONWHITE)
CheckRadioButton(hDlg, IDOR, IDCUT, IDAND);
else
CheckRadioButton(hDlg, IDOR, IDCUT, IDCUT);
break;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
if (IsWindowEnabled(GetDlgItem(hDlg, IDOK))) {
GetDlgItemText(hDlg, (unsigned)IDHORIZ, (LPSTR)Buf, 5);
Horizontal = atoi(Buf);
GetDlgItemText(hDlg, (unsigned)IDVERTI, (LPSTR)Buf, 5);
Vertical = atoi(Buf);
if (IsDlgButtonChecked(hDlg, IDOR))
BltMode = WHITEONBLACK;
else
if (IsDlgButtonChecked(hDlg, IDAND))
BltMode = BLACKONWHITE;
else
BltMode = COLORONCOLOR;
EndDialog(hDlg, TRUE);
}
break;
case IDCANCEL:
EndDialog(hDlg, FALSE);
break;
case IDHORIZ:
case IDVERTI:
if (HIWORD(lParam) == EN_KILLFOCUS) {
GetDlgItemText(hDlg, (unsigned)wParam, (LPSTR)Buf, 5);
sprintf(Buf, "%4d", atoi(Buf));
SetDlgItemText(hDlg, (unsigned)wParam, (LPSTR)Buf);
}
if (HIWORD(lParam) == EN_CHANGE) {
GetDlgItemText(hDlg, IDHORIZ, (LPSTR)Buf, 5);
GetDlgItemText(hDlg, IDVERTI, (LPSTR)&Buf[5], 5);
EnableWindow(GetDlgItem(hDlg, IDOK),
(BOOL)(atoi(Buf) && atoi(&Buf[5])));
}
break;
case IDOR:
case IDAND:
case IDCUT:
CheckRadioButton(hDlg, IDOR, IDCUT, (int)wParam);
break;
default:
return(FALSE);
}
break;
default:
return(FALSE);
}
return(TRUE);
}
BOOL FAR PASCAL GetbitmpSave(hDlg, message, wParam, lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{
char *ResultBuf, *Scan;
int len;
switch (message)
{
case WM_INITDIALOG:
/* Initialize Path field with current directory */
DlgDirList(hDlg, (LPSTR)0, 0, IDPATH, 0);
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
break;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
if (IsWindowEnabled(GetDlgItem(hDlg, IDOK))) {
len = 4+GetWindowTextLength(GetDlgItem(hDlg, IDEDIT));
if (ResultBuf = (char *)LocalAlloc(LPTR, (WORD)++len)) {
GetDlgItemText(hDlg, IDEDIT, (LPSTR)ResultBuf, len);
for (Scan = ResultBuf; *Scan && *Scan != '.'; Scan++);
if (!*Scan)
lstrcpy((LPSTR)Scan, (LPSTR)".BMP");
AnsiUpper((LPSTR)ResultBuf);
}
EndDialog(hDlg, (int)ResultBuf);
}
break;
case IDCANCEL:
EndDialog(hDlg, NULL);
break;
case IDEDIT:
if (HIWORD(lParam) == EN_CHANGE)
EnableWindow(GetDlgItem(hDlg, IDOK), (BOOL)(SendMessage(
GetDlgItem(hDlg, IDEDIT), WM_GETTEXTLENGTH, 0, 0L)));
break;
default:
return(FALSE);
}
break;
default:
return(FALSE);
}
return(TRUE);
}
BOOL GetClip(hWnd)
HWND hWnd;
{
BOOL Retry = FALSE;
HBITMAP hClipBits;
BITMAP ClipBits;
HANDLE hBits;
LPSTR lpBits;
if (OpenClipboard(hWnd)) {
if (hClipBits = (HBITMAP)GetClipboardData(CF_BITMAP)) {
GetObject((HANDLE)hClipBits, sizeof(BITMAP), (LPSTR)&ClipBits);
if (hBitmap)
DeleteObject((HANDLE)hBitmap);
if ((hBitmap = CreateBitmapIndirect((BITMAP FAR *)&ClipBits)) &&
(hBits = GlobalAlloc(GHND,
(DWORD)(ClipBits.bmWidthBytes * ClipBits.bmHeight)))) {
lpBits = GlobalLock(hBits);
GetBitmapBits(hClipBits,
(long)ClipBits.bmWidthBytes * ClipBits.bmHeight, lpBits);
SetBitmapBits(hBitmap,
(DWORD)ClipBits.bmWidthBytes * ClipBits.bmHeight, lpBits);
GlobalUnlock(hBits);
GlobalFree(hBits);
Horizontal = ClipBits.bmWidth;
Vertical = ClipBits.bmHeight;
BltMode = BLACKONWHITE;
if (!SaveEnable) {
SaveEnable = TRUE;
EnableMenuItem(GetMenu(hWnd), IDSIZE, MF_ENABLED);
EnableMenuItem(GetMenu(hWnd), IDSAVE, MF_ENABLED);
DrawMenuBar(hWnd);
}
}
else {
Retry = (BOOL)(MessageBox(hWnd, (LPSTR)szClipMemory, (LPSTR)NULL,
MB_RETRYCANCEL | MB_ICONHAND) == IDRETRY);
if (SaveEnable) {
SaveEnable = FALSE;
EnableMenuItem(GetMenu(hWnd), IDSIZE, MF_GRAYED);
EnableMenuItem(GetMenu(hWnd), IDSAVE, MF_GRAYED);
DrawMenuBar(hWnd);
}
}
}
else
Retry = (BOOL)(MessageBox(hWnd, (LPSTR)szNotBit, (LPSTR)NULL,
MB_RETRYCANCEL | MB_ICONHAND) == IDRETRY);
if (!CloseClipboard())
Retry = (BOOL)(MessageBox(hWnd, (LPSTR)szClipClose, (LPSTR)NULL,
MB_RETRYCANCEL | MB_ICONHAND) == IDRETRY);
}
else
return((BOOL)(MessageBox(hWnd, (LPSTR)szCliplock, (LPSTR)NULL,
MB_RETRYCANCEL | MB_ICONHAND) == IDRETRY));
return(Retry);
}
void GetbitmpCommand(hWnd, id)
HWND hWnd;
WORD id;
{
switch (id)
{
case IDCAPT:
while(GetClip(hWnd));
break;
case IDSIZE:
DialogBox(hInst, MAKEINTRESOURCE(SIZEBOX), hWnd, lpprocSize);
break;
case IDSAVE: {
char *FileName;
OFSTRUCT ofStruct;
int hFile;
HDC hDC, hSrcDC, hDstDC;
BOOL Abort = FALSE;
BITMAP Bitmap;
HBITMAP hBitmapDst = NULL, hBitmapSave = hBitmap;
HANDLE hBits;
LPSTR lpBits;
if (FileName = (char *)DialogBox(hInst, MAKEINTRESOURCE(SAVEBOX),
hWnd, lpprocSave)) {
if ((hFile = OpenFile((LPSTR)FileName, (LPOFSTRUCT)&ofStruct,
OF_WRITE | OF_CREATE)) != -1) {
GetObject((HANDLE)hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);
if (Horizontal!=Bitmap.bmWidth || Vertical!=Bitmap.bmHeight) {
hDC = GetDC(hWnd);
hSrcDC = CreateCompatibleDC(hDC);
hDstDC = CreateCompatibleDC(hDC);
ReleaseDC(hWnd, hDC);
SelectObject(hSrcDC, (HANDLE)hBitmap);
if (hBitmapSave = hBitmapDst =
CreateCompatibleBitmap(hSrcDC, Horizontal, Vertical)) {
SelectObject(hDstDC, (HANDLE)hBitmapDst);
SetStretchBltMode(hDstDC, BltMode);
StretchBlt(hDstDC, 0, 0, Horizontal, Vertical,
hSrcDC, 0, 0, Bitmap.bmWidth, Bitmap.bmHeight,
SRCCOPY);
}
else {
MessageBox(hWnd, (LPSTR)szClipMemory, (LPSTR)NULL,
MB_OK | MB_ICONHAND);
Abort = TRUE;
}
DeleteDC(hDstDC);
DeleteDC(hSrcDC);
}
if (!Abort) {
GetObject((HANDLE)hBitmapSave, sizeof(BITMAP),
(LPSTR)&Bitmap);
if (hBits = GlobalAlloc(GHND,
(DWORD)(Bitmap.bmWidthBytes * Bitmap.bmHeight))) {
lpBits = GlobalLock(hBits);
GetBitmapBits(hBitmapSave,
(long)Bitmap.bmWidthBytes*Bitmap.bmHeight,lpBits);
_lwrite(hFile, (LPSTR)"\002", 2);
_lwrite(hFile, (LPSTR)&Bitmap, 14);
_lwrite(hFile, lpBits, (int)(Bitmap.bmWidthBytes *
Bitmap.bmHeight));
_lclose(hFile);
GlobalUnlock(hBits);
GlobalFree(hBits);
}
else
MessageBox(hWnd, (LPSTR)szClipMemory, (LPSTR)NULL,
MB_OK | MB_ICONHAND);
if (hBitmapDst)
DeleteObject((HANDLE)hBitmapDst);
}
}
LocalFree((HANDLE)FileName);
}
break;
}
}
}
BOOL GetbitmpInit(hInstance)
HANDLE hInstance;
{
PWNDCLASS pGetbitmpClass;
/* Loading from string table */
LoadString(hInstance, IDSNAME, (LPSTR)szAppName, 20);
LoadString(hInstance, IDSABOUT, (LPSTR)szAbout, 20);
LoadString(hInstance, IDSTITLE, (LPSTR)szWindowTitle, 40);
LoadString(hInstance, IDSCLIPBD, (LPSTR)szCliplock, 40);
LoadString(hInstance, IDSCLIPBM, (LPSTR)szNotBit, 40);
LoadString(hInstance, IDSCLIPCL, (LPSTR)szClipClose, 40);
LoadString(hInstance, IDSCLIPMM, (LPSTR)szClipMemory, 40);
pGetbitmpClass = (PWNDCLASS)LocalAlloc(LPTR, sizeof(WNDCLASS));
pGetbitmpClass->hCursor = LoadCursor(NULL, IDC_ARROW);
pGetbitmpClass->hIcon = LoadIcon(hInstance, (LPSTR)szAppName);
pGetbitmpClass->lpszMenuName = (LPSTR)szAppName;
pGetbitmpClass->hInstance = hInstance;
pGetbitmpClass->lpszClassName = (LPSTR)szAppName;
pGetbitmpClass->hbrBackground = (HBRUSH)COLOR_WINDOW+1;
pGetbitmpClass->style = CS_HREDRAW | CS_VREDRAW;
pGetbitmpClass->lpfnWndProc = GetbitmpWndProc;
if (!RegisterClass((LPWNDCLASS)pGetbitmpClass))
return(FALSE); /* Initialization failed */
LocalFree((HANDLE)pGetbitmpClass);
return(TRUE); /* Initialization succeeded */
}
int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
HANDLE hInstance, hPrevInstance;
LPSTR lpszCmdLine;
int cmdShow;
{
MSG msg;
HWND hWnd;
HMENU hMenu;
if (!hPrevInstance) {
if (!GetbitmpInit(hInstance))
return(FALSE);
}
else {
/* Copy data from previous instance */
GetInstanceData(hPrevInstance, (PSTR)szAppName, 20);
GetInstanceData(hPrevInstance, (PSTR)szAbout, 20);
GetInstanceData(hPrevInstance, (PSTR)szWindowTitle, 40);
GetInstanceData(hPrevInstance, (PSTR)szCliplock, 40);
GetInstanceData(hPrevInstance, (PSTR)szNotBit, 40);
GetInstanceData(hPrevInstance, (PSTR)szClipClose, 40);
GetInstanceData(hPrevInstance, (PSTR)szClipMemory, 40);
}
hWnd = CreateWindow((LPSTR)szAppName,
(LPSTR)szWindowTitle,
WS_TILEDWINDOW,
0, /* x - ignored for tiled windows */
0, /* y - ignored for tiled windows */
0, /* cx - ignored for tiled windows */
0, /* cy - ignored for tiled windows */
(HWND)NULL, /* no parent */
(HMENU)NULL, /* use class menu */
(HANDLE)hInstance, /* handle to window instance */
(LPSTR)NULL
);
hInst = hInstance;
lpprocAbout = MakeProcInstance((FARPROC)GetbitmpAbout, hInstance);
lpprocSize = MakeProcInstance((FARPROC)GetbitmpSize, hInstance);
lpprocSave = MakeProcInstance((FARPROC)GetbitmpSave, hInstance);
hMenu = GetSystemMenu(hWnd, FALSE);
ChangeMenu(hMenu, 0, NULL, 999, MF_APPEND | MF_SEPARATOR);
ChangeMenu(hMenu, 0, (LPSTR)szAbout, IDSABOUT, MF_APPEND | MF_STRING);
ShowWindow(hWnd, cmdShow);
DialogBox(hInst, MAKEINTRESOURCE(ABOUTBOX), hWnd, lpprocAbout);
AutoAbort = FALSE;
while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
TranslateMessage((LPMSG)&msg);
DispatchMessage((LPMSG)&msg);
}
return((int)msg.wParam);
}
LONG FAR PASCAL GetbitmpWndProc(hWnd, message, wParam, lParam)
HWND hWnd;
unsigned message;
WORD wParam;
LONG lParam;
{
switch (message)
{
case WM_SYSCOMMAND:
switch (wParam)
{
case IDSABOUT:
DialogBox(hInst, MAKEINTRESOURCE(ABOUTBOX), hWnd, lpprocAbout);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
break;
case WM_CREATE:
EnableMenuItem(GetMenu(hWnd), IDSIZE, MF_GRAYED);
EnableMenuItem(GetMenu(hWnd), IDSAVE, MF_GRAYED);
break;
case WM_PAINT:
ValidateRect(hWnd, (LPRECT)NULL);
break;
case WM_COMMAND:
GetbitmpCommand(hWnd, wParam);
break;
case WM_DESTROY:
if (hBitmap)
DeleteObject((HANDLE)hBitmap);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return(0L);
}