📄 gpm_os2.c
字号:
/* the Get_Event function blocks until there is an event to process */ DosWaitEventSem( hevKeyLock, SEM_INDEFINITE_WAIT ); DosQueryEventSem( hevKeyLock, &ulRequestCount ); DosResetEventSem( hevKeyLock, &ulRequestCount ); event->what = ourevent.what; event->info = ourevent.info; return; } void RunPMWindow( ULONG dummy ) { unsigned char classname[] = "DisplayClass"; ULONG flClassFlags; static HMQ hmq; QMSG qmsg; if ( (hab = WinInitialize( 0 )) == 0 ) { printf( "Error doing WinInitialize()\n" ); return; } if ( (hmq = WinCreateMsgQueue( hab, 0 )) == (HMQ)NULL ) { printf( "Error doing WinCreateMsgQueue()\n" ); return; } if ( !WinRegisterClass( hab, (PSZ)classname, (PFNWP)Message_Process, CS_SIZEREDRAW, 0 ) ) { printf( "Error doing WinRegisterClass()\n" ); return; } flClassFlags = FCF_TITLEBAR | FCF_MINBUTTON | FCF_DLGBORDER | FCF_TASKLIST | FCF_SYSMENU; if ( (hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, &flClassFlags, (PSZ)classname, (PSZ)"FreeType PM Graphics", WS_VISIBLE, 0, 0, &hwndClient )) == 0 ) { printf( "Error doing WinCreateStdWindow()\n" ); return; } /* find the title window handle */ hwndTitle = WinWindowFromID( hwndFrame, FID_TITLEBAR ); /* set Window size and position */ WinSetWindowPos( hwndFrame, 0L, (SHORT)60, (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) - ( VIO_HEIGHT + MAG_HEIGHT + 100 ), (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CYDLGFRAME ) * 2 + VIO_WIDTH, (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CYTITLEBAR ) + WinQuerySysValue( HWND_DESKTOP, SV_CYDLGFRAME ) * 2 + VIO_HEIGHT + MAG_HEIGHT, SWP_SIZE | SWP_MOVE ) ; /* run the message queue till the end */ while ( WinGetMsg( hab, &qmsg, (HWND)NULL, 0, 0 ) ) WinDispatchMsg( hab, &qmsg ); /* clean-up */ WinDestroyWindow( hwndFrame ); hwndFrame = (HWND)NULL; WinDestroyMsgQueue( hmq ); WinTerminate( hab ); /* await death... */ while ( 1 ) DosSleep( 100 ); } void Adjust_Mag_Rectangle( void ) { SIZEL source, target; /* Step 1, find optimal source size for this mag and window size */ source.cx = mag_win_size.cx / magnification; if (source.cx > vio_Width) source.cx = vio_Width; source.cy = mag_win_size.cy / magnification; if (source.cy > vio_Height) source.cy = vio_Height; target.cx = source.cx * magnification; target.cy = source.cy * magnification; aptlMagd[0].x = (mag_win_size.cx - target.cx) / 2; aptlMagd[0].y = (mag_win_size.cy - target.cy) / 2; aptlMagd[1].x = aptlMagd[0].x + target.cx - 1; aptlMagd[1].y = aptlMagd[0].x + target.cy - 1; /* Step 2, try crosshairs point dependent coordinates */ aptlMagd[2].x = view_target.x - source.cx / 2; aptlMagd[2].y = view_target.y - source.cy / 2; if (aptlMagd[2].x < 0 ) aptlMagd[2].x = 0; if (aptlMagd[2].y < 0 ) aptlMagd[2].y = 0; if (aptlMagd[2].x > vio_Width - source.cx) aptlMagd[2].x = vio_Width - source.cx; if (aptlMagd[2].y > vio_Height - source.cy) aptlMagd[2].y = vio_Height - source.cy; aptlMagd[3].x = aptlMagd[2].x + source.cx - 1; aptlMagd[3].y = aptlMagd[2].y + source.cy - 1; } /* End of Adjust_Mag_Rectangle; */ /* Message processing for our PM Window class */ MRESULT EXPENTRY Message_Process( HWND handle, ULONG mess, MPARAM parm1, MPARAM parm2 ) { static HDC hdc; static HPS hps; static BOOL minimized; POINTL top_corner, bottom_corner; SWP swp; int i; switch( mess ) { case WM_DESTROY: /* warn the main thread to quit if it didn't know */ ourevent.what = event_Quit; ourevent.info = 0; DosPostEventSem( hevKeyLock ); break; case WM_CREATE: /* set original magnification */ magnification = 4; minimized = FALSE; /* create Device Context and Presentation Space for screen. */ /* could we use a cached one ? */ hdc = WinOpenWindowDC( handle ); mag_win_size.cx = 0; mag_win_size.cy = 0; hps = GpiCreatePS( hab, hdc, &mag_win_size, PU_PELS | GPIT_MICRO | GPIA_ASSOC | GPIF_DEFAULT ); /* Set to size of magnifier window */ mag_win_size.cx = MAG_WIDTH; mag_win_size.cy = MAG_HEIGHT; Adjust_Mag_Rectangle(); /* take the input focus */ WinFocusChange( HWND_DESKTOP, handle, 0L ); break; case WM_BUTTON1DOWN: if ( MOUSEMSG( &mess )->y >= MAG_HEIGHT ) { view_target.x = MOUSEMSG( &mess )->x; view_target.y = MOUSEMSG( &mess )->y - MAG_HEIGHT; Adjust_Mag_Rectangle(); WinInvalidateRect( hwndClient, NULL, FALSE ); } return WinDefWindowProc( handle, mess, parm1, parm2 ); break; case WM_MINMAXFRAME: /* to update minimized if changed */ swp = *((PSWP) parm1); if ( swp.fl & SWP_MINIMIZE ) minimized = TRUE; if ( swp.fl & SWP_RESTORE ) minimized = FALSE; return WinDefWindowProc( handle, mess, parm1, parm2 ); break; case WM_ERASEBACKGROUND: case WM_PAINT: /* reset the window title only if not minimized */ if ( !minimized ) WinSetWindowText( hwndTitle, Header ); /* copy the memory image of the screen out to the real screen */ DosRequestMutexSem( hmtxPSMemoryLock, SEM_INDEFINITE_WAIT ); WinBeginPaint( handle, hps, NULL ); /* main image and magnified picture */ GpiBitBlt( hps, hpsMemory, 4L, aptlFull, ROP_SRCCOPY, BBO_AND ); GpiBitBlt( hps, hpsMemory, 4L, aptlMagd, ROP_SRCCOPY, BBO_AND ); /* double-dash the magnifing bounding box. Paint the mag liner? */ if ( magnification != 1 ) { GpiSetLineType( hps, LINETYPE_LONGDASH ); bottom_corner.x = aptlMagd[2].x - 1; bottom_corner.y = aptlMagd[2].y + MAG_HEIGHT - 1; top_corner.x = aptlMagd[3].x ; top_corner.y = aptlMagd[3].y + MAG_HEIGHT; GpiMove( hps, &bottom_corner ); GpiBox( hps, DRO_OUTLINE, &top_corner, 0L, 0L );#if 0 GpiSetClipRegion(); GpiErase();#endif } WinEndPaint( hps ); DosReleaseMutexSem( hmtxPSMemoryLock ); break; case WM_CHAR: if ( CHARMSG( &mess )->fs & KC_KEYUP ) break; switch ( CHARMSG( &mess )->vkey ) { case VK_ESC: ourevent.what = event_Quit; ourevent.info = 0; DosPostEventSem( hevKeyLock ); break; case VK_PAGEDOWN: if ( magnification < MAX_MAG ) { magnification += 1; Adjust_Mag_Rectangle(); WinInvalidateRect( handle, NULL, FALSE ); } break; case VK_PAGEUP: if ( magnification > 1 ) { magnification -= 1; Adjust_Mag_Rectangle(); WinInvalidateRect( handle, NULL, FALSE ); } break; case VK_LEFT: if ( view_target.x > 0 ) { view_target.x -= 1; Adjust_Mag_Rectangle(); WinInvalidateRect( handle, NULL, FALSE ); } break; case VK_RIGHT: if ( view_target.x < VIO_WIDTH - 1 ) { view_target.x += 1; Adjust_Mag_Rectangle(); WinInvalidateRect( handle, NULL, FALSE ); } break; case VK_DOWN: if ( view_target.y > 0 ) { view_target.y -= 1; Adjust_Mag_Rectangle(); WinInvalidateRect( handle, NULL, FALSE ); } break; case VK_UP: if ( view_target.y < VIO_HEIGHT - 1 ) { view_target.y += 1; Adjust_Mag_Rectangle(); WinInvalidateRect( handle, NULL, FALSE ); } break; case VK_F1: /* bring up help and about dialog window */ break; } if ( CHARMSG( &mess )->fs & KC_CHAR ) { char c = (CHAR)CHARMSG( &mess )->chr ; for ( i = 0; i < NUM_Translators; i++ ) { if ( c == trans[i].key ) { ourevent.what = trans[i].event_class; ourevent.info = trans[i].event_info; DosPostEventSem( hevKeyLock ); return (MRESULT)TRUE; } } /* unrecognized keystroke */ ourevent.what = event_Keyboard; ourevent.info = (int)c; DosPostEventSem( hevKeyLock ); } break; default: return WinDefWindowProc( handle, mess, parm1, parm2 ); } return (MRESULT) FALSE; }/* End */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -