static BOOL init_instance( int show ) { HWND frame_hwnd; ULONG flags = FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU | FCF_MENU | FCF_MINMAX | FCF_SHELLPOSITION; frame_hwnd = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, &flags, "DrawDemo", "Draw a Picture", WS_VISIBLE, 0, 200, &hwnd ); /* If window could not be created, return "failure" */ if( hwnd == 0 || frame_hwnd == 0 ) { return (FALSE); } /* Make the window visible; update its client area; and return "success" */ WinSetWindowPos( frame_hwnd, HWND_TOP, 50, 50, 200, 200, show ); make_buttons( hwnd ); WinShowWindow( frame_hwnd, TRUE ); WinUpdateWindow( frame_hwnd ); return( TRUE ); }
static void refresh_rectangle( grPMSurface* surface, int x, int y, int w, int h ) { LOG(( "Os2PM: refresh_rectangle( %08lx, %d, %d, %d, %d )\n", (long)surface, x, y, w, h )); (void)x; (void)y; (void)w; (void)h; /* convert_rectangle( surface, x, y, w, h ); */ LOCK( surface->image_lock ); GpiSetBitmapBits( surface->image_ps, 0, surface->root.bitmap.rows, surface->root.bitmap.buffer, surface->bitmap_header ); UNLOCK( surface->image_lock ); WinInvalidateRect( surface->client_window, NULL, FALSE ); WinUpdateWindow( surface->frame_window ); }
OWindow& OWindow::setForeColor(COLOR color) { pparms.Fore = color; WinSetPresParam(hwnd, PP_FOREGROUNDCOLOR, sizeof(COLOR), &pparms.Fore); WinUpdateWindow(hwnd); return(*this); }
OWindow& OWindow::setFont(PSZ fontnamesize) { strcpy(pparms.Font, fontnamesize); WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(pparms.Font)+1, pparms.Font); WinUpdateWindow(hwnd); return(*this); }
OWindow& OWindow::setBackColor(COLOR color) { pparms.Back = color; WinSetPresParam(hwnd, PP_BACKGROUNDCOLOR, sizeof(COLOR), &pparms.Back); WinUpdateWindow(hwnd); return(*this); }
/* * _NewWindow - create a new window */ unsigned _NewWindow( char *name, ... ) { LPWDATA w; MENUITEM menus; HWND hwnd,frame,temp; char str[80]; int x1,x2,y1,y2; ULONG style; RECTL rcl; va_list al; _GetWindowNameAndCoords( name, str, &x1, &x2, &y1, &y2 ); style = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MINMAX | FCF_VERTSCROLL; frame = WinCreateStdWindow( _MainWindow, WS_VISIBLE | WS_CLIPSIBLINGS, &style, _ClassName, str, 0, NULL, 0, &hwnd ); if( frame == 0 ) return( FALSE ); WinSetOwner( hwnd, _MainWindow ); va_start( al, name ); w = _AnotherWindowData( hwnd, al ); w->frame = frame; w->text_color = CLR_WHITE; w->background_color = CLR_BLACK; WinSendMsg( frame, WM_SETICON, MPFROMLONG( WinQuerySysPointer( HWND_DESKTOP, SPTR_APPICON, TRUE ) ), 0 ); WinSetWindowBits( WinWindowFromID( w->frame, FID_VERTSCROLL ), QWL_STYLE, SBS_AUTOTRACK, SBS_AUTOTRACK ); _CreateFont( w ); _PositionScrollThumb( w ); WinQueryWindowRect( _MainWindow, &rcl ); WinSetWindowPos( frame, HWND_TOP, x1*w->xchar, (rcl.yTop - rcl.yBottom)-y1*w->ychar-y2*w->ychar, x2*w->xchar, y2*w->ychar, SWP_SIZE | SWP_MOVE | SWP_ZORDER ); menus.iPosition = _MainWindowData->window_count - 1; menus.afStyle = MIS_TEXT; menus.afAttribute = 0; menus.id = DID_WIND_STDIO + w->handles[0]; menus.hwndSubMenu = NULL; menus.hItem = 0; if ( MIT_ERROR == (BOOL)WinSendMsg( menuHandle, ( ULONG )MM_INSERTITEM, MPFROMP( &menus ), MPFROMP( str ) ) ) abort(); temp = WinWindowFromID( frame, FID_SYSMENU ); WinSendMsg( temp, MM_QUERYITEM, MPFROM2SHORT(SC_SYSMENU, TRUE), MPFROMP((PSZ)&menus) ); WinSendMsg( menus.hwndSubMenu, MM_DELETEITEM, MPFROM2SHORT( SC_CLOSE, TRUE ), 0 ); WinUpdateWindow( hwnd ); WinSetFocus( HWND_DESKTOP, hwnd ); return( TRUE ); } /* _NewWindow */
MRESULT MainVertScroll(HWND hwnd, /* handle to the main client window */ MPARAM mp2) { LONG sVscrollInc; switch (SHORT2FROMMP (mp2)) { case SB_LINEUP: sVscrollInc = -1 ; break ; case SB_LINEDOWN: sVscrollInc = 1 ; break ; case SB_PAGEUP: sVscrollInc = min (-1, -cyClient / cyChar) ; break ; case SB_PAGEDOWN: sVscrollInc = max (1, cyClient / cyChar) ; break ; case SB_SLIDERTRACK: sVscrollInc = SHORT1FROMMP (mp2) - sVscrollPos; break ; default: sVscrollInc = 0; break ; } sVscrollInc = max (-sVscrollPos, min (sVscrollInc, sVscrollMax - sVscrollPos)) ; if (sVscrollInc != 0) { sVscrollPos += sVscrollInc ; WinScrollWindow ((HWND)hwnd, 0, (cyChar * sVscrollInc), (PRECTL)NULL, (PRECTL)NULL, (HRGN)NULL, (PRECTL)NULL, SW_INVALIDATERGN); WinSendMsg (hwndVscroll, SBM_SETPOS, MPFROMSHORT (sVscrollPos), MPVOID) ; WinUpdateWindow (hwnd) ; } return (MRFROMLONG(0)); }
void info_wait(int id) { POINTL pt; if (id) load_string(id, szWait, sizeof(szWait)); else szWait[0] = '\0'; if (hwnd_status) { WinInvalidateRect(hwnd_status, (PRECTL)NULL, TRUE); WinUpdateWindow(hwnd_status); } /* find out if cursor over hwnd_bmp */ if (!WinQueryPointerPos(HWND_DESKTOP, &pt)) return; if (hwnd_bmp == WinWindowFromPoint(HWND_DESKTOP, &pt, TRUE)) WinSendMsg(hwnd_bmp, WM_MOUSEMOVE, MPFROM2SHORT(pt.x, pt.y), (MPARAM)0); }
// // Here is a sample subclass function. // MRESULT APIENTRY SubClassFunc( HWND hWnd, ULONG Message, MPARAM wParam, MPARAM lParam) { PluginInstance *This = GetInstance(hWnd); switch(Message) { case WM_REALIZEPALETTE: WinInvalidateRect(hWnd, 0, TRUE); WinUpdateWindow(hWnd); return 0; break; case WM_PAINT: { RECTL rcl; WinQueryWindowRect( This->hWnd, &rcl ); pprintf( szPPR, "Rect (hmf %x) : ( %d, %d ) - ( %d, %d )\n\r", This->hmf, rcl.xLeft, rcl.yBottom, rcl.xRight, rcl.yTop ); WinInvalidateRect(hWnd, 0, TRUE); RECTL invalidRect; WinBeginPaint( hWnd, This->hps, &invalidRect ); /* draw using common drawing routine */ Draw( This, This->hps, FALSE, TRUE ); WinEndPaint( This->hps ); return (MRESULT)0; } break; default: break; } return ((PFNWP)This->lpfnOldWndProc)( hWnd, Message, wParam, lParam ); }
/* gsview menu commands */ int gsview_command(int command) { switch (command) { case IDM_NEXTHOME: case IDM_NEXT: case IDM_NEXTSKIP: case IDM_REDISPLAY: case IDM_PREVHOME: case IDM_PREVSKIP: case IDM_PREV: case IDM_GOBACK: case IDM_GOFWD: case IDM_MAGPLUS: case IDM_MAGMINUS: case IDM_FITWIN: case IDM_ZOOM: case IDM_FULLSCREEN: /* These don't close the full screen window */ break; default: gsview_fullscreen_end(); } switch (command) { case IDM_FULLSCREEN: gsview_fullscreen(); return 0; case IDM_OPEN: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } gsview_display(); return 0; case IDM_LASTFILE1: case IDM_LASTFILE2: case IDM_LASTFILE3: case IDM_LASTFILE4: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } make_cwd(last_files[command-IDM_LASTFILE1]); gsview_displayfile(last_files[command-IDM_LASTFILE1]); return 0; case IDM_CLOSE: /* doesn't unload DLL */ /* close file */ if (gsdll.open && (gsdll.state != GS_UNINIT)) { PSFILE *tpsfile; if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } tpsfile = (PSFILE *)malloc(sizeof(PSFILE)); if (tpsfile == NULL) return 0; memset((char *)tpsfile, 0, sizeof(PSFILE)); pending.psfile = tpsfile; pending.now = TRUE; if (psfile.name[0] && psfile.dsc==(CDSC *)NULL) pending.abort = TRUE; } else { /* DLL isn't loaded */ if (psfile.file) dfclose(); /* just to make sure */ psfile_free(&psfile); post_img_message(WM_GSTITLE, 0); info_wait(IDS_NOWAIT); } return 0; case IDM_CLOSE_DONE: if (selectname[0] != '\0') { /* pending IDM_SELECT */ PSFILE *tpsfile; tpsfile = gsview_openfile(selectname); if (tpsfile) { psfile = *tpsfile; free(tpsfile); } selectname[0] = '\0'; post_img_message(WM_GSTITLE, 0); info_wait(IDS_NOWAIT); } return 0; case IDM_NEXTHOME: #ifdef UNIX set_scroll(-1, 0); #else #ifdef _Windows PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L); #else WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP)); #endif #endif /* fall thru */ case IDM_NEXT: if (not_open()) return 0; gs_page_skip(1); return 0; case IDM_NEXTSKIP: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(page_skip); return 0; case IDM_REDISPLAY: if (dfchanged()) { PSFILE *tpsfile; if (dfchanged() < 0) { gs_addmess("File has been deleted\n"); gsview_command(IDM_CLOSE); pending.unload = TRUE; pending.now = FALSE; return 0; } if (pending.psfile) tpsfile = pending.psfile; /* new file, old file deleted */ else tpsfile = gsview_openfile(psfile.name); if (tpsfile) { tpsfile->pagenum = psfile.pagenum; request_mutex(); pending.psfile = tpsfile; if ( gsdll.hmodule && (psfile.dsc==(CDSC *)NULL) && (gsdll.state != GS_IDLE) ) /* don't know where we are so close and reopen */ pending.abort = TRUE; pending.now = TRUE; release_mutex(); } } if (not_open()) return 0; if (psfile.dsc==(CDSC *)NULL) { /* don't know where we are so close and reopen */ if (gsdll.state != GS_IDLE) { if (!pending.psfile) { pending.psfile = (PSFILE *)malloc(sizeof(PSFILE)); if (pending.psfile) *pending.psfile = psfile; } pending.psfile->pagenum = pending.pagenum = 1; pending.abort = TRUE; pending.now = TRUE; } } else { pending.pagenum = -1; /* default page number is current page */ if (psfile.dsc->page_order == CDSC_SPECIAL) pending.pagenum = 1; /* restart */ } gsview_unzoom(); pending.now = TRUE; return 0; case IDM_PREVHOME: #ifdef UNIX set_scroll(-1, 0); #else #ifdef _Windows PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L); #else WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP)); #endif #endif /* fall thru */ case IDM_PREV: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(-1); return 0; case IDM_PREVSKIP: if (not_dsc()) return 0; if (order_is_special()) return 0; gs_page_skip(-page_skip); return 0; case IDM_GOTO: if (not_dsc()) return 0; if (order_is_special()) return 0; if (psfile.dsc->page_count == 0) { gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER); return 0; } nHelpTopic = IDS_TOPICGOTO; { int pagenum; pagenum = psfile.pagenum; if (get_page(&pagenum, FALSE, FALSE)) { gsview_goto_page(pagenum); } } return 0; case IDM_GOBACK: if (not_dsc()) return 0; if (order_is_special()) return 0; history_back(); return 0; case IDM_GOFWD: if (not_open()) return 0; if (psfile.dsc == (CDSC *)NULL) gsview_command(IDM_NEXT); else history_forward(); return 0; case IDM_INFO: show_info(); return 0; case IDM_SELECT: if (pending.psfile) { play_sound(SOUND_BUSY); return 0; } gsview_select(); return 0; #ifndef VIEWONLY case IDM_PRINT: case IDM_PRINTTOFILE: case IDM_CONVERTFILE: if (psfile.name[0] == '\0') gsview_select(); if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (dfreopen() != 0) return 0; if (command == IDM_PRINTTOFILE) option.print_to_file = TRUE; if (psfile.name[0] != '\0') gsview_print(command == IDM_CONVERTFILE); dfclose(); return 0; case IDM_SPOOL: gsview_spool((char *)NULL, (char *)NULL); return 0; case IDM_SAVEAS: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); if (psfile.name[0] != '\0') gsview_saveas(); return 0; case IDM_EXTRACT: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); if (order_is_special()) return 0; if (psfile.name[0] != '\0') gsview_extract(); return 0; case IDM_PSTOEDIT: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } if (psfile.name[0] == '\0') gsview_select(); (void)order_is_special(); /* warn, but allow it anyway */ if (dfreopen() != 0) return 0; if (psfile.name[0] != '\0') gsview_pstoedit(); dfclose(); return 0; case IDM_TEXTEXTRACT: if (psfile.name[0] == '\0') gsview_select(); if (psfile.name[0] != '\0') gsview_text_extract(); return 0; case IDM_TEXTEXTRACT_SLOW: gsview_text_extract_slow(); return 0; case IDM_TEXTFIND: gsview_text_find(); return 0; case IDM_TEXTFINDNEXT: gsview_text_findnext(); return 0; case IDM_COPYCLIP: copy_clipboard(); return 0; case IDM_PASTETO: paste_to_file(); return 0; case IDM_CONVERT: clip_convert(); return 0; case IDM_MEASURE: if (gsdll.state == GS_BUSY) { play_sound(SOUND_BUSY); return 0; } measure_show(); return 0; #endif /* !VIEWONLY */ case IDM_GSMESS: gs_showmess(); /* show messages from Ghostscript */ return 0; case IDM_EXIT: if (print_count) { /* Still busy printing. Warn user. */ TCHAR buf[MAXSTR]; load_string(IDS_BUSYPRINTING, buf, sizeof(buf)/sizeof(TCHAR)-1); if (message_box(buf, MB_OKCANCEL) != IDOK) return 0; } post_img_message(WM_CLOSE, 0); return 0; case IDM_CFG: /* Easy configure */ config_wizard(TRUE); return 0; case IDM_GSCOMMAND: /* Advanced configure */ if (install_gsdll() && gsdll.open) pending.unload = TRUE; return 0; case IDM_UNITPT: case IDM_UNITMM: case IDM_UNITINCH: gsview_unit(command); return 0; case IDM_UNITFINE: option.unitfine = !option.unitfine; check_menu_item(IDM_UNITMENU, IDM_UNITFINE, option.unitfine); return 0; case IDM_LANGMENU+1: case IDM_LANGMENU+2: case IDM_LANGMENU+3: case IDM_LANGMENU+4: case IDM_LANGMENU+5: case IDM_LANGMENU+6: case IDM_LANGMENU+7: case IDM_LANGMENU+8: case IDM_LANGMENU+9: case IDM_LANGMENU+10: case IDM_LANGMENU+11: case IDM_LANGMENU+12: case IDM_LANGMENU+13: case IDM_LANGMENU+14: case IDM_LANGMENU+15: case IDM_LANGMENU+16: case IDM_LANGMENU+17: case IDM_LANGMENU+18: case IDM_LANGMENU+19: gsview_language(command); return 0; case IDM_SAFER: option.safer = !option.safer; check_menu_item(IDM_OPTIONMENU, IDM_SAFER, option.safer); return 0; case IDM_SAVEDIR: option.save_dir = !option.save_dir; check_menu_item(IDM_OPTIONMENU, IDM_SAVEDIR, option.save_dir); return 0; case IDM_BUTTONSHOW: option.button_show = !option.button_show; check_menu_item(IDM_OPTIONMENU, IDM_BUTTONSHOW, option.button_show); show_buttons(); return 0; case IDM_FITPAGE: option.fit_page = !option.fit_page; check_menu_item(IDM_OPTIONMENU, IDM_FITPAGE, option.fit_page); /* should cause WM_SIZE message to be sent */ return 0; case IDM_PSTOTEXTDIS: case IDM_PSTOTEXTNORM: case IDM_PSTOTEXTCORK: check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, FALSE); option.pstotext = command - IDM_PSTOTEXTMENU - 1; check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, TRUE); return 0; case IDM_AUTOREDISPLAY: option.redisplay = !option.redisplay; check_menu_item(IDM_OPTIONMENU, IDM_AUTOREDISPLAY, option.redisplay); return 0; case IDM_EPSFCLIP: option.epsf_clip = !option.epsf_clip; check_menu_item(IDM_OPTIONMENU, IDM_EPSFCLIP, option.epsf_clip); gs_resize(); return 0; case IDM_EPSFWARN: option.epsf_warn = !option.epsf_warn; check_menu_item(IDM_OPTIONMENU, IDM_EPSFWARN, option.epsf_warn); return 0; case IDM_IGNOREDSC: option.ignore_dsc = !option.ignore_dsc; check_menu_item(IDM_OPTIONMENU, IDM_IGNOREDSC, option.ignore_dsc); if (psfile.name[0]) { if (option.redisplay) gsview_displayfile(psfile.name); else gsview_selectfile(psfile.name); } return 0; case IDM_SHOWBBOX: option.show_bbox = !option.show_bbox; check_menu_item(IDM_OPTIONMENU, IDM_SHOWBBOX, option.show_bbox); #ifdef UNIX gtk_widget_draw(img, NULL); #else #ifdef _Windows PostMessage(hwndimg, WM_GSSYNC, 0, 0L); #else if (!WinInvalidateRect(hwnd_bmp, (PRECTL)NULL, TRUE)) error_message("error invalidating rect"); if (!WinUpdateWindow(hwnd_bmp)) error_message("error updating window"); #endif #endif return 0; #ifndef VIEWONLY case IDM_PSTOEPS: if (not_open()) return 0; if (psfile.name[0] != '\0') { if (dfreopen() != 0) return 0; ps_to_eps(); dfclose(); } return 0; case IDM_MAKEEPSI: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_interchange(FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPST4: case IDM_MAKEEPST6U: case IDM_MAKEEPST6P: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_tiff(command, FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPSW: if ( (option.orientation == IDM_PORTRAIT) || (option.auto_orientation == TRUE) ) { char epsname[MAXSTR]; epsname[0] = '\0'; if (dfreopen() != 0) return 0; if (!get_filename(epsname, TRUE, FILTER_EPS, 0, IDS_TOPICPREVIEW)) { dfclose(); return 0; } image_lock(view.img); make_eps_metafile(FALSE, epsname); image_unlock(view.img); dfclose(); } else gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0); return 0; case IDM_MAKEEPSU: if (dfreopen() != 0) return 0; make_eps_user(); dfclose(); return 0; case IDM_EXTRACTPS: case IDM_EXTRACTPRE: if (dfreopen() != 0) return 0; extract_doseps(command); dfclose(); return 0; #endif case IDM_SETTINGS: write_profile(); return 0; case IDM_SAVESETTINGS: option.settings = !option.settings; check_menu_item(IDM_OPTIONMENU, IDM_SAVESETTINGS, option.settings); { char buf[MAXSTR]; PROFILE *prf = profile_open(szIniFile); sprintf(buf, "%d", (int)option.settings); profile_write_string(prf, INISECTION, "SaveSettings", buf); profile_close(prf); } return 0; case IDM_SOUNDS: change_sounds(); return 0; case IDM_AUTOORIENT: case IDM_PORTRAIT: case IDM_LANDSCAPE: case IDM_UPSIDEDOWN: case IDM_SEASCAPE: case IDM_SWAPLANDSCAPE: gsview_orientation(command); return 0; case IDM_DSC_OFF: case IDM_DSC_ERROR: case IDM_DSC_WARN: case IDM_DSC_INFO: check_menu_item(IDM_DSCMENU, option.dsc_warn, FALSE); option.dsc_warn = command; check_menu_item(IDM_DSCMENU, option.dsc_warn, TRUE); return 0; case IDM_ZOOM: /* called indirectly from Right Mouse Button */ if (not_dsc()) { zoom = FALSE; return 0; } if (order_is_special()) { zoom = FALSE; return 0; } if (! ((gsdll.state == GS_PAGE) || (gsdll.state == GS_IDLE)) ) { zoom = FALSE; gserror(IDS_NOZOOM, NULL, MB_ICONEXCLAMATION, SOUND_ERROR); return 0; } gs_resize(); pending.pagenum = -1; /* default page number is current page */ pending.now = TRUE; return 0; case IDM_MAGPLUS: gs_magnify((float)1.2); return 0; case IDM_MAGMINUS: gs_magnify((float)0.8333); return 0; case IDM_FITWIN: /* fit media to size of current window */ gsview_fitwin(); return 0; case IDM_DISPLAYSETTINGS: display_settings(); return 0; case IDM_MEDIAROTATE: option.media_rotate = !option.media_rotate; check_menu_item(IDM_MEDIAMENU, IDM_MEDIAROTATE, option.media_rotate); zoom = FALSE; gs_resize(); return 0; case IDM_11x17: case IDM_A3: case IDM_A4: case IDM_A5: case IDM_B4: case IDM_B5: case IDM_LEDGER: case IDM_LEGAL: case IDM_LETTER: case IDM_NOTE: case IDM_USERSIZE: case IDM_USERSIZE1: case IDM_USERSIZE2: case IDM_USERSIZE3: case IDM_USERSIZE4: case IDM_USERSIZE5: case IDM_USERSIZE6: case IDM_USERSIZE7: case IDM_USERSIZE8: case IDM_USERSIZE9: case IDM_USERSIZE10: case IDM_USERSIZE11: case IDM_USERSIZE12: case IDM_USERSIZE13: if (command == IDM_USERSIZE) if (!gsview_usersize()) return 0; gsview_media(command); return 0; case IDM_HELPCONTENT: #ifdef UNIX nHelpTopic = IDS_TOPICROOT; get_help(); #else #ifdef _Windows #ifdef USE_HTMLHELP nHelpTopic = IDS_TOPICROOT; get_help(); #else WinHelp(hwndimg,szHelpName,HELP_CONTENTS,(DWORD)NULL); #endif #else WinSendMsg(hwnd_help, HM_HELP_CONTENTS, 0L, 0L); #endif #endif return 0; case IDM_HELPSEARCH: #ifdef UNIX gs_addmess("IDM_HELPSEARCH: not implemented\n"); #else #ifdef _Windows #ifdef USE_HTMLHELP HtmlHelp(hwndimg,szHelpName,HH_DISPLAY_INDEX, (DWORD)TEXT("")); gs_addmessf("HtmlHelp: %s HH_DISPLAY_INDEX\n", szHelpName); #else WinHelp(hwndimg,szHelpName,HELP_PARTIALKEY,(DWORD)""); #endif #else WinSendMsg(hwnd_help, HM_HELP_INDEX, 0L, 0L); #endif #endif return 0; case IDM_HELPKEYS: nHelpTopic = IDS_TOPICKEYS; get_help(); return 0; case IDM_ABOUT: show_about(); return 0; case IDM_REGISTER: registration_nag(); return 0; } return 0; }
/*------------------------------------------------------------------------*/ MRESULT EXPENTRY CanvasWndproc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) { HPS hps; RECTL rcl; SHORT sVscrollInc; /* Vertical scrollbar incr val */ SHORT sHscrollInc; /* Horizontal scrollbar incr val */ switch (msg) { case WM_CREATE: view.hwndVscroll = WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT), FID_VERTSCROLL); view.hwndHscroll = WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT), FID_HORZSCROLL); view.iZoom = ZOOM_NORMAL; view.hwndClient = hwnd; return 0; case WM_SIZE: view.cxCanvas = (LONG)SHORT1FROMMP (mp2); view.cyCanvas = (LONG)SHORT2FROMMP (mp2); CanvScrollBar(pwiCanv, TRUE); return 0; case WM_CHAR: if (SHORT1FROMMP(mp1) & KC_KEYUP ) return 0; if (SHORT1FROMMP(mp1) & KC_INVALIDCHAR ) return 0; if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) { switch (SHORT2FROMMP(mp2)) { case VK_ESC: return KeybEsc(); /* see drwmain */ case VK_PAGEUP: case VK_PAGEDOWN: return WinSendMsg(view.hwndVscroll,msg,mp1,mp2); } } return (MRESULT)0; case WM_PAINT: hps = WinBeginPaint(hwnd,(HPS)0,NULL); WinQueryWindowRect(hwnd, &rcl); WinFillRect(hps,&rcl,CLR_DARKGRAY); WinEndPaint(hps); return 0; /*========================Vertical=Scrolling================================*/ case WM_VSCROLL: switch (SHORT2FROMMP (mp2)) { case SB_LINEUP: sVscrollInc = -pwiCanv->fattrs.lMaxBaselineExt; break; case SB_LINEDOWN: sVscrollInc = pwiCanv->fattrs.lMaxBaselineExt; break; case SB_PAGEUP: sVscrollInc = -view.cyCanvas; break; case SB_PAGEDOWN: sVscrollInc = view.cyCanvas; break; case SB_SLIDERPOSITION: sVscrollInc = SHORT1FROMMP (mp2) - view.sVscrollPos; break; default: sVscrollInc = 0; break; } sVscrollInc = max(-view.sVscrollPos, min(sVscrollInc,view.sVscrollMax - view.sVscrollPos)); if ( sVscrollInc != 0 ) { view.sVscrollPos += sVscrollInc; WinScrollWindow (hwnd,0,sVscrollInc,(PRECTL)NULL, (PRECTL)NULL,(HRGN)NULLHANDLE, (PRECTL)NULL,SW_INVALIDATERGN | SW_SCROLLCHILDREN ); WinSendMsg (view.hwndVscroll, SBM_SETPOS, MPFROMSHORT (view.sVscrollPos), NULL); WinUpdateWindow (hwnd); } return 0; /*========================Horizontal=Scrolling==============================*/ case WM_HSCROLL: switch(SHORT2FROMMP (mp2)) { case SB_LINELEFT: sHscrollInc = -pwiCanv->fattrs.lAveCharWidth; break; case SB_LINERIGHT: sHscrollInc = pwiCanv->fattrs.lAveCharWidth; break; case SB_PAGELEFT: sHscrollInc = -view.cxCanvas; break; case SB_PAGERIGHT: sHscrollInc = view.cxCanvas; break; case SB_SLIDERPOSITION: sHscrollInc = SHORT1FROMMP (mp2) - view.sHscrollPos; break; default: sHscrollInc = 0; break; } sHscrollInc = max ( -view.sHscrollPos, min (sHscrollInc, view.sHscrollMax - view.sHscrollPos)); if ( sHscrollInc !=0) { view.sHscrollPos += sHscrollInc; WinScrollWindow(hwnd,-sHscrollInc,0L, (PRECTL)NULL,(PRECTL)NULL, (HRGN)NULLHANDLE,(PRECTL)NULL, SW_INVALIDATERGN | SW_SCROLLCHILDREN); WinSendMsg (view.hwndHscroll, SBM_SETPOS, MPFROMSHORT (view.sHscrollPos), NULL); WinUpdateWindow (hwnd); } return 0; } return WinDefWindowProc (hwnd ,msg,mp1,mp2); }
// // Here is a sample subclass function. // MRESULT APIENTRY SubClassFunc( HWND hWnd, ULONG Message, MPARAM wParam, MPARAM lParam) { PluginInstance *This = GetInstance(hWnd); switch(Message) { case WM_REALIZEPALETTE: WinInvalidateRect(hWnd, 0, TRUE); WinUpdateWindow(hWnd); return 0; break; case WM_TIMER: { if ((ULONG)wParam == kTimerId) { /* get window size */ RECTL rect; WinQueryWindowRect(hWnd, &rect); /* draw updated clock */ ULONG saveID = GpiSavePS(This->hps); if (This->pClock->Timer(This->hps, &rect)) WinInvalidateRect(hWnd, NULL, TRUE); GpiRestorePS(This->hps, saveID); } } return (MRESULT)0; break; case WM_PAINT: { /* invalidate the whole window */ WinInvalidateRect(hWnd, NULL, TRUE); /* get PS associated with window and set to PU_TWIPS coordinates */ RECTL invalidRect; WinBeginPaint(hWnd, This->hps, &invalidRect); /* get window size */ RECTL rect; WinQueryWindowRect(hWnd, &rect); // set onscreen flag - always true BOOL OnScreen = TRUE; if (OnScreen) { HRGN hrgnUsed; This->pClock->Size(rect, &hrgnUsed); } // draw background WinFillRect(This->hps, &rect, CLR_BACKGROUND); // draw the clock ULONG saveID = GpiSavePS(This->hps); This->pClock->Draw(This->hps, &rect, OnScreen, This->Transparency); GpiRestorePS(This->hps, saveID); WinEndPaint(This->hps); // start the timer for the next draw if (! This->fTimer) { WinStartTimer(WinQueryAnchorBlock(hWnd), hWnd, kTimerId, kTimerFrequency); This->fTimer = TRUE; } } return (MRESULT)0; break; default: break; } return ((PFNWP)This->lpfnOldWndProc)( hWnd, Message, wParam, lParam); }
MRESULT EXPENTRY MLECustomProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) { SHORT sScrollBarFirst; SHORT sScrollBarLast; static SHORT sScrollBarRange; USHORT idVScroll; USHORT idHScroll; static int iFirstVScroll=0; static int iFirstHScroll=0; static HWND hwndHScroll; static HWND hwndVScroll; MRESULT mres; IPT ipt; //Insertion point IPT iptLineStart; //First insertion point for a line IPT iptTotalLineLength; //Total lenght of a line of text IPT iptCursorToEndLength; //Length from cursor to end of line. static long lCurrentLine; static long lCurrentColumn; int iRes; static BOOL bEnterKeyDown; LONG lColor; switch(msg) { case MLM_SETFONT: FontPalProc(); break; case MLM_SETBACKCOLOR: WinDlgBox(HWND_DESKTOP, hwnd, ColorChgDlgProc, NULLHANDLE, IDD_COLORCHANGE, NULL); //Reshow color palette ColorPalProc(); //If background color is changed, let message fall through if(glColorChgAction==COLORCHANGE_BACKGROUND) { //Get color of text. lColor=LONGFROMMR(WinSendMsg(hwndMLE, MLM_QUERYTEXTCOLOR, MPVOID,MPVOID)); if(lColor==mp1) { sprintf(buffer,"Text color and background color may not be the same."); WinMessageBox(HWND_DESKTOP, hwndClient, buffer,szAppName,0, MB_OK|MB_ICONEXCLAMATION|MB_MOVEABLE); return 0; } else { //Set color change flag so color is not changed again. glColorChgAction=COLORCHANGE_CANCEL; break; } } //If text color is changed, change text color and return if(glColorChgAction==COLORCHANGE_TEXT) { //Get color of background. lColor=LONGFROMMR(WinSendMsg(hwndMLE, MLM_QUERYBACKCOLOR, MPVOID,MPVOID)); if(lColor==mp1) { sprintf(buffer,"Text color and background color may not be the same."); WinMessageBox(HWND_DESKTOP, hwndClient, buffer,szAppName,0, MB_OK|MB_ICONEXCLAMATION|MB_MOVEABLE); return 0; } else { WinSendMsg(hwndMLE, MLM_SETTEXTCOLOR, mp1, MPVOID); //Set color change flag so color is not changed again. glColorChgAction=COLORCHANGE_CANCEL; return 0; } } //Handle cancel if(glColorChgAction==COLORCHANGE_CANCEL) return 0; break; //MLM_SETBACKCOLOR case WM_CHAR: //Set enter key flag down for autoindent. if(!(CHARMSG(&msg)->fs & KC_KEYUP)) { switch(CHARMSG(&msg)->vkey) { case VK_ENTER: case VK_NEWLINE: bEnterKeyDown=TRUE; break; } } //Let autosave know there was a modification if(CHARMSG(&msg)->fs & KC_KEYUP) { iRes=AutoSaveModProc(AUTOSAVEMOD_INCREMENT); } //Handle key status changes - caps lock, num lock, insert if(CHARMSG(&msg)->fs & KC_KEYUP) if(CHARMSG(&msg)->fs & KC_VIRTUALKEY) switch(CHARMSG(&msg)->vkey) { case VK_PAGEUP: break; case VK_UP: break; case VK_ENTER: case VK_NEWLINE: if(bEnterKeyDown) { if(bUseAutoIndent) iRes=AutoIndentProc(); } bEnterKeyDown=FALSE; break; case VK_INSERT: case VK_CAPSLOCK: case VK_NUMLOCK: if (bStatusBarOn) UpdateKeyStatus(); //in status.c break; } case WM_BUTTON1CLICK: if (bStatusBarOn) { //Update line display in status window ipt=LONGFROMMR(WinSendMsg(hwndMLE, MLM_QUERYSEL, MPFROMSHORT(MLFQS_CURSORSEL), MPVOID)); lGlobalCurrentLine=LONGFROMMR(WinSendMsg(hwndMLE, MLM_LINEFROMCHAR, MPFROMLONG(ipt), MPVOID))+1; //Get start of current line iptLineStart=LONGFROMMR(WinSendMsg(hwndMLE, MLM_CHARFROMLINE, MPFROMLONG(-1L), //MPFROMLONG(lGlobalCurrentLine), MPVOID)); //Get total length of line iptTotalLineLength=LONGFROMMR(WinSendMsg(hwndMLE, MLM_QUERYLINELENGTH, MPFROMLONG(iptLineStart), MPVOID)); //Get length from cursor to end of line iptCursorToEndLength=LONGFROMMR(WinSendMsg(hwndMLE, MLM_QUERYLINELENGTH, MPFROMLONG(-1L), MPVOID)); //Calculate current column lGlobalCurrentColumn=iptTotalLineLength-iptCursorToEndLength+1; //Update status window if line or column has changed if ( (lCurrentColumn!=lGlobalCurrentColumn) || (lCurrentLine!=lGlobalCurrentLine) ) UpdateStatusWindow(); //store curren line and column lCurrentColumn=lGlobalCurrentColumn; lCurrentLine=lGlobalCurrentLine; } //end if bStatusBarOn break; ///////////////////////////////////////////////////// //Real-time vertical scrolling case WM_VSCROLL: if(iFirstVScroll==0) { //Get scroll bar ID idVScroll=SHORT1FROMMP(mp1); //Get handle of scroll vertical scroll bar. hwndVScroll=WinWindowFromID(hwndMLE,idVScroll); //Get scroll bar range. mres=WinSendMsg(hwndVScroll, SBM_QUERYRANGE, MPVOID,MPVOID); sScrollBarFirst=SHORT1FROMMR(mres); sScrollBarLast=SHORT2FROMMR(mres); sScrollBarRange=sScrollBarLast-sScrollBarFirst; iFirstVScroll=1; } if (SHORT2FROMMP(mp2)==SB_ENDSCROLL) break; switch (SHORT2FROMMP(mp2)) { case SB_SLIDERTRACK: //Send message to fool MLE into thinking scroll has ended WinSendMsg(hwndMLE, WM_VSCROLL, mp1, MPFROMLONG( MAKELONG( SHORT1FROMMP(mp2), SB_SLIDERPOSITION ) )); WinSendMsg(hwndMLE, WM_VSCROLL, mp1, MPFROMLONG( MAKELONG( SHORT1FROMMP(mp2), SB_ENDSCROLL ) )); break; } //Invalidate scroll paint area. WinInvalidateRect(hwndVScroll,NULL,TRUE); //Force update of scroll bar WinUpdateWindow(hwndVScroll); break;//WM_VSCROLL ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// //Real-time horizontal scrolling. case WM_HSCROLL: if(iFirstHScroll==0) { //Get scroll bar ID idHScroll=SHORT1FROMMP(mp1); //Get handle of scroll vertical scroll bar. hwndHScroll=WinWindowFromID(hwndMLE,idHScroll); iFirstHScroll=1; } if (SHORT2FROMMP(mp2)==SB_ENDSCROLL) break; switch (SHORT2FROMMP(mp2)) { case SB_SLIDERTRACK: //Send message to fool MLE into thinking scroll has ended WinSendMsg(hwndMLE, WM_HSCROLL, mp1, MPFROMLONG( MAKELONG( SHORT1FROMMP(mp2), SB_SLIDERPOSITION ) )); WinSendMsg(hwndMLE, WM_HSCROLL, mp1, MPFROMLONG( MAKELONG( SHORT1FROMMP(mp2), SB_ENDSCROLL ) )); break; } //Invalidate scroll paint area. WinInvalidateRect(hwndHScroll,NULL,TRUE); //Force update of scroll bar WinUpdateWindow(hwndHScroll); break; //WM_HSCROLL ///////////////////////////////////////////////////// } return MLEDefProc(hwnd,msg,mp1,mp2); }
void SetSortColumn( HWND hwnd, ULONG ulCmd) { HWND hMenu; HWND hCnr; ULONG ulCol; ULONG ulSortCol; ULONG ulID; MENUITEM mi; hMenu = WinWindowFromID( hwnd, FID_MENU); WinSendMsg( hMenu, MM_QUERYITEM, MPFROM2SHORT( IDM_SORT, FALSE), (MP)&mi); hMenu = mi.hwndSubMenu; if (ulCmd >= IDM_SORTFIRST && ulCmd < IDM_SORTFIRST + eCNTCOLS) ulCol = QueryColumnIndex( ulCmd - IDM_SORTFIRST); else ulCol = ulCmd; ulSortCol = QueryColumnIndex( CAM_SORTCOL); // every change requires us to uncheck the currently checked // menu item in order to get the menu to repaint properly; ulID = IDM_SORTFIRST + (ciX[ulSortCol]->flags & CIF_NDXMASK); WinSendMsg( hMenu, MM_SETITEMATTR, MPFROM2SHORT( ulID, FALSE), MPFROM2SHORT( MIA_CHECKED, 0)); // if the selected column is the current sort column, change the // sort direction; otherwise, remove the sort indicator from the // previous sort column, save the new one, and set the direction // to ascending if (ulSortCol == ulCol) sSortSense = -sSortSense; else { *(strchr( ciX[ulSortCol]->pszTitle, 0) - 1) = ' '; if (ulCol != (ULONG)-1) { ciX[ulSortCol]->flags &= ~CIF_SORTCOL; ulSortCol = ulCol; sSortSense = 1; ciX[ulSortCol]->flags |= CIF_SORTCOL; } } ulID = IDM_SORTFIRST + (ciX[ulSortCol]->flags & CIF_NDXMASK); // set the customized checkmark - note: the high order word // of mp1 has to be true for this to work correctly WinSendMsg( hMenu, MM_SETITEMCHECKMARK, MPFROM2SHORT( ulID, TRUE), (MP)(sSortSense > 0 ? hbmAsc : hbmDesc)); // check the appropriate menu item WinSendMsg( hMenu, MM_SETITEMATTR, MPFROM2SHORT( ulID, FALSE), MPFROM2SHORT( MIA_CHECKED, MIA_CHECKED)); // replace the last character of the title (which is a space) // with the sort indicator; it's done this way to keep the column // title from shifting position as the indicator is added & removed *(strchr( ciX[ulSortCol]->pszTitle, 0) - 1) = (sSortSense > 0 ? chAsc : chDesc); // sort the records using the sort function for this column; // this will cause the entire window to be repainted so we // don't need to do anything to get the column titles updated // unless we're in demo mode where there are no records to sort hCnr = WinWindowFromID( hwnd, FID_CLIENT); if (GetCamPtr()) WinSendMsg( hCnr, CM_SORTRECORD, (MP)ciX[ulSortCol]->pvSort, 0); else { WinInvalidateRect( hCnr, 0, TRUE); WinUpdateWindow( hCnr); } return; }
MRESULT PMfrCommands (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2) { /* These are the routnes that handle the commands issued by the FRACTINT for PM menus. In most cases, they call another support routine to handle or schedule the event requested by the user. */ SHORT sCommand = SHORT1FROMMP(mp1); switch (sCommand) { case IDM_GO: /* fire up the subtask */ cp.fContinueCalc = TRUE ; if (npNewParms.fNewParms) { CopyParmsToBase(); /* GetMemoryBitmap(); */ SetSwitchEntry (hwnd, szTitleBar, GetFractalName(cp.iFractType) ); } cp.sSubAction = SUB_ACT_CALC; /* we want a Calculation */ DosSemClear (&cp.ulSemTrigger) ; /* release the subthread */ sStatus = STATUS_WORKING ; /* WinInvalidateRect (hwnd, NULL, FALSE) ; */ UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt); EnableMenuItem (hwnd, IDM_GO, FALSE) ; EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ; /* WinStartTimer (hab, hwnd, ID_TIMER, 5000); */ return 0 ; case IDM_PAN: /* Pan selected. Pan to where the cross hairs were */ PanNewCenter(hwnd); fGoodPan = FALSE; return 0; case IDM_ZIN_WIN: /* Zoom to the Window selected. */ EraseZoomBox(hwnd); ZoomNewWindow(hwnd, TRUE); /* zoom in */ fGoodZoom = FALSE; return 0; case IDM_ZOUT_WIN: /* Zoom to the Window selected. */ EraseZoomBox(hwnd); ZoomNewWindow(hwnd, FALSE); /* zoom out */ fGoodZoom = FALSE; return 0; case IDM_FREEZE_HALT: if (sStatus == STATUS_WORKING) { /* schedule the subthread to find a stopping place */ cp.fContinueCalc = FALSE ; EnableMenuItem (hwnd, IDM_FREEZE_HALT, FALSE) ; } if (sStatus == STATUS_READY) { /* we Freeze to play with parms repeatedly */ /* make a copy to play with. We will keep */ /* working with only this copy */ InitNewParms(NULL); /* now change state */ sStatus = STATUS_FROZEN; EnableMenuItem (hwnd, IDM_FREEZE_HALT, FALSE); } return 0 ; case IDM_ABOUT: /* send up the About box */ WinDlgBox (HWND_DESKTOP, hwnd, AboutDlgProc, (HMODULE) 0, IDD_ABOUT, NULL) ; return 0 ; case IDM_NEW_FRACTAL: /* * send up the Select Fractal Type box. * On OK return, schedule the new parameters. * Handle the special cases needing files or other data * as part of exiting the initial dialog box. */ if (WinDlgBox (HWND_DESKTOP, hwnd, SelFractalDlgProc, (HMODULE) 0, IDD_SET_FRACTTYPE, NULL) ) ScheduleNewParms (hwnd); return 0 ; case IDM_SET_PARAMS: /* * send up the Set Paramters box. * On OK return, schedule the new parameters. */ if (WinDlgBox (HWND_DESKTOP, hwnd, SetParametersDlgProc, (HMODULE) 0, IDD_SET_PARAMS, NULL) ) ScheduleNewParms (hwnd); return 0 ; case IDM_SET_OPTIONS: /* * send up the Set Options box. * On OK return, schedule the new parameters. */ if (WinDlgBox (HWND_DESKTOP, hwnd, SetOptionsDlgProc, (HMODULE) 0, IDD_SET_OPTIONS, NULL) ) ScheduleNewParms (hwnd); return 0 ; case IDM_SET_IMAGE: /* * send up the Set Image box. * On OK return, schedule the new parameters. */ if (WinDlgBox (HWND_DESKTOP, hwnd, SetImageDlgProc, (HMODULE) 0, IDD_SET_IMAGE, NULL) ) ScheduleNewParms (hwnd); return 0 ; case IDM_SET_PALETTE: /* * send up the Set Palette box. * Return is not checked because effects are immediate */ WinDlgBox (HWND_DESKTOP, hwnd, SetPaletteDlgProc, (HMODULE) 0, IDD_SET_PALETTE, NULL) ; return 0 ; case IDM_ZIN_PICK: case IDM_ZOUT_PICK: /* * Send up the Zoom Value dialog box. * On OK return, schedule the new parameters. */ if ( WinDlgBox (HWND_DESKTOP, hwnd, ZoomValueDlgProc, (HMODULE) 0, IDD_NUMBER_PICK, MPFROMP((PVOID) &COMMANDMSG(&msg)->cmd)) ) ScheduleNewParms (hwnd); return 0 ; case IDM_ZIN_2: case IDM_ZIN_5: case IDM_ZIN_10: /* * Zoom in by fixed value. * Schedule the new parameters. */ InitNewParms(NULL); CalcZoomValues(&npNewParms, (double) (sCommand), TRUE ); npNewParms.fNewParms = TRUE; ScheduleNewParms(hwnd); return 0; case IDM_ZOUT_2: case IDM_ZOUT_5: case IDM_ZOUT_10: /* * Zoom out by fixed value. * Schedule the new parameters. */ InitNewParms(NULL); CalcZoomValues(&npNewParms, (double) (sCommand - 10), FALSE ); npNewParms.fNewParms = TRUE; ScheduleNewParms(hwnd); return 0; case IDM_SET_EXTENTS: /* * Send up the Set Extents dialog box. * On OK return, schedule the new parameters. */ if ( WinDlgBox (HWND_DESKTOP, hwnd, SetExtentsDlgProc, (HMODULE) 0, IDD_SET_EXTENTS, NULL) ) ScheduleNewParms (hwnd); return 0; case IDM_SET_SWAP: /* swap Mandel for Julia or vice versa. Handle it as a parm change */ InitNewParms(NULL); if (fractalspecific[npNewParms.iFractType].tojulia != NOFRACTAL && npNewParms.param[0] == 0.0 && npNewParms.param[1] == 0.0) { /* switch to corresponding Julia set */ npNewParms.iFractType = fractalspecific[npNewParms.iFractType].tojulia; npNewParms.param[0] = npNewParms.XCenter; npNewParms.param[1] = npNewParms.YCenter; npNewParms.mxXL = fractalspecific[npNewParms.iFractType].xmin; npNewParms.mxXR = fractalspecific[npNewParms.iFractType].xmax; npNewParms.mxYB = fractalspecific[npNewParms.iFractType].ymin; npNewParms.mxYT = fractalspecific[npNewParms.iFractType].ymax; } else if (fractalspecific[npNewParms.iFractType].tomandel != NOFRACTAL) { /* switch to corresponding Mandel set */ npNewParms.iFractType = fractalspecific[npNewParms.iFractType].tomandel; npNewParms.param[0] = 0.0; npNewParms.param[1] = 0.0; npNewParms.mxXL = fractalspecific[npNewParms.iFractType].xmin; npNewParms.mxXR = fractalspecific[npNewParms.iFractType].xmax; npNewParms.mxYB = fractalspecific[npNewParms.iFractType].ymin; npNewParms.mxYT = fractalspecific[npNewParms.iFractType].ymax; } npNewParms.fNewParms = TRUE; ScheduleNewParms (hwnd); return 0; case IDM_SET_RESET: /* copy the work copy of the parms back from the set used by the calculation engine. This resets any dicking around done with the dialogs. Note: this is only active during FREEZE mode. */ CopyParmsToNew(); return 0; case IDM_HELP_INTRO: /* basic Introductory Help */ SimpleHelp(hab, hwnd, szTitleBar, (HMODULE) 0, IDT_TEXT, IDT_HELP_INTRO); return 0; case IDM_HELP_FRACTTYPE: /* Fractal list Help */ SimpleHelp(hab, hwnd, szTitleBar, (HMODULE) 0, IDT_TEXT, IDT_HELP_TYPES); return 0; case IDM_HELP_OPERATE: /* Menu Help */ SimpleHelp(hab, hwnd, szTitleBar, (HMODULE) 0, IDT_TEXT, IDT_HELP_OPERATE); return 0; case IDM_PRINT_FILE: /* Send up the Print Where Dialog. On OK return, fire up the subtask */ if ( WinDlgBox(HWND_DESKTOP, hwnd, PrintOptionsDlgProc, (HMODULE) 0, IDD_PRINT, NULL) ) { /* fire up the subtask */ cp.sSubAction = SUB_ACT_PRINT; /* we want a Print */ cp.fContinueCalc = TRUE; DosSemClear (&cp.ulSemTrigger) ; /* release the subthread */ sStatus = STATUS_WORKING ; UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt); EnableMenuItem (hwnd, IDM_GO, FALSE) ; EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ; cp.fSuppressPaint = TRUE; WinInvalidateRect(hwnd, NULL, FALSE); } return 0 ; case IDM_READ_FILE: /* Send up the Load/Save Format Dialog to find out the format we will read. Then send up the generic Open File dialog. On OK return, fire up the subtask */ { DLF dlf; HFILE hfDummy; PSZ pszExt; if ( WinDlgBox(HWND_DESKTOP, hwnd, LoadSaveFmtDlgProc, (HMODULE) 0, IDD_LOADSAVE_TYPE, szLoadWhatFmt) ) { FileFmtExt (&pszExt); SetupDLF (&dlf, DLG_OPENDLG, &hfDummy, pszExt, szTitleBar, szOpenTitle, szOpenHelp); if (TDF_OLDOPEN == DlgFile(hwnd, &dlf) ) { /* close the dummy file handle */ DosClose(hfDummy); /* fire up the subtask */ cp.sSubAction = SUB_ACT_LOAD; /* we want a Load */ cp.sSubFunction = cp.sLastLoadSaveType; _fstrcpy(cp.szFileName, dlf.szOpenFile); cp.fContinueCalc = TRUE; DosSemClear (&cp.ulSemTrigger) ; /* release the subthread */ sStatus = STATUS_WORKING ; UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt); EnableMenuItem (hwnd, IDM_GO, FALSE) ; EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ; cp.fSuppressPaint = TRUE; WinInvalidateRect(hwnd, NULL, FALSE); } } return 0 ; } case IDM_SAVE_FILE: /* Send up the Load/Save Format Dialog to find out the format we will be writing. Then send up the generic Save File dialog. On OK return, fire up the subtask */ { DLF dlf; HFILE hfDummy; PSZ pszExt; if ( WinDlgBox(HWND_DESKTOP, hwnd, LoadSaveFmtDlgProc, (HMODULE) 0, IDD_LOADSAVE_TYPE, szSaveWhatFmt) ) { FileFmtExt (&pszExt); SetupDLF (&dlf, DLG_SAVEDLG, &hfDummy, pszExt, szTitleBar, szOpenTitle, szOpenHelp); _fstrcpy(dlf.szOpenFile, cp.szFileName); if (TDF_NOSAVE != DlgFile(hwnd, &dlf) ) { /* close the dummy file handle */ DosClose(hfDummy); /* and delete the dummy file */ DosDelete(dlf.szOpenFile, 0); /* fire up the subtask */ cp.sSubAction = SUB_ACT_SAVE; /* we want a Save */ cp.sSubFunction = cp.sLastLoadSaveType; _fstrcpy(cp.szFileName, dlf.szOpenFile); cp.fContinueCalc = TRUE; DosSemClear (&cp.ulSemTrigger) ; /* release the subthread */ sStatus = STATUS_WORKING ; UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt); EnableMenuItem (hwnd, IDM_GO, FALSE) ; EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ; cp.fSuppressPaint = TRUE; WinInvalidateRect(hwnd, NULL, FALSE); } } return 0 ; } case IDM_READ_COLORMAP: /* Send up the generic Open File dialog. On OK return, read in the file via subroutine. */ { DLF dlf; HFILE hfDummy; SetupDLF (&dlf, DLG_OPENDLG, &hfDummy, "\\*.map", szTitleBar, szColorMapTitle, szColorMapHelp); if (TDF_OLDOPEN == DlgFile(hwnd, &dlf) ) { /* close the dummy file handle */ DosClose(hfDummy); /* throw up the hour-glass */ WinSetCapture(HWND_DESKTOP, hwnd); WinSetPointer(HWND_DESKTOP, hptrWait); /* read it in */ LoadColorMap(dlf.szOpenFile); /* now clean up */ WinSetPointer(HWND_DESKTOP, hptrArrow); WinSetCapture(HWND_DESKTOP, (HWND) NULL); } } return 0; case IDM_WRITE_COLORMAP: /* Send up the generic Save File dialog. On OK return, write the file via subroutine */ { DLF dlf; HFILE hfDummy; SetupDLF (&dlf, DLG_SAVEDLG, &hfDummy, "\\*.map", szTitleBar, szColorMapTitle, szColorMapHelp); if (TDF_NOSAVE != DlgFile(hwnd, &dlf) ) { /* close the dummy file handle */ DosClose(hfDummy); /* throw up the hour-glass */ WinSetCapture(HWND_DESKTOP, hwnd); WinSetPointer(HWND_DESKTOP, hptrWait); /* write it out */ SaveColorMap(dlf.szOpenFile); /* now clean up */ WinSetPointer(HWND_DESKTOP, hptrArrow); WinSetCapture(HWND_DESKTOP, (HWND) NULL); } } return 0; case IDM_CLEAR_CLPB: /* clear the current contents of the clipboard */ WinOpenClipbrd (hab); WinEmptyClipbrd (hab); WinCloseClipbrd (hab); return 0; case IDM_PASTE: { /* paste from the clipboard into us */ USHORT usClipBrdInfo; if ( WinQueryClipbrdFmtInfo(hab, CF_BITMAP, &usClipBrdInfo) ) { /* we have a bitmap to fetch */ /* draw the curtain over the display */ cp.fSuppressPaint = TRUE; WinInvalidateRect(hwnd, NULL, FALSE); WinUpdateWindow(hwnd); /* throw up the hour-glass */ WinSetCapture(HWND_DESKTOP, hwnd); WinSetPointer(HWND_DESKTOP, hptrWait); /* fetch the bitmap */ PMfrFetchClipbrdBmp(hab); /* now clean up */ WinSetPointer(HWND_DESKTOP, hptrArrow); WinSetCapture(HWND_DESKTOP, (HWND) NULL); /* and schedule redrawing the window */ SetSwitchEntry (hwnd, szTitleBar, GetFractalName(cp.iFractType) ); cp.fSuppressPaint = FALSE; WinInvalidateRect(hwnd, NULL, FALSE); } } return 0; case IDM_COPY_BMP: { /* copy to the clipboard from us */ /* throw up the hour-glass */ WinSetCapture(HWND_DESKTOP, hwnd); WinSetPointer(HWND_DESKTOP, hptrWait); /* write the bitmap */ PMfrWriteClipbrdBmp(hab); /* now clean up */ WinSetPointer(HWND_DESKTOP, hptrArrow); WinSetCapture(HWND_DESKTOP, (HWND) NULL); } return 0; } return 0; }
int main (void) { SHORT ix, iy; SHORT iwidth, idepth; SWP swp; ULONG ulResult; int iRes; static CHAR szClientClass[]="ZIN"; static ULONG flFrameFlags= FCF_TITLEBAR | FCF_SYSMENU | FCF_TASKLIST | FCF_ICON | FCF_SHELLPOSITION| FCF_BORDER | FCF_NOBYTEALIGN; hab=WinInitialize(0); hmq=WinCreateMsgQueue(hab, 0); //Register processing class WinRegisterClass( hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0); //Create Window hwndFrame=WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, &flFrameFlags, szClientClass, NULL, 0L, 0, //Module handle for resources ID_RESOURCE, //ID of resources &hwndClient); //Size window WinSetWindowPos( hwndFrame, HWND_TOP, 0, 0, 640, 480, SWP_SIZE ); //Center window iwidth = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ); idepth = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ); WinQueryWindowPos( hwndFrame, (PSWP)&swp ); ix = (SHORT)(( iwidth - swp.cx ) / 2); iy = (SHORT)(( idepth - swp.cy ) / 2); WinSetWindowPos( hwndFrame, HWND_TOP, ix, iy, 0, 0, SWP_MOVE ); //Set focus to edit window. WinSetFocus(HWND_DESKTOP,hwndClient); //Load application title WinLoadString(hab, 0, ID_APPNAME, LITTLEBUF, (PSZ) szAppName); //Set title of frame. WinSetWindowText(hwndFrame, (PSZ) szAppName); //Show the window WinShowWindow(hwndFrame,TRUE); //Get source directory. GetCurrentDirectory(szSourceDir); //Load first message FIRSTMSG: usResponse=MsgBox(ID_FIRSTMSG, ID_APPNAME, MB_OKCANCEL); WinUpdateWindow(hwndClient); if (usResponse==MBID_OK) { //Show readme.txt file ulResult=WinDlgBox(HWND_DESKTOP, hwndClient, ReadmeDlgProc, NULLHANDLE, IDD_README, NULL); if (ulResult==FALSE) { //The installation has been cancelled. usResponse=MsgBox(ID_CANCELINSTALL, ID_APPNAME, MB_OK); goto END_INSTALL; } ulResult=WinDlgBox(HWND_DESKTOP, hwndClient, GetDirDlgProc, NULLHANDLE, IDD_GETDIR, NULL); if (ulResult==FALSE) goto FIRSTMSG; //Update the window WinUpdateWindow(hwndClient); //Load status dialog LoadStatusDlg(); //Make sure all files exist iRes=CheckFiles(szSourceDir); if (iRes!=0) { DestroyStatusDlg(); usResponse=MsgBox(ID_FILENOTFOUND, ID_APPNAME, MB_OK); goto END_INSTALL; } //Copy the files iRes=CopyFiles(szSourceDir, szInstallDir); if (iRes!=0) { DestroyStatusDlg(); usResponse=MsgBox(ID_FILESNOTCOPIED, ID_APPNAME, MB_OK); goto END_INSTALL; } iRes=PatchZed(szInstallDir); if (iRes!=0) { DestroyStatusDlg(); usResponse=MsgBox(ID_PATCHFAILED, ID_APPNAME, MB_OK); goto END_INSTALL; } iRes=CreateObject(szInstallDir); if (iRes!=0) usResponse=MsgBox(ID_CANTCREATEOBJECT, ID_APPNAME, MB_OK); //unload status window DestroyStatusDlg(); //Update the window WinUpdateWindow(hwndClient); //Success usResponse=MsgBox(ID_SUCCESS, ID_APPNAME, MB_OK); goto END_INSTALL; //Main message loop while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0)) WinDispatchMsg(hab, &qmsg); } if (usResponse==MBID_CANCEL) { //The installation has been cancelled. usResponse=MsgBox(ID_CANCELINSTALL, ID_APPNAME, MB_OK); } END_INSTALL: //Cleanup WinDestroyWindow(hwndFrame); WinDestroyMsgQueue(hmq); WinTerminate(hab); //End return 0; }
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static HAB hab ; static HWND hwndMenu ; static INT iCurrentRep = IDM_10 ; static INT iStatus = STATUS_READY ; static LONG lCalcRep, lRepAmts [] = { 10, 100, 1000, 10000, 100000 } ; static ULONG ulElapsedTime ; double A ; LONG lRep ; switch (msg) { case WM_CREATE: hab = WinQueryAnchorBlock (hwnd) ; hwndMenu = WinWindowFromID ( WinQueryWindow (hwnd, QW_PARENT), FID_MENU) ; return 0 ; case WM_COMMAND: switch (COMMANDMSG(&msg)->cmd) { case IDM_10: case IDM_100: case IDM_1000: case IDM_10000: case IDM_100000: WinCheckMenuItem (hwndMenu, iCurrentRep, FALSE) ; iCurrentRep = COMMANDMSG(&msg)->cmd ; WinCheckMenuItem (hwndMenu, iCurrentRep, TRUE) ; return 0 ; case IDM_START: WinEnableMenuItem (hwndMenu, IDM_START, FALSE) ; WinEnableMenuItem (hwndMenu, IDM_ABORT, TRUE) ; iStatus = STATUS_WORKING ; WinInvalidateRect (hwnd, NULL, FALSE) ; WinUpdateWindow (hwnd) ; WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (HWND_DESKTOP, SPTR_WAIT, FALSE)) ; if (WinQuerySysValue (HWND_DESKTOP, SV_MOUSEPRESENT) == 0) WinShowPointer (HWND_DESKTOP, TRUE) ; lCalcRep = lRepAmts [iCurrentRep - IDM_10] ; ulElapsedTime = WinGetCurrentTime (hab) ; for (A = 1.0, lRep = 0 ; lRep < lCalcRep ; lRep++) A = Savage (A) ; ulElapsedTime = WinGetCurrentTime (hab) - ulElapsedTime ; if (WinQuerySysValue (HWND_DESKTOP, SV_MOUSEPRESENT) == 0) WinShowPointer (HWND_DESKTOP, FALSE) ; WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (HWND_DESKTOP, SPTR_ARROW, FALSE)) ; iStatus = STATUS_DONE ; WinInvalidateRect (hwnd, NULL, FALSE) ; WinUpdateWindow (hwnd) ; WinEnableMenuItem (hwndMenu, IDM_START, TRUE) ; WinEnableMenuItem (hwndMenu, IDM_ABORT, FALSE) ; return 0 ; case IDM_ABORT: // Not much we can do here return 0 ; } break ; case WM_PAINT: PaintWindow (hwnd, iStatus, lCalcRep, ulElapsedTime) ; return 0 ; } return WinDefWindowProc (hwnd, msg, mp1, mp2) ; }
_WCRTLINK int __InitDefaultWin() { //================================== ULONG style; RECTL rcl; HWND menhdl; HWND submenu; MENUITEM *menudesc; MENUITEM menus; SWP swp; _ClassName = WatcomClass; _AnchorBlock = WinInitialize( 0 ); if( _AnchorBlock == 0 ) return( 0 ); hMessageQueue = WinCreateMsgQueue( _AnchorBlock, 0 ); if( hMessageQueue == 0 ) return( 0 ); if( !WinRegisterClass( _AnchorBlock, _ClassName, (PFNWP)_MainDriver, CS_SIZEREDRAW, 0 ) ) { return( 0 ); } _InitMainWindowData( 0 ); style = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MINMAX | FCF_SHELLPOSITION | FCF_TASKLIST; _MainFrameWindow = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE | WS_CLIPCHILDREN, &style, _ClassName, "", 0, NULL, 0, &ClientWindow ); if( _MainFrameWindow == 0 ) return( 0 ); WinSendMsg( _MainFrameWindow, WM_SETICON, MPFROMLONG( WinQuerySysPointer( HWND_DESKTOP, SPTR_APPICON, TRUE ) ), 0 ); WinQueryWindowRect( _MainWindow, &rcl ); WinSetWindowPos( _MainFrameWindow, HWND_TOP, rcl.xLeft, rcl.yBottom, rcl.xLeft - rcl.xRight, rcl.yTop - rcl.yBottom, SWP_SHOW | SWP_SIZE | SWP_MOVE | SWP_MAXIMIZE ); _InitFunctionPointers(); _MainWindow = ClientWindow; WinUpdateWindow( _MainWindow ); menudesc = &menus; menhdl = WinCreateMenu( _MainFrameWindow, NULL ); WinSetWindowBits( menhdl, QWL_STYLE, MS_ACTIONBAR, MS_ACTIONBAR ); submenu = WinCreateMenu( menhdl, NULL ); menudesc->afStyle = MIS_TEXT; menudesc->afAttribute = 0; menudesc->hwndSubMenu = NULL; menudesc->hItem = 0; menudesc->iPosition = 0; menudesc->id = DID_FILE_SAVE; if ( MIT_ERROR == (BOOL)WinSendMsg( submenu, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "Save As..." ) ) ) abort(); menudesc->iPosition = 1; menudesc->id = DID_FILE_CLEAR; if ( MIT_ERROR == (BOOL)WinSendMsg( submenu, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "Set Lines Between Clears..." ) ) ) abort(); menudesc->afStyle = MIS_SEPARATOR; menudesc->iPosition = 2; menudesc->id = 0; if ( MIT_ERROR == (BOOL)WinSendMsg( submenu, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "Exit" ) ) ) abort(); menudesc->afStyle = MIS_TEXT; menudesc->iPosition = 3; menudesc->id = DID_FILE_EXIT; if ( MIT_ERROR == (BOOL)WinSendMsg( submenu, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "Exit" ) ) ) abort(); menudesc->iPosition = 0; menudesc->id = DID_MAIN_FILE; menudesc->hwndSubMenu = submenu; menudesc->afStyle = MIS_TEXT | MIS_SUBMENU; if ( MIT_ERROR == (BOOL)WinSendMsg( menhdl, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "~File" ) ) ) abort(); submenu = WinCreateMenu( menhdl, NULL ); menudesc->afStyle = MIS_TEXT; menudesc->iPosition = 0; menudesc->id = DID_EDIT_CLEAR; menudesc->hwndSubMenu = NULL; if ( MIT_ERROR == (BOOL)WinSendMsg( submenu, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "Clear" ) ) ) abort(); menudesc->iPosition = 1; menudesc->id = DID_EDIT_COPY; if ( MIT_ERROR == (BOOL)WinSendMsg( submenu, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "Copy" ) ) ) abort(); menudesc->iPosition = 1; menudesc->id = DID_MAIN_EDIT; menudesc->hwndSubMenu = submenu; menudesc->afStyle = MIS_SUBMENU; if ( MIT_ERROR == (BOOL)WinSendMsg( menhdl, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "~Edit" ) ) ) abort(); submenu = WinCreateMenu( menhdl, NULL ); _SetWinMenuHandle( submenu ); menudesc->iPosition = 2; menudesc->afAttribute = 0; menudesc->id = DID_MAIN_WIND; menudesc->hwndSubMenu = submenu; menudesc->afStyle = MIS_SUBMENU; if ( MIT_ERROR == (BOOL)WinSendMsg( menhdl, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "~Windows" ) ) ) abort(); submenu = WinCreateMenu( menhdl, NULL ); menudesc->afStyle = MIS_TEXT; menudesc->iPosition = 0; menudesc->id = DID_HELP_ABOUT; menudesc->hwndSubMenu = NULL; if ( MIT_ERROR == (BOOL)WinSendMsg( submenu, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "About" ) ) ) abort(); menudesc->iPosition = 3; menudesc->id = DID_MAIN_HELP; menudesc->hwndSubMenu = submenu; menudesc->afStyle = MIS_SUBMENU; if ( MIT_ERROR == (BOOL)WinSendMsg( menhdl, ( ULONG )MM_INSERTITEM, MPFROMP( menudesc ), MPFROMP( "~Help" ) ) ) abort(); WinSendMsg( _MainFrameWindow, ( ULONG )WM_UPDATEFRAME, 0, 0 ); _NewWindow( "Standard IO", 0,1,2,-1 ); WinUpdateWindow( _MainFrameWindow ); WinQueryWindowPos( _MainWindow, &swp ); swp.fl |= SWP_MAXIMIZE; WinSetWindowPos( _MainWindow, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy, SWP_MAXIMIZE | SWP_ACTIVATE | SWP_MOVE | SWP_SHOW | SWP_SIZE ); return( 1 ); }
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static INT aiPuzzle[NUMROWS][NUMCOLS], iBlankRow, iBlankCol, cxSquare, cySquare ; CHAR szNum[10] ; HPS hps ; HWND hwndFrame ; INT iRow, iCol, iMouseRow, iMouseCol, i ; POINTL ptl ; RECTL rcl, rclInvalid, rclIntersect ; SIZEL sizl ; switch (msg) { case WM_CREATE: // Calculate square size in pixels hps = WinGetPS (hwnd) ; sizl.cx = sizl.cy = 0 ; GpiSetPS (hps, &sizl, PU_LOENGLISH) ; ptl.x = SQUARESIZE ; ptl.y = SQUARESIZE ; GpiConvert (hps, CVTC_PAGE, CVTC_DEVICE, 1L, &ptl) ; WinReleasePS (hps) ; cxSquare = ptl.x ; cySquare = ptl.y ; // Calculate client window size and position rcl.xLeft = (WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN) - NUMCOLS * cxSquare) / 2 ; rcl.yBottom = (WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN) - NUMROWS * cySquare) / 2 ; rcl.xRight = rcl.xLeft + NUMCOLS * cxSquare ; rcl.yTop = rcl.yBottom + NUMROWS * cySquare ; // Set frame window position and size hwndFrame = WinQueryWindow (hwnd, QW_PARENT) ; WinCalcFrameRect (hwndFrame, &rcl, FALSE) ; WinSetWindowPos (hwndFrame, NULLHANDLE, rcl.xLeft, rcl.yBottom, rcl.xRight - rcl.xLeft, rcl.yTop - rcl.yBottom, SWP_MOVE | SWP_SIZE | SWP_ACTIVATE) ; // Initialize the aiPuzzle array WinSendMsg (hwnd, WM_COMMAND, MPFROMSHORT (IDM_NORMAL), NULL) ; return 0 ; case WM_PAINT: hps = WinBeginPaint (hwnd, NULLHANDLE, &rclInvalid) ; // Draw the squares for (iRow = NUMROWS - 1 ; iRow >= 0 ; iRow--) for (iCol = 0 ; iCol < NUMCOLS ; iCol++) { rcl.xLeft = cxSquare * iCol ; rcl.yBottom = cySquare * iRow ; rcl.xRight = rcl.xLeft + cxSquare ; rcl.yTop = rcl.yBottom + cySquare ; if (!WinIntersectRect (0, &rclIntersect, &rcl, &rclInvalid)) continue ; if (iRow == iBlankRow && iCol == iBlankCol) WinFillRect (hps, &rcl, CLR_BLACK) ; else { WinDrawBorder (hps, &rcl, 5, 5, CLR_PALEGRAY, CLR_DARKGRAY, DB_STANDARD | DB_INTERIOR) ; WinDrawBorder (hps, &rcl, 2, 2, CLR_BLACK, 0L, DB_STANDARD) ; sprintf (szNum, "%d", aiPuzzle[iRow][iCol]) ; WinDrawText (hps, -1, szNum, &rcl, CLR_WHITE, CLR_DARKGRAY, DT_CENTER | DT_VCENTER) ; } } WinEndPaint (hps) ; return 0 ; case WM_BUTTON1DOWN: iMouseCol = MOUSEMSG(&msg)->x / cxSquare ; iMouseRow = MOUSEMSG(&msg)->y / cySquare ; // Check if mouse was in valid area if ( iMouseRow < 0 || iMouseCol < 0 || iMouseRow >= NUMROWS || iMouseCol >= NUMCOLS || (iMouseRow != iBlankRow && iMouseCol != iBlankCol) || (iMouseRow == iBlankRow && iMouseCol == iBlankCol)) break ; // Move a row right or left if (iMouseRow == iBlankRow) { if (iMouseCol < iBlankCol) for (iCol = iBlankCol ; iCol > iMouseCol ; iCol--) aiPuzzle[iBlankRow][iCol] = aiPuzzle[iBlankRow][iCol - 1] ; else for (iCol = iBlankCol ; iCol < iMouseCol ; iCol++) aiPuzzle[iBlankRow][iCol] = aiPuzzle[iBlankRow][iCol + 1] ; } // Move a column up or down else { if (iMouseRow < iBlankRow) for (iRow = iBlankRow ; iRow > iMouseRow ; iRow--) aiPuzzle[iRow][iBlankCol] = aiPuzzle[iRow - 1][iBlankCol] ; else for (iRow = iBlankRow ; iRow < iMouseRow ; iRow++) aiPuzzle[iRow][iBlankCol] = aiPuzzle[iRow + 1][iBlankCol] ; } // Calculate invalid rectangle rcl.xLeft = cxSquare * min (iMouseCol, iBlankCol) ; rcl.yBottom = cySquare * min (iMouseRow, iBlankRow) ; rcl.xRight = cxSquare * (max (iMouseCol, iBlankCol) + 1) ; rcl.yTop = cySquare * (max (iMouseRow, iBlankRow) + 1) ; // Set new array and blank values iBlankRow = iMouseRow ; iBlankCol = iMouseCol ; aiPuzzle[iBlankRow][iBlankCol] = 0 ; // Invalidate rectangle WinInvalidateRect (hwnd, &rcl, FALSE) ; break ; case WM_CHAR: if (!(CHARMSG(&msg)->fs & KC_VIRTUALKEY) || CHARMSG(&msg)->fs & KC_KEYUP) return 0 ; // Mimic a WM_BUTTON1DOWN message iMouseCol = iBlankCol ; iMouseRow = iBlankRow ; switch (CHARMSG(&msg)->vkey) { case VK_LEFT: iMouseCol++ ; break ; case VK_RIGHT: iMouseCol-- ; break ; case VK_UP: iMouseRow-- ; break ; case VK_DOWN: iMouseRow++ ; break ; default: return 0 ; } WinSendMsg (hwnd, WM_BUTTON1DOWN, MPFROM2SHORT (iMouseCol * cxSquare, iMouseRow * cySquare), NULL) ; return 0 ; case WM_COMMAND: switch (COMMANDMSG(&msg)->cmd) { // Initialize aiPuzzle array case IDM_NORMAL: case IDM_INVERT: for (iRow = 0 ; iRow < NUMROWS ; iRow++) for (iCol = 0 ; iCol < NUMCOLS ; iCol++) aiPuzzle[iRow][iCol] = iCol + 1 + NUMCOLS * (NUMROWS - iRow - 1) ; if (COMMANDMSG(&msg)->cmd == IDM_INVERT) { aiPuzzle[0][NUMCOLS-2] = NUMCOLS * NUMROWS - 2 ; aiPuzzle[0][NUMCOLS-3] = NUMCOLS * NUMROWS - 1 ; } aiPuzzle[iBlankRow = 0][iBlankCol = NUMCOLS - 1] = 0 ; WinInvalidateRect (hwnd, NULL, FALSE) ; return 0 ; // Randomly scramble the squares case IDM_SCRAMBLE: WinSetPointer (HWND_DESKTOP, WinQuerySysPointer ( HWND_DESKTOP, SPTR_WAIT, FALSE)) ; srand ((int) WinGetCurrentTime (0)) ; for (i = 0 ; i < SCRAMBLEREP ; i++) { WinSendMsg (hwnd, WM_BUTTON1DOWN, MPFROM2SHORT (rand() % NUMCOLS * cxSquare, iBlankRow * cySquare), NULL) ; WinUpdateWindow (hwnd) ; WinSendMsg (hwnd, WM_BUTTON1DOWN, MPFROM2SHORT (iBlankCol * cxSquare, rand() % NUMROWS * cySquare), NULL) ; WinUpdateWindow (hwnd) ; } WinSetPointer (HWND_DESKTOP, WinQuerySysPointer ( HWND_DESKTOP, SPTR_ARROW, FALSE)); return 0 ; } break ; } return WinDefWindowProc (hwnd, msg, mp1, mp2) ; }