Programming Guide |
Translates screen coordinates to display coordinates
int sm_translatecoords(int column, int line, int *column_ptr, int *line_ptr);
column, line
- Zero-based coordinates relative to the current screen, where
0,0
specifies the screen's upper-left corner.column_ptr, line_ptr
- On return, contain the pixel coordinates relative to the drawing area.
Motif, Windows
- 0 Success.
sm_translatecoords
translates the Pantherline
andcolumn
relative to a screen, into pixel line and column relative to the upper left hand corner of the drawing area.line
andcolumn
are zero based. This function in conjunction with sm_drawingarea is useful when placing objects such as bitmapped graphics or custom widgets on a Panther screen.
#include <smdefs.h>
#include <smwin.h>
#include "drawbmp.h"
/*
* The following program shows how to display a bitmap file
* on current Panther screen in Windows. The routine uses
* several functions from sample code in Programming Windows
* 3.1, pp. 610-616 by Charles Petzold (Microsoft Press,
* 1992). All other functions are either standard C,
* Panther API, or Windows API calls
*/
int prlfx_display_bmp_file(char *file_name, int ln, int col)
{
static BYTE huge *lpDib;
HWND hwnd;
HDC hdc;
BYTE huge *lpDibBits;
short cxDib, cyDib, pix_ln, pix_col;
if (lpDib != NULL) {
GlobalFreePtr(lpDib);
lpDib = NULL;
}
lpDib = ReadDib(file_name); /* Petzold, pp. 613-614 */
if (lpDib == NULL) {
sm_message_box("Could not open DIB file", "ERROR",
SM_MB_OK | SM_MB_ICONSTOP, 0);
return RET_FATAL;
}
hwnd = sm_mw_drawingarea();
hdc = GetDC(hwnd);
if (hdc != NULL) {
lpDibBits = GetDibBitsAddr(lpDib);/* Petzold,p. 612 */
cxDib = GetDibWidth(lpDib); /* Petzold, p. 612 */
cyDib = GetDibHeight(lpDib); /* Petzold, p. 612 */
if (sm_translatecoords(col, ln, &pix_col, &pix_ln) < 0) {
char buf[100];
sprintf(buf,
"prlfx_display_bmp_file: invalid line/column: %d/%d",
ln, col);
sm_message_box(buf, "ERROR",
SM_MB_OK | SM_MB_ICONSTOP, 0);
return RET_FATAL;
}
SetStretchBltMode(hdc, COLORONCOLOR);
SetDIBitsToDevice(
hdc, pix_col, pix_ln, cxDib, cyDib, 0, 0, 0, cyDib,
(LPSTR) lpDibBits, (LPBITMAPINFO) lpDib,
DIB_RGB_COLORS);
}
else {
sm_message_box("Could not get handle to drawing area",
"ERROR", SM_MB_OK | SM_MB_ICONSTOP, 0);
}
ReleaseDC(hwnd, hdc);
return RET_SUCCESS;
}