📄 prntfile.c
字号:
{
PSTR pTmp;
if (!pSrc[0])
return (FALSE); /* Indicates no filename was specified */
pTmp = pSrc;
while (*pTmp) /* Searches the string for wildcards */
{
switch (*pTmp++)
{
case '*':
case '?':
MessageBox(hWnd, "Wildcards not allowed.",
NULL, MB_OK | MB_ICONEXCLAMATION);
return (FALSE);
}
}
AddExt(pSrc, DefExt); /* Adds the default extension if needed */
if (OpenFile(pSrc, (LPOFSTRUCT) &OfStruct, OF_EXIST) >= 0)
{
sprintf(str, "Replace existing %s?", pSrc);
if (MessageBox(hWnd, str, "PrntFile",
MB_OKCANCEL | MB_ICONEXCLAMATION) == IDCANCEL)
return (FALSE);
}
strcpy(pDest, pSrc);
return (TRUE);
}
/****************************************************************************
FUNCTION: SaveFile(HWND)
PURPOSE: Save current file
COMMENTS:
This saves the current contents of the Edit buffer, and changes
bChanges to indicate that the buffer has not been changed since the
last save.
Before the edit buffer is sent, you must get its handle and lock it
to get its address. Once the file is written, you must unlock the
buffer. This allows Windows to move the buffer when not in immediate
use.
****************************************************************************/
BOOL SaveFile(hWnd)
HWND hWnd;
{
BOOL bSuccess;
int IOStatus; /* result of a file write */
if ((hFile = OpenFile(FileName, &OfStruct,
OF_PROMPT | OF_CANCEL | OF_CREATE)) < 0)
{
/* If the file can't be saved */
sprintf(str, "Cannot write to %s.", FileName);
MessageBox(hWnd, str, NULL, MB_OK | MB_ICONHAND);
return (FALSE);
}
hEditBuffer = (HANDLE)SendMessage(hEditWnd, EM_GETHANDLE, (WPARAM)0, (LPARAM)0);
pEditBuffer = LocalLock(hEditBuffer);
/* Set the cursor to an hourglass during the file transfer */
hSaveCursor = SetCursor(hHourGlass);
IOStatus = (int)_hwrite(hFile, pEditBuffer, strlen(pEditBuffer));
_lclose(hFile);
SetCursor(hSaveCursor);
if (IOStatus != (int)strlen(pEditBuffer))
{
sprintf(str, "Error writing to %s.", FileName);
MessageBox(hWnd, str, NULL, MB_OK | MB_ICONHAND);
bSuccess = FALSE;
}
else
{
bSuccess = TRUE; /* Indicates the file was saved */
bChanges = FALSE; /* Indicates changes have been saved */
}
LocalUnlock(hEditBuffer);
return (bSuccess);
}
/****************************************************************************
FUNCTION: QuerySaveFile(HWND);
PURPOSE: Called when some action might lose current contents
COMMENTS:
This function is called whenever we are about to take an action that
would lose the current contents of the edit buffer.
****************************************************************************/
BOOL QuerySaveFile(hWnd)
HWND hWnd;
{
int Response;
FARPROC lpSaveAsDlg;
if (bChanges)
{
sprintf(str, "Save current changes: %s", FileName);
Response = MessageBox(hWnd, str,
"PrntFile", MB_YESNOCANCEL | MB_ICONHAND);
if (Response == IDYES)
{
check_name:
/* Make sure there is a filename to save to */
if (!FileName[0])
{
lpSaveAsDlg = MakeProcInstance(SaveAsDlg, hInst);
Response = DialogBox(hInst, "SaveAs", hWnd, lpSaveAsDlg);
FreeProcInstance(lpSaveAsDlg);
if (Response == IDOK)
goto check_name;
else
return (FALSE);
}
SaveFile(hWnd);
}
else if (Response == IDCANCEL)
return (FALSE);
}
else
return (TRUE);
}
/****************************************************************************
FUNCTION: SetNewBuffer(HWND, HANDLE, PSTR)
PURPOSE: Set new buffer for edit window
COMMENTS:
Point the edit window to the new buffer, update the window title, and
redraw the edit window. If hNewBuffer is NULL, then create an empty
1K buffer, and return its handle.
****************************************************************************/
void SetNewBuffer(hWnd, hNewBuffer, Title)
HWND hWnd;
HANDLE hNewBuffer;
PSTR Title;
{
HANDLE hOldBuffer;
hOldBuffer = (HANDLE)SendMessage(hEditWnd, EM_GETHANDLE, (WPARAM)0, (LPARAM)0);
LocalFree(hOldBuffer);
if (!hNewBuffer) /* Allocates a buffer if none exists */
hNewBuffer = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, 1);
/* Updates the buffer and displays new buffer */
SendMessage(hEditWnd, EM_SETHANDLE, hNewBuffer, 0L);
SetWindowText(hWnd, Title);
SetFocus(hEditWnd);
bChanges = FALSE;
}
/****************************************************************************
FUNCTION: ExtDeviceMode()
PURPOSE: Test for the existence of ExtDeviceMode function
****************************************************************************/
int ExtDeviceMode(HWND hWnd,
HANDLE phDriver,
LPDEVMODE lpDevModeOutput,
LPSTR lpDeviceName,
LPSTR lpPort,
LPDEVMODE lpDevModeInput,
LPSTR lpProfile,
WORD wMode)
{
FARPROC lpfpExtDeviceMode;
if (lpfpExtDeviceMode = GetProcAddress(phDriver,(LPSTR)"EXTDEVICEMODE"))
return (*lpfpExtDeviceMode)((HWND)hWnd,
(HANDLE)phDriver,
(LPDEVMODE)lpDevModeOutput,
(LPSTR)lpDeviceName,
(LPSTR)lpPort,
(LPDEVMODE)lpDevModeInput,
(LPSTR)lpProfile,
(WORD)wMode);
else
return(-1);
}
/****************************************************************************
FUNCTION: GetPrinterDC()
PURPOSE: Get hDc for current device on current output port according to
info in WIN.INI.
COMMENTS:
Searches WIN.INI for information about what printer is connected, and
if found, creates a DC for the printer.
returns
hDC > 0 if success
hDC = 0 if failure
****************************************************************************/
HANDLE GetPrinterDC()
{
char pPrintInfo[80];
LPSTR lpTemp;
LPSTR lpPrintType;
LPSTR lpPrintDriver;
LPSTR lpPrintPort;
char pmodule[32];
HANDLE phDriver;
DEVMODE DevModeIn;
HANDLE hDevModeOut;
PSTR lpDevModeOut;
int count;
hDevModeOut = NULL;
if (!GetProfileString("windows", "Device", (LPSTR)"", pPrintInfo, 80))
return (NULL);
lpTemp = lpPrintType = pPrintInfo;
lpPrintDriver = lpPrintPort = 0;
while (*lpTemp)
{
if (*lpTemp == ',')
{
*lpTemp++ = 0;
while (*lpTemp == ' ')
lpTemp = AnsiNext(lpTemp);
if (!lpPrintDriver)
lpPrintDriver = lpTemp;
else
{
lpPrintPort = lpTemp;
break;
}
}
else
lpTemp = AnsiNext(lpTemp);
}
/********* Call to ExtDeviceMode code added *******/
/** Build driver name **/
wsprintf (pmodule, "%s.drv",(LPSTR)lpPrintDriver);
/** Load driver **/
if ((phDriver = LoadLibrary(pmodule)) > 31)
{
/** Call ExtDeviceMode function **/
count = ExtDeviceMode((HWND)NULL,
(HANDLE)phDriver,
(LPDEVMODE)NULL,
(LPSTR)lpPrintType,
(LPSTR)lpPrintPort,
(LPDEVMODE)NULL,
(LPSTR)NULL,
(WORD)0);
if (count != -1)
{
/** Allocate storage for devmode structure **/
hDevModeOut = LocalAlloc(LHND, count);
if (hDevModeOut)
{
/** Set orientation to landscape **/
lpDevModeOut = LocalLock(hDevModeOut);
lstrcpy(DevModeIn. dmDeviceName, lpPrintType);
DevModeIn.dmSpecVersion = DM_SPECVERSION;
DevModeIn.dmDriverVersion = 0;
DevModeIn.dmSize = sizeof(DEVMODE);
DevModeIn.dmDriverExtra = 0;
DevModeIn.dmFields = DM_ORIENTATION;
DevModeIn.dmOrientation = DMORIENT_LANDSCAPE;
count = ExtDeviceMode((HWND)NULL,
(HANDLE)phDriver,
(LPDEVMODE)lpDevModeOut,
(LPSTR)lpPrintType,
(LPSTR)lpPrintPort,
(LPDEVMODE)&DevModeIn,
(LPSTR)NULL,
DM_IN_BUFFER | DM_OUT_BUFFER);
return (CreateDC(lpPrintDriver, lpPrintType, lpPrintPort,
(LPSTR)lpDevModeOut));
}
}
else
return (CreateDC(lpPrintDriver, lpPrintType, lpPrintPort,
(LPSTR)NULL));
if (hDevModeOut)
{
LocalUnlock(hDevModeOut);
LocalFree(hDevModeOut);
lpDevModeOut = NULL;
}
FreeLibrary(phDriver);
}
return (CreateDC(lpPrintDriver, lpPrintType, lpPrintPort, (LPSTR) NULL));
}
/****************************************************************************
FUNCTION: AbortProc()
PURPOSE: Processes messages for the Abort Dialog box
****************************************************************************/
int FAR PASCAL AbortProc(hPr, Code)
HDC hPr; /* for multiple printer display contexts */
int Code; /* printing status */
{
MSG msg;
/* Process messages intended for the abort dialog box */
while (!bAbort && PeekMessage(&msg, NULL, NULL, NULL, TRUE))
if (!IsDialogMessage(hAbortDlgWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
/* bAbort is TRUE (return is FALSE) if the user has aborted */
return (!bAbort);
}
/****************************************************************************
FUNCTION: AbortDlg(HWND, unsigned, WORD, LONG)
PURPOSE: Processes messages for printer abort dialog box
MESSAGES:
WM_INITDIALOG - initialize dialog box
WM_COMMAND - Input received
COMMENTS
This dialog box is created while the program is printing, and allows
the user to cancel the printing process.
****************************************************************************/
int FAR PASCAL AbortDlg(hDlg, msg, wParam, lParam)
HWND hDlg;
unsigned msg;
WORD wParam;
LONG lParam;
{
switch(msg)
{
/* Watch for Cancel button, RETURN key, ESCAPE key, or SPACE BAR */
case WM_COMMAND:
return (bAbort = TRUE);
case WM_INITDIALOG:
/* Set the focus to the Cancel box of the dialog */
SetFocus(GetDlgItem(hDlg, IDCANCEL));
SetDlgItemText(hDlg, IDC_FILENAME, FileName);
return (TRUE);
}
return (FALSE);
}
/****************************************************************************
FUNCTION: About(HWND, unsigned, WORD, LONG)
PURPOSE: Processes messages for "About" dialog box
MESSAGES:
WM_INITDIALOG - initialize dialog box
WM_COMMAND - Input received
****************************************************************************/
BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{
switch (message)
{
case WM_INITDIALOG:
return (TRUE);
case WM_COMMAND:
if (wParam == IDOK || wParam == IDCANCEL)
{
EndDialog(hDlg, TRUE);
return (TRUE);
}
return (TRUE);
}
return (FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -