MRESULT EXPENTRY DriverWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) { CHAR szFile[CCHMAXPATH]; /* File HOlder */ FILEFINDBUF3 findbuf; /* File Find Buffer */ FONTMETRICS fm; /* Font Metrics Structure */ HDIR hDir = (HDIR)HDIR_CREATE; /* Directory Handle */ HPS hPS; /* Presentation Space Handle */ HWND hwndListBox; /* List Box Window Handle */ LISTBOXCDATA lbwcd; /* List Box Window Control Data */ POWNERITEM poi; /* Owner Item */ RECTL rcl; /* Client Window Rectangle */ ULONG ulFileCnt = 1UL; /* File Counter Holder */ register INT i, k, n; /* Loop Counter */ switch ( msg ) { /* Perform window initialization */ case WM_CREATE : hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE); WinSetPointer(HWND_DESKTOP, hptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE)); memset(&lbwcd, 0, sizeof(LISTBOXCDATA)); lbwcd.cb = sizeof(LISTBOXCDATA); lbwcd.ulVersion = LBV_110; lbwcd.vdata.lbcd1_1.flExtStyles = LSXS_CHECKBOX | LSXS_EDITABLE; hwndList1 = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE, 10L, 10L, 100L, 175L, hWnd, HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL); hwndListx = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE, 125L, 10L, 100L, 175L, hWnd, HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL); hwndList2 = WinCreateWindow(hWnd, "ListBoxWindow", "", WS_VISIBLE, 10L, 190L, 250L, 200L, hWnd, HWND_TOP, 1025UL, (PVOID)&lbwcd, (PVOID)NULL); WinSendMsg(hwndList1, LMXM_SETSOUNDEVENT, MPFROMLONG(LSND_SINGLECLICK), MPFROMP("ahooga.wav")); WinSendMsg(hwndListx, LMXM_SETSOUNDEVENT, MPFROMLONG(LSND_DOUBLECLICK), MPFROMP("flush.wav")); hwndListA = WinCreateWindow(hWnd, WC_LISTBOX, "", LS_OWNERDRAW | LS_HORZSCROLL | LS_MULTIPLESEL | WS_VISIBLE, 275L, 10L, 100L, 175L, hWnd, HWND_TOP, 1026UL, (PVOID)NULL, (PVOID)NULL); /* Sub-class the default window procedure with */ /* new one which will handle specific messages */ /* allowing better control over the sizing frame */ hwndListB = WinCreateWindow(hWnd, WC_LISTBOX, "", WS_VISIBLE | LS_EXTENDEDSEL, 275L, 190L, 250L, 200L, hWnd, HWND_TOP, 1027UL, (PVOID)NULL, (PVOID)NULL); for ( i = 0; i < 10; i++ ) { sprintf(szFile, "Item %04d Item %04d Item %04d", i, i, i); WinSendMsg(hwndListx, LM_INSERTITEM, MPFROMLONG(LIT_END), MPFROMP(szFile)); } n = (INT)WinSendMsg(hwndList2, LMX_CALCLINECOUNT, MPFROMLONG(175L), 0L); k = 0; WinSendMsg(hwndList2, LM_SETITEMHEIGHT, MPFROMLONG(36L), 0L); if ( !DosFindFirst("*.*", &hDir, FILE_NORMAL, (PVOID)&findbuf, sizeof(FILEFINDBUF3), &ulFileCnt, FIL_STANDARD) ) { do { WinSendMsg(hwndList2, LM_INSERTITEM, MPFROMLONG(LIT_SORTDESCENDING), MPFROMP(findbuf.achName)); WinSendMsg(hwndList1, LM_INSERTITEM, MPFROMLONG(LIT_SORTASCENDING), MPFROMP(findbuf.achName)); if ( ++k > n ) WinSendMsg(hwndList2, LM_SETTOPINDEX, MPFROMLONG(k - n), 0L); WinSendMsg(hwndListB, LM_INSERTITEM, MPFROMLONG(LIT_SORTDESCENDING), MPFROMP(findbuf.achName)); WinSendMsg(hwndListA, LM_INSERTITEM, MPFROMLONG(LIT_SORTASCENDING), MPFROMP(findbuf.achName)); } while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) ); DosFindClose(hDir); } break; case WM_BUTTON1DOWN : WinEnableWindowUpdate(hwndListA, FALSE); WinEnableWindowUpdate(hwndList1, FALSE); WinSendMsg(hwndListA, LM_DELETEALL, 0L, 0L); WinSendMsg(hwndList1, LM_DELETEALL, 0L, 0L); i = 0; if ( !DosFindFirst("*.*", &hDir, FILE_NORMAL, (PVOID)&findbuf, sizeof(FILEFINDBUF3), &ulFileCnt, FIL_STANDARD) ) { do { WinSendMsg(hwndListA, LM_INSERTITEM, MPFROMLONG(LIT_SORTASCENDING), MPFROMP(findbuf.achName)); WinSendMsg(hwndList1, LM_INSERTITEM, MPFROMLONG(LIT_SORTASCENDING), MPFROMP(findbuf.achName)); ++i; } while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) ); DosFindClose(hDir); } WinShowWindow(hwndListA, TRUE); WinShowWindow(hwndList1, TRUE); while ( i ) { if ( i % 2 ) { WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE)); WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE)); } --i; } break; case WM_CONTROL : switch ( SHORT2FROMMP(mp1) ) { /* Process double click on a List Box */ case LN_SELECT : switch ( SHORT1FROMMP(mp1) ) { case 1024UL : /* WinAlarm(HWND_DESKTOP, WA_NOTE); */ break; case 1027UL : /* WinAlarm(HWND_DESKTOP, WA_ERROR); */ break; } break; } break; case WM_MEASUREITEM : GpiQueryFontMetrics(hPS = WinGetPS(hWnd), sizeof(FONTMETRICS), &fm); WinReleasePS(hPS); return(MRFROMLONG(fm.lMaxBaselineExt)); /* Draw a list box item */ case WM_DRAWITEM : if ( SHORT1FROMMP(mp1) == 1024 ) hwndListBox = hwndList1; else if ( SHORT1FROMMP(mp1) == 1026 ) hwndListBox = hwndListA; /* Point to Owner Item information */ poi = (POWNERITEM)mp2; GpiCreateLogColorTable(poi->hps, 0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL); i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXTLENGTH, MPFROMLONG(poi->idItem), 0L)); i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXT, MPFROM2SHORT(poi->idItem, CCHMAXPATH), MPFROMP(szFile))); /* Check to see if item to be drawn or */ /* highlighted */ if ( poi->fsState != poi->fsStateOld ) { WinFillRect(poi->hps, &poi->rclItem, RGBCLR_DIALOGBACKGROUND); if ( poi->fsState ) WinDrawText(poi->hps, -1L, szFile, &poi->rclItem, RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER | DT_ERASERECT); /* Set item highlighting by inverting the items */ /* rectangle colour */ WinInvertRect(poi->hps, &poi->rclItem); if ( !poi->fsState ) WinDrawText(poi->hps, -1L, szFile, &poi->rclItem, RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER | DT_ERASERECT); poi->fsState = poi->fsStateOld = 0; } else { /* Item needs to be drawn, get item rectangle */ /* item position */ WinFillRect(poi->hps, &poi->rclItem, RGBCLR_DIALOGBACKGROUND); WinDrawText(poi->hps, -1L, szFile, &poi->rclItem, RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER | DT_ERASERECT); } return(MRFROMLONG(TRUE)); case WM_BUTTON1DBLCLK : i = 0; if ( !DosFindFirst("*.*", &hDir, FILE_NORMAL, (PVOID)&findbuf, sizeof(FILEFINDBUF3), &ulFileCnt, FIL_STANDARD) ) { do { ++i; } while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) ); DosFindClose(hDir); } while ( i ) { if ( i % 2 ) { WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE)); WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE)); } --i; } break; case WM_BUTTON2DOWN : for ( i = 0; i < 5; i++ ) WinSendMsg(hwndListx, LM_DELETEITEM, MPFROMSHORT(2), 0L); #if 0 WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(LIT_NONE), MPFROMLONG(TRUE)); i = LIT_FIRST; while ( (i = (INT)LONGFROMMR(WinSendMsg(hwndList1, LM_QUERYSELECTION, MPFROMLONG(i), 0L))) != LIT_NONE ) WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i), MPFROMLONG(FALSE)); #endif break; /* Erase background */ case WM_ERASEBACKGROUND : WinQueryWindowRect(hWnd, &rcl); WinFillRect((HPS)mp1, &rcl, SYSCLR_DIALOGBACKGROUND); break; /* Paint the main client window */ case WM_PAINT : WinSetPointer(HWND_DESKTOP, hptrWait); WinFillRect(hPS = WinBeginPaint(hWnd, (HPS)NULL, &rcl), &rcl, SYSCLR_DIALOGBACKGROUND); WinEndPaint(hPS); WinSetPointer(HWND_DESKTOP, hptrArrow); break; /* Close Down */ case WM_CLOSE : WinPostMsg(hWnd, WM_QUIT, 0L, 0L); break; case WM_DESTROY : WinDestroyPointer(hptrArrow); WinDestroyPointer(hptrWait); break; /* Default message processing */ default: return(WinDefWindowProc(hWnd, msg, mp1, mp2)); } return(0L); }
/*----------------------------------------------------------------------*/ SHORT DMLBLocateListboxItem( HWND hwnd, HWND RelHwnd, SHORT Y, SHORT Option ) /*----------------------------------------------------------------------*/ /* Parameters: */ /* hwnd Listbox of interest */ /* RelHwnd Window to which Y is relative to */ /* Y Y position of the pointer */ /* Option LLI_UNDER to return index of item under pointer, */ /* LLI_INSERTPOINT to index of item nearest insert point */ /*----------------------------------------------------------------------*/ /* Given a Y window coordinate, this function will calculate the item */ /* number of the listbox item at that position. The LLI_UNDER option */ /* will return the item directly under the pointer. The LLI_INSERTPOINT*/ /* option will return the item number *before* which an insertion should*/ /* be made (drop zones are calculated as the half-way points through */ /* each item). */ /*----------------------------------------------------------------------*/ { RECTL Rect; POINTL Points[2]; HPS hps; LONG VertSize; SHORT ItemNum; char ClassName[10]; /* Map coordinate from window it is relative to, to win of interst*/ Points[0].x = 0; Points[0].y = Y; WinMapWindowPoints(RelHwnd, hwnd, &(Points[0]), 1L); Y = Points[0].y; /* If this is actually a MultiColumn ListBox, we must find the */ /* real listbox which is the first column and use it for our */ /* location calculations. Since we only care about the Y */ /* coordinate we only need to look at the 1st column of the MCLB. */ WinQueryClassName(hwnd, sizeof(ClassName), ClassName); if (!strcmp("MCLBCls", ClassName)) hwnd = WinWindowFromID(hwnd, 1); /* Get handle of 1st column's listbox */ /* If this is an OWNERDRAW listbox, ask owner how big items are. */ VertSize = 0; if (WinQueryWindowULong(hwnd, QWL_STYLE) & LS_OWNERDRAW) VertSize = SHORT1FROMMR( // Take returned Height WinSendMsg(WinQueryWindow(hwnd, QW_OWNER), // Query owner of listbox WM_MEASUREITEM, // Ask owner the size MPFROMSHORT(WinQueryWindowUShort(hwnd, QWS_ID)), // Listbox ID MPFROMSHORT(0))); // First item if (VertSize == 0) { /* For a normal listbox, items are the size of the font. To */ /* determine the size we get the bounding box of a space. */ hps = WinGetPS(hwnd); GpiQueryTextBox(hps, 1L, " ", 2, Points); VertSize = Points[TXTBOX_TOPLEFT].y - Points[TXTBOX_BOTTOMLEFT].y; WinReleasePS(hps); } WinQueryWindowRect(hwnd, &Rect); Rect.yTop = Rect.yTop-2; /* Listbox frame is 2 pixels */ /* Calculate item number of item under the pointer */ ItemNum = (SHORT)WinSendMsg(hwnd, LM_QUERYTOPINDEX, 0L, 0L) + ((Rect.yTop-Y)/VertSize); /* Return item under pointer, or insertion point */ switch (Option) { case LLI_UNDER: return ItemNum; case LLI_INSERTPOINT: if (((Rect.yTop-Y) % VertSize) <= (VertSize / 2)) return ItemNum; return ItemNum+1; /* Note: May exceed num of items in list */ } }
void DoWaWEConfigureWindow(HWND hwndOwner) { SWP swpTemp, swpParent; POINTL ptlTemp; unsigned short usTabTextLength=0, usTabTextHeight=0; // The user wants to configure WaWE! // Save old config for Undo! memcpy(&WaWEUndoConfiguration, &WaWEConfiguration, sizeof(WaWEConfiguration)); // For this, we'll create a notebook window. // The first page of the notebook will contain the cache settings. // Later, it can have more notebook tabs, if required. #ifdef DEBUG_BUILD printf("[DoWaWEConfigureWindow] : Loading dialog from EXE...\n"); #endif hwndConfigDlg=WinLoadDlg(HWND_DESKTOP, hwndOwner, (PFNWP)ConfigDlgProc, NULL, DLG_CONFIGURATION, NULL); if (!hwndConfigDlg) { #ifdef DEBUG_BUILD printf("[DoWaWEConfigureWindow] : Could not load resource!\n"); #endif return; } #ifdef DEBUG_BUILD printf("[DoWaWEConfigureWindow] : Dialog loaded, others come...\n"); #endif // Query the handle of the notebook control hwndConfigNB = WinWindowFromID(hwndConfigDlg, NB_CONFIGURATION); // Now load and add the pages, one by one... hwndCacheNBP = WinLoadDlg(hwndConfigNB, hwndConfigNB, (PFNWP) fnCacheNotebookPage, NULL, DLG_CONFIGURATION_CACHE, NULL); hwndInterfaceNBP = WinLoadDlg(hwndConfigNB, hwndConfigNB, (PFNWP) fnInterfaceNotebookPage, NULL, DLG_CONFIGURATION_INTERFACE, NULL); // Save the size of one notebook page for later use. // (after adding, it will be resized, because of the AUDIOSIZE flag of notebook!) WinQueryWindowPos(hwndCacheNBP, &swpTemp); // Add pages to notebook: AddNotebookTab(hwndConfigNB, hwndInterfaceNBP, BKA_MAJOR, "Interface", "Interface settings", &(ulInterfaceNBPID), &usTabTextLength, &usTabTextHeight); AddNotebookTab(hwndConfigNB, hwndCacheNBP, BKA_MAJOR, "Cache", "Read-cache settings", &(ulCacheNBPID), &usTabTextLength, &usTabTextHeight); // The followings are discarder on Warp4, but makes things look better on Warp3: // Set notebook info field color (default is white... Yipe...) WinSendMsg(hwndConfigNB, BKM_SETNOTEBOOKCOLORS, MPFROMLONG(SYSCLR_FIELDBACKGROUND), MPFROMSHORT(BKA_BACKGROUNDPAGECOLORINDEX)); // Adjust tab size: WinSendMsg(hwndConfigNB, BKM_SETDIMENSIONS, MPFROM2SHORT(usTabTextLength + 10, (SHORT)((float)usTabTextHeight * 0.8)), MPFROMSHORT(BKA_MAJORTAB)); WinSendMsg(hwndConfigNB, BKM_SETDIMENSIONS, MPFROM2SHORT(0, 0), MPFROMSHORT(BKA_MINORTAB)); // Adjust controls and window size AdjustControls(swpTemp.cx, swpTemp.cy); // Position the window in the middle of its parent! WinQueryWindowPos(hwndOwner, &swpParent); ptlTemp.x = swpParent.x; ptlTemp.y = swpParent.y; WinMapWindowPoints(hwndOwner, HWND_DESKTOP, &ptlTemp, 1); swpParent.x = ptlTemp.x; swpParent.y = ptlTemp.y; WinQueryWindowPos(hwndConfigDlg, &swpTemp); swpTemp.x = (swpParent.cx-swpTemp.cx)/2 + swpParent.x; swpTemp.y = (swpParent.cy-swpTemp.cy)/2 + swpParent.y; WinSetWindowPos(hwndConfigDlg, HWND_TOP, swpTemp.x, swpTemp.y, 0, 0, SWP_MOVE); // Show window WinShowWindow(hwndConfigDlg, TRUE); WinSetFocus(HWND_DESKTOP, hwndConfigNB); #ifdef DEBUG_BUILD printf("[DoWaWEConfigureWindow] : Processing config window...\n"); #endif // Process messages WinProcessDlg(hwndConfigDlg); #ifdef DEBUG_BUILD printf("[DoWaWEConfigureWindow] : End of configuration!\n"); #endif // Now cleanup WinDestroyWindow(hwndConfigDlg); }
ULONG HEOptions(HWND hwnd) { HWND hwndDlg; ULONG TextFormat = (ULONG) WinSendMsg(hwndHMLE,HMLM_QUERYTEXTFORMAT,0L,0L); ULONG HanType = (ULONG) WinSendMsg(hwndHMLE,HMLM_QUERYHANTYPE,0L,0L); ULONG ulrc = ( ULONG ) WinSendMsg( hwndHMLE, HMLM_QUERYWRAP, 0, 0 ); //int old_eoltype = TextFormat; //int old_hantype = HanType; BOOL wordWrap = CHAR3FROMMP( ulrc ); BOOL wordProtect = CHAR4FROMMP( ulrc ); int wordWrapSize = SHORT1FROMMR( ulrc ); CHAR size[ 10 ]; hwndDlg = WinLoadDlg(HWND_DESKTOP,hwnd,&WinDefDlgProc,NULLHANDLE,IDD_OPTIONS,NULL); if (TextFormat==HMLE_EOL_CRLF) WinSendMsg(WinWindowFromID(hwndDlg,IDB_TF_CRLF),BM_SETCHECK,MPFROMLONG(1L),0L); else WinSendMsg(WinWindowFromID(hwndDlg,IDB_TF_LF),BM_SETCHECK,MPFROMLONG(1L),0L); if (HanType==HMLE_HAN_KS) WinSendMsg(WinWindowFromID(hwndDlg,IDB_HT_KS),BM_SETCHECK,MPFROMLONG(1L),0L); else WinSendMsg(WinWindowFromID(hwndDlg,IDB_HT_SY),BM_SETCHECK,MPFROMLONG(1L),0L); WinSendMsg( WinWindowFromID( hwndDlg, IDB_WORDWRAP ), BM_SETCHECK, MPFROMLONG( SHORT1FROMMR( wordWrap )), 0 ); _itoa( wordWrapSize, size, 10 ); WinSetWindowText( WinWindowFromID( hwndDlg, IDEF_WORDWRAP_SIZE ), size ); //WinSetFocus(HWND_DESKTOP,hwndDlg); ulrc = WinProcessDlg(hwndDlg); if (ulrc == DID_OK) { TextFormat = (ULONG) WinSendMsg(WinWindowFromID(hwndDlg,IDB_TF_CRLF),BM_QUERYCHECKINDEX,0L,0L); HanType = (ULONG) WinSendMsg(WinWindowFromID(hwndDlg,IDB_HT_KS),BM_QUERYCHECKINDEX,0L,0L); if (TextFormat == 1) { WinSendMsg(hwndHMLE,HMLM_SETTEXTFORMAT,MPFROMLONG(HMLE_EOL_CRLF),0L); WinPostMsg(hwndStatbar,STATBAR_USERM_SETEOLTYPE,MPFROMLONG(HMLE_EOL_CRLF),0L); } else { WinSendMsg(hwndHMLE,HMLM_SETTEXTFORMAT,MPFROMLONG(HMLE_EOL_LF),0L); WinPostMsg(hwndStatbar,STATBAR_USERM_SETEOLTYPE,MPFROMLONG(HMLE_EOL_LF),0L); } if (HanType == 1) { WinSendMsg(hwndHMLE,HMLM_SETHANTYPE,MPFROMLONG(HMLE_HAN_KS),0L); WinPostMsg(hwndStatbar,STATBAR_USERM_SETHANTYPE,MPFROMLONG(HMLE_HAN_KS),0L); } else { WinSendMsg(hwndHMLE,HMLM_SETHANTYPE,MPFROMLONG(HMLE_HAN_SY),0L); WinPostMsg(hwndStatbar,STATBAR_USERM_SETHANTYPE,MPFROMLONG(HMLE_HAN_SY),0L); } wordWrap = ( BOOL )WinSendDlgItemMsg( hwndDlg, IDB_WORDWRAP, BM_QUERYCHECK, 0, 0 ); WinQueryWindowText( WinWindowFromID( hwndDlg, IDEF_WORDWRAP_SIZE ), sizeof( size ), size ); wordWrapSize = atoi( size ); if(( wordWrapSize != 0 ) && ( wordWrapSize < MIN_WORDWRAP_SIZE )) wordWrapSize = MIN_WORDWRAP_SIZE; WinSendMsg( hwndHMLE, HMLM_SETWRAP, MPFROM2SHORT( wordWrap, wordProtect ), MPFROMSHORT( wordWrapSize )); } WinDestroyWindow(hwndDlg); return 0L; }
/* ConfigureDlgProc This is the dialog procedure for the module configuration dialog. The dialog contains a check box for enabling/disabling the module and two push buttons ("OK" and "Cancel") to close/cancel the dialog. Since version 1.2, it contains a slider to set the animation speed; if you don't want this slider, change the '#if 0' line in the WM_INITDLG part of this dialog procedure. This is enough for simple saver modules, but can easily be expanded for more saver modules that need more settings. */ MRESULT EXPENTRY ConfigureDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { char buf[sizeof(modulename)+20]; static HWND hwndEnabled; static HWND hwndSpeed; /* $$$$$ insert code here $$$$$ If you need additional data for dialog processing, insert it here. $$$$$ for example $$$$$ */ static HWND hwndCount; switch(msg){ case WM_INITDLG: /* set titlebar of the dialog window */ /* to "MODULENAME configuration" */ strcpy(buf, modulename); strcat(buf, " configuration"); WinSetWindowText(hwnd, (PSZ)buf); /* get window handles of the dialog controls */ /* and set initial state of the controls */ hwndEnabled = WinWindowFromID(hwnd, IDC_ENABLED); WinSendMsg(hwndEnabled, BM_SETCHECK, MPFROMSHORT(configuration_data.enabled), MPVOID); hwndSpeed = WinWindowFromID(hwnd, IDC_SPEED); WinSendMsg(hwndSpeed, SLM_SETTICKSIZE, MPFROM2SHORT(SMA_SETALLTICKS, 3), MPVOID); WinSendMsg(hwndSpeed, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), MPFROMLONG(configuration_data.animation_speed)); WinSendMsg(hwndSpeed, SLM_SETSCALETEXT, MPFROMSHORT(0), MPFROMP("slow")); WinSendMsg(hwndSpeed, SLM_SETSCALETEXT, MPFROMSHORT(4), MPFROMP("fast")); /* $$$$$ insert code here $$$$$ Get window handles of your dialog controls. Set initial state of your controls. $$$$$ for example $$$$$ */ hwndCount = WinWindowFromID(hwnd, IDC_COUNT); WinSendMsg(hwndCount, SPBM_SETLIMITS, (MPARAM)CONFIGURATION_MAXIMUM_COUNT, (MPARAM)CONFIGURATION_MINIMUM_COUNT); WinSendMsg(hwndCount, SPBM_SETCURRENTVALUE, MPFROMLONG(configuration_data.count), MPVOID); /* return FALSE since we did not change the focus */ return (MRESULT)FALSE; case WM_COMMAND: switch(SHORT1FROMMP(mp1)){ case IDC_OK: /* OK button was pressed. query the control settings */ configuration_data.enabled = SHORT1FROMMR(WinSendMsg(hwndEnabled, BM_QUERYCHECK, MPVOID, MPVOID)); configuration_data.animation_speed = SHORT1FROMMR(WinSendMsg(hwndSpeed, SLM_QUERYSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), MPVOID)); /* $$$$$ insert code here $$$$$ Query control settings of your controls. $$$$$ for example $$$$$ */ WinSendMsg(hwndCount, SPBM_QUERYVALUE, MPFROMP(&configuration_data.count), MPFROM2SHORT(0, SPBQ_DONOTUPDATE)); /* write all configuration data to INI-file */ write_profile_data(); /* end dialog */ WinDismissDlg(hwnd, TRUE); return (MRESULT)0; case IDC_CANCEL: /* dialog was cancelled; end it */ WinDismissDlg(hwnd, FALSE); return (MRESULT)0; default: return (MRESULT)0; } } return WinDefDlgProc(hwnd, msg, mp1, mp2); }
OButton& OButton::setState(ULONG state) { WinSendMsg(hwnd, BM_SETCHECK, MPFROMSHORT(state), NULL); return(*this); }
OButton& OButton::setHilite(BOOL hiliteState) { WinSendMsg(hwnd, BM_SETHILITE, MPFROMSHORT(hiliteState), NULL); return(*this); }
ULONG OListBox::queryItemHandle(const ULONG itemIndex) { return((ULONG)WinSendMsg(hwnd, LM_QUERYITEMHANDLE, MPFROMSHORT(itemIndex), NULL)); }
ULONG OListBox::queryItemTextLength(const ULONG itemIndex) { return((ULONG)WinSendMsg(hwnd, LM_QUERYITEMTEXTLENGTH, MPFROMSHORT(itemIndex), NULL)); }
VOID resizePDF(VOID *hwnd) { HAB habT; HMQ hmqT; CHAR errMsg1[80]; CHAR sizeStr[15]; ULONG totalSpace, allocated, available; ULONG drvNum, drvNumOrg, ulDriveMap; struct find_t ffblk; struct Smp { SHORT indx; CHAR noteName[NAMESIZE]; }tplate; habT = WinInitialize(0); hmqT = WinCreateMsgQueue(habT, 0); WinCancelShutdown(hmqT, TRUE); subClassWin(); disableButtons(); /* WinEnableMenuItem(hwndMenu, ID_MISC , FALSE); WinEnableMenuItem(hwndMenu, ID_OPTIONS , FALSE); WinEnableMenuItem(hwndMenu, ID_HELPME , FALSE); WinEnableMenuItem(hwndMenu, ID_SETMODULES , FALSE); WinEnableMenuItem(WinWindowFromID(hwndFrame, FID_SYSMENU), SC_CLOSE , FALSE); */ _dos_findfirst(datFile, _A_NORMAL, &ffblk); DosQueryCurrentDisk(&drvNumOrg, &ulDriveMap); drvNum = pdf[0].noteText[0] - '@'; DosSetDefaultDisk(drvNum); QueryDiskSpace (drvNum, &totalSpace, &allocated, &available); if( ((ffblk.size*2)+44000) >= available ) { strcpy(errMsg1, "You need at least "); ultoa((ffblk.size*2)+44000, sizeStr, 10); strcat(errMsg1, sizeStr); strcat(errMsg1, " bytes free and possibly more to resize this file."); WinMessageBox(HWND_DESKTOP, (HWND)hwnd, errMsg1, "Not enough disk space to accomplish task!", 0, MB_ICONEXCLAMATION | MB_OK); } else { INT LRECSIZE; INT xx, i; FILE *rHan, *hanTMP; div_t dvt; INT origFL; origFL = FIXEDLEN; rHan = fopen(datFile, MRW); fseek(rHan, 0L, SEEK_SET); fread(&recIndex, sizeof(recIndex), 1, rHan); xx = WinQueryLboxCount(WinWindowFromID((HWND)hwnd, ID_LISTBOX1)); LRECSIZE = 0; for(i=0;i<xx;i++) { fread(&tplate, sizeof(tplate), 1, rHan); fread(&dataRecs.noteText, FIXEDLEN, 1, rHan); if( strlen(dataRecs.noteText) > LRECSIZE ) LRECSIZE = strlen(dataRecs.noteText); } fclose(rHan); if( LRECSIZE < 1000 ) sModSize = 1; if( LRECSIZE > 28999 ) sModSize = 30; if( (LRECSIZE > 999) && (LRECSIZE < 29000) ) { dvt = div(LRECSIZE, 1000); if( dvt.rem == 0 ) sModSize = dvt.quot; else sModSize = dvt.quot + 1; } if( newSizePrompt((HWND)hwnd) ) { rHan = fopen(datFile, MRW); fseek(rHan, 0L, SEEK_SET); fread(&recIndex, sizeof(recIndex), 1, rHan); recIndex[0].alIndex = sModSize; hanTMP = fopen("TMP$$$$$.PDF", "w+b" ); fwrite(&recIndex, sizeof(recIndex), 1, hanTMP); for(i=0;i<xx;i++) { fread(&tplate, sizeof(tplate), 1, rHan); fread(&dataRecs.noteText, FIXEDLEN, 1, rHan); fwrite(&tplate, sizeof(tplate), 1, hanTMP); fwrite(&dataRecs.noteText, sModSize, 1, hanTMP); } fclose(rHan); fclose(hanTMP); if( rename(datFile, "X$X$$$$$.PDF") != 0 ) { FIXEDLEN = origFL; recIndex[0].alIndex = FIXEDLEN; sModSize = FIXEDLEN; } if( rename("TMP$$$$$.PDF", datFile) != 0 ) { FIXEDLEN = origFL; recIndex[0].alIndex = FIXEDLEN; rename("X$X$$$$$.PDF", datFile); sModSize = FIXEDLEN; } remove("X$X$$$$$.PDF"); FIXEDLEN = sModSize; initLoad(WinWindowFromID((HWND)hwnd, ID_LISTBOX1), datFile); setStatus((HWND)hwnd, datFile); WinPostMsg(WinWindowFromID((HWND)hwnd, ID_LISTBOX1), LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE)); } } DosSetDefaultDisk(drvNumOrg); enableButtons(); unSubClassWin(); /* WinEnableMenuItem(hwndMenu, ID_OPTIONS , TRUE); WinEnableMenuItem(hwndMenu, ID_HELPME , TRUE); WinEnableMenuItem(hwndMenu, ID_MISC , TRUE); WinEnableMenuItem(hwndMenu, ID_SETMODULES , TRUE); WinEnableMenuItem(WinWindowFromID(hwndFrame, FID_SYSMENU), SC_CLOSE , TRUE); */ WinDestroyMsgQueue(hmqT); WinTerminate(habT); _endthread(); }
ULONG OListBox::deleteItem(const ULONG itemIndex) { return((ULONG)WinSendMsg(hwnd, LM_DELETEITEM, MPFROMSHORT(itemIndex), NULL)); }
MRESULT EXPENTRY AirTrafficControlDlg (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { PINST pinst; pinst = (PINST) WinQueryWindowPtr(hwnd,QWL_USER); switch (msg) { case WM_INITDLG: { /* * INITIALIZE APPLICATION */ CNRINFO ccinfo; // Container info structure // Initialize instance data pinst = (PINST) calloc (1, sizeof *pinst); WinSetWindowPtr(hwnd,QWL_USER,pinst); pinst->hwndCnr = WinWindowFromID (hwnd, IDCNR_SAMPLE); pinst->hab = WinQueryAnchorBlock (hwnd); pinst->hwndAircraftMenu = // Load aircraft menu WinLoadMenu( HWND_OBJECT, 0, IDMENU_AIRCRAFT); pinst->hwndContainerMenu = // Load container menu WinLoadMenu( HWND_OBJECT, 0, IDMENU_CONTAINER); pinst->CurrentView = IDMVIEW_RADAR; // Set container info to request owner background painting memset (&ccinfo, 0, sizeof ccinfo); ccinfo.cb = sizeof ccinfo; ccinfo.flWindowAttr = CA_OWNERPAINTBACKGROUND; WinSendMsg (pinst->hwndCnr, CM_SETCNRINFO, &ccinfo, MPFROMLONG(CMA_FLWINDOWATTR)); // Subclass container window to provide background painting pfnwpCnr = WinSubclassWindow (pinst->hwndCnr, CnrSubclassWndProc); assert (pfnwpCnr); // Insert the columns into the container InsertContainerColumns (pinst); // Insert the initial records into the container InsertContainerRecords (pinst); // Start a timer to control aircraft WinStartTimer (pinst->hab, hwnd, IDTIMER_ADJUSTAIRCRAFT, AIRCRAFT_ADJUST_FREQUENCY); // The container is ready for viewing WinShowWindow (pinst->hwndCnr, TRUE); SetUpControllerHandoffValueSet (hwnd); return 0; } case WM_TIMER: /* * DO TIME-RELATED AIRCRAFT HANDLING */ if (SHORT1FROMMP (mp1) == IDTIMER_ADJUSTAIRCRAFT) { PAPPCNRREC pacrTraverse; // Loop through all container records for (pacrTraverse = FIRST_CNR_ITEM (pinst->hwndCnr); pacrTraverse; pacrTraverse = NEXT_CNR_ITEM(pinst->hwndCnr,pacrTraverse)) { BOOL fInvalid = FALSE; if (pinst->CurrentView == IDMVIEW_RADAR) { /* Erase the record from previous location. */ WinSendMsg (pinst->hwndCnr, CM_ERASERECORD, MPFROMP(pacrTraverse), NULL); } // Maneuver the aircraft if (ManeuverAircraft (pacrTraverse)) { // Update aircraft text if necessary SetRecordText (pacrTraverse); fInvalid = TRUE; } if (fInvalid || pinst->CurrentView == IDMVIEW_RADAR) /* Paint the record in its new position */ WinSendMsg (pinst->hwndCnr, CM_INVALIDATERECORD, MPFROMP(&pacrTraverse), MPFROMSHORT(1)); } } else if (SHORT1FROMMP (mp1) == IDTIMER_DISPLAYTIMEDMSG) { WinStopTimer (pinst->hab, hwnd, IDTIMER_DISPLAYTIMEDMSG); WinSetDlgItemText (hwnd, IDST_STATUSMESSAGES, ""); } return 0; case WM_CONTROL: if (SHORT1FROMMP (mp1) == IDCNR_SAMPLE) switch (SHORT2FROMMP (mp1)) { case CN_CONTEXTMENU: { /* * MENU HANDLING */ POINTL ptlMouse; HWND hwndMenu; WinQueryMsgPos (pinst->hab, &ptlMouse); // Save pointer to record mouse is over, if any pinst->pacrSelected = (PAPPCNRREC) mp2; hwndMenu = pinst->pacrSelected ? pinst->hwndAircraftMenu : pinst->hwndContainerMenu; // Display menu WinPopupMenu (HWND_DESKTOP, hwnd, hwndMenu, ptlMouse.x, ptlMouse.y, 0, PU_HCONSTRAIN | PU_VCONSTRAIN | PU_KEYBOARD | PU_MOUSEBUTTON1 | PU_MOUSEBUTTON2 | PU_MOUSEBUTTON3); return 0; } case CN_INITDRAG: ProcessInitDrag ( WinWindowFromID (hwnd, SHORT1FROMMP (mp1)), ((PCNRDRAGINIT) (PVOIDFROMMP(mp2)))); return 0; case CN_SCROLL: WinInvalidateRect (pinst->hwndCnr, 0, 0); return 0; } else /* * HANDLE WM_CONTROL MESSAGES FROM VALUE SET CONTROL */ if (SHORT1FROMMP (mp1) == IDVS_CONTROLLERS) switch (SHORT2FROMMP (mp1)) { case VN_SELECT: DisplayTimedMsg (pinst->hab, hwnd, "Drag an airplane to one " "of the controller icons to hand off to " "another controller.", 8); return 0; case VN_DROP: { PVSDRAGINFO pvsdinfo = (PVSDRAGINFO) PVOIDFROMMP (mp2); PDRAGINFO pdinfo = pvsdinfo->pDragInfo; PDRAGITEM pditem; INT iItem; INT cHandedOffAircraft = 0; CHAR szHandedOffAircraft [100]; *szHandedOffAircraft = 0; assert (DrgAccessDraginfo(pdinfo)); for (iItem = 0; iItem < pdinfo->cditem; ++iItem) { PAPPCNRREC pacr; pditem = DrgQueryDragitemPtr (pdinfo, iItem); pacr = (PAPPCNRREC) pditem->ulItemID; if (pdinfo->usOperation == DO_MOVE) { WinSendMsg (pdinfo->hwndSource, CM_REMOVERECORD, MPFROMP(&pacr), MPFROM2SHORT (1, CMA_INVALIDATE)); if (cHandedOffAircraft++) strcat (szHandedOffAircraft, ", "); strcat (szHandedOffAircraft, pacr->pszCallsign); } } if (cHandedOffAircraft) { CHAR szMsg [200]; sprintf (szMsg, "Aircraft %s %s been handed off " "to %s Sector controller.", szHandedOffAircraft, cHandedOffAircraft > 1 ? "have" : "has", pvsdinfo->usColumn == 1 ? "West" : "East"); DisplayTimedMsg (pinst->hab, hwnd, szMsg, 8); } DrgFreeDraginfo (pdinfo); WinAlarm (HWND_DESKTOP, WA_NOTE); return 0; } } return 0; case WM_COMMAND: /* * COMMAND HANDLING */ switch (SHORT1FROMMP (mp1)) { case IDMAIRCRAFT_CONTROLINSTRUCT: // Issue instruction { // Present "Control Aircraft" dialog WinDlgBox (HWND_DESKTOP, hwnd, ControlInstructionDlg, 0, IDDLG_CONTROLAIRCRAFT, pinst); return 0; } case IDMVIEW_RADAR: case IDMVIEW_NAME: case IDMVIEW_TREE: case IDMVIEW_DETAILS: case IDMVIEW_TEXT: { static const ULONG aViews [] = { CV_ICON, CV_NAME, CV_TREE, CV_DETAIL, CV_TEXT }; CNRINFO ccinfo; memset (&ccinfo, 0, sizeof ccinfo); ccinfo.cb = sizeof ccinfo; ccinfo.flWindowAttr = CA_DETAILSVIEWTITLES | CA_TITLESEPARATOR | CA_TREELINE | CA_OWNERPAINTBACKGROUND | aViews [SHORT1FROMMP (mp1) - IDMVIEW_BASE]; WinSendMsg (pinst->hwndCnr, CM_SETCNRINFO, &ccinfo, MPFROMLONG(CMA_FLWINDOWATTR)); pinst->CurrentView = SHORT1FROMMP (mp1); WinInvalidateRect (pinst->hwndCnr, 0, 0); return 0; } } return WinDefDlgProc (hwnd, msg, mp1, mp2); default: return WinDefDlgProc (hwnd, msg, mp1, mp2); } }
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) ; }
/* This procedure handles the author settings page */ MRESULT EXPENTRY authorOptionDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { CWDataFolder* thisPtr; switch(msg) { case WM_INITDLG : WinSetWindowULong(hwnd, QWL_USER,(ULONG)PVOIDFROMMP(mp2));//Save object ptr. thisPtr=(CWDataFolder*)PVOIDFROMMP(mp2); WinSendMsg(WinWindowFromID(hwnd,IDEF_APPLICATION),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)128),0); WinSetWindowText(WinWindowFromID(hwnd,IDEF_APPLICATION),thisPtr->chrApplication); WinSendMsg(WinWindowFromID(hwnd,IDEF_PUBLISHER),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)128),0); WinSetWindowText(WinWindowFromID(hwnd,IDEF_PUBLISHER),thisPtr->chrPublisher); WinSendMsg(WinWindowFromID(hwnd,IDEF_PREPARER),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)128),0); WinSetWindowText(WinWindowFromID(hwnd,IDEF_PREPARER),thisPtr->chrPreparer); WinSendMsg(WinWindowFromID(hwnd,IDEF_VOLUMENAME),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)32),0); WinSetWindowText(WinWindowFromID(hwnd,IDEF_VOLUMENAME),thisPtr->chrVolumeName); /* Move default buttons on Warp 4 */ cwMoveNotebookButtonsWarp4(hwnd, IDPB_AUTHORHELP, 20); return (MRESULT) TRUE; /* This prevents switching the notebook page behind the open folder */ case WM_WINDOWPOSCHANGED: { MRESULT mr; if(WinQueryFocus(HWND_DESKTOP)!= WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT), QW_PARENT)) { mp2=MPFROMLONG(LONGFROMMP(mp2)|0x80000);/*AWP_ACTIVATE 0x00080000L*/ mr=WinDefDlgProc(hwnd, msg, mp1, mp2); return mr; } break; } case WM_FOCUSCHANGE: { if(!SHORT1FROMMP(mp2)) { if(HWNDFROMMP(mp1)==hwnd) { MRESULT mr; mr=WinDefDlgProc(hwnd, msg, mp1, mp2); WinSendMsg(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT), QW_PARENT), WM_SETFOCUS, MPFROMHWND(hwnd), (MPARAM)TRUE); return mr; } } break; } case WM_DESTROY: /* The notebook closes and gets destroyed */ /* Set focus to desktop to prevent PM freeze */ WinSetFocus(HWND_DESKTOP, HWND_DESKTOP); /* Let the WPS save the new instance data */ // thisPtr=(CWDataFolder*) WinQueryWindowULong(WinWindowFromID(hwnd,IDPB_AUTHORUNDO),QWL_USER); thisPtr=(CWDataFolder*) WinQueryWindowULong(hwnd,QWL_USER); if(somIsObj(thisPtr)) { WinQueryWindowText( WinWindowFromID(hwnd,IDEF_APPLICATION),sizeof(thisPtr->chrApplication),thisPtr->chrApplication); WinQueryWindowText( WinWindowFromID(hwnd,IDEF_PUBLISHER),sizeof(thisPtr->chrPublisher),thisPtr->chrPublisher); WinQueryWindowText( WinWindowFromID(hwnd,IDEF_PREPARER),sizeof(thisPtr->chrPreparer),thisPtr->chrPreparer); WinQueryWindowText( WinWindowFromID(hwnd,IDEF_VOLUMENAME),sizeof(thisPtr->chrVolumeName),thisPtr->chrVolumeName); thisPtr->wpSaveDeferred(); } /* Setup is done */ return (MRESULT) TRUE; case WM_COMMAND: switch(SHORT1FROMMP(mp1)) { case IDPB_AUTHORUNDO: /* User pressed the UNDO button */ // thisPtr=(CWDataFolder*) WinQueryWindowULong(WinWindowFromID(hwnd,IDPB_AUTHORUNDO),QWL_USER); thisPtr=(CWDataFolder*) WinQueryWindowULong(hwnd,QWL_USER); if(somIsObj(thisPtr)) { WinSetWindowText(WinWindowFromID(hwnd,IDEF_APPLICATION),thisPtr->chrApplication); WinSetWindowText(WinWindowFromID(hwnd,IDEF_PUBLISHER),thisPtr->chrPublisher); WinSetWindowText(WinWindowFromID(hwnd,IDEF_PREPARER),thisPtr->chrPreparer); WinSetWindowText(WinWindowFromID(hwnd,IDEF_VOLUMENAME),thisPtr->chrVolumeName); } break; default: break; } return (MRESULT) TRUE; default: break; } return WinDefDlgProc(hwnd, msg, mp1, mp2); }
/**************************************************************************** * Initialize * * - Performs several application initializations. Reads profile info, * * modifies client window to match it, seeds random number generator, * * initializes game data structures, and starts the timer. * * - No I/O. * ****************************************************************************/ VOID Initialize(VOID) { INT i; ULONG cb; /* Read in the profile data if it exists */ PrfQueryProfileSize(HINI_USERPROFILE, szClientClass, "Data", &cb); if (cb == sizeof(PROFILEREC)) PrfQueryProfileData(HINI_USERPROFILE, szClientClass, "Data", (PVOID)&prfProfile, &cb); /* Make frame size & position match profile information (or initialize) */ if ((prfProfile.ulMINMAX & SWP_MINIMIZE) || (prfProfile.ulMINMAX & SWP_MAXIMIZE)) WinSetWindowPos(hwndFrame, HWND_TOP, prfProfile.x, prfProfile.y, prfProfile.cx, prfProfile.cy, SWP_ACTIVATE | SWP_SHOW | SWP_SIZE | SWP_MOVE | prfProfile.ulMINMAX); else if ((prfProfile.cx != 0) && (prfProfile.cy != 0)) WinSetWindowPos(hwndFrame,HWND_TOP, prfProfile.x,prfProfile.y,prfProfile.cx,prfProfile.cy, SWP_ACTIVATE | SWP_SHOW | SWP_SIZE | SWP_MOVE); /* Profile information is new. Rely on PM to size/position the client * * window this first time. */ else WinShowWindow(hwndFrame, TRUE); /* Hide controls if hidden at last save * * Normally this if block should occur prior to the previous one, but * * there appears to be a PM v1.2 bug w/hide before WinSetWindowPos: * * the title bar _looks_ inactive when it is later shown. */ if (!prfProfile.bCONTROLS) HideFrameControls(); /* Create a help instance */ hwndHelp = WinCreateHelpInstance(hab, &hinit); if (hwndHelp == NULLHANDLE) { /* failed to create help instance */ WinAlarm(HWND_DESKTOP, WA_WARNING); WinMessageBox(HWND_DESKTOP, NULLHANDLE, "Please put ASTEROID.HLP in a directory pointed to by the HELP " "environment variable or in the ASTEROID working directory.", "Could not find help file", 0, MB_ICONHAND | MB_OK | MB_APPLMODAL); } else WinAssociateHelpInstance(hwndHelp, hwndFrame); /* Initialize Menu according to profile info */ InitMenu(); /* Seed the random number generator from seed in profile */ srand((unsigned int) prfProfile.uiSEED); prfProfile.uiSEED = (UINT) rand(); /* Initialize game data structures */ WinSendMsg(hwndClient, WM_INITGAME, MPFROMSHORT(0), MPVOID); /* Startup a timer for screen updates */ TogglePause(FORCE_UNPAUSE); if ((prfProfile.ulMINMAX & SWP_MINIMIZE) && (!prfProfile.bBACKGRND)) { /* Set icon */ WinSendMsg(hwndFrame, WM_SETICON, (MPARAM)WinLoadPointer(HWND_DESKTOP, NULLHANDLE, ID_RESOURCE), MPVOID); TogglePause(SUSPEND_ON); } }
ULONG OListBox::querySelection(const ULONG itemStart) { return((ULONG)WinSendMsg(hwnd, LM_QUERYSELECTION, MPFROMSHORT(itemStart), NULL)); }
/**************************************************************************** * KeyDlgProc * * - Redefines keys by processing WM_CHAR's and assigning the key to the * * selected radiobutton (game key) * * - Standard dialog window I/O * ****************************************************************************/ MRESULT EXPENTRY KeyDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { int i; static KEY keyTmp[KEYS]; static SHORT id; switch (msg) { case WM_INITDLG: /* Set the associated text for each of the radio buttons */ for (i=0;i<KEYS;i++) { keyTmp[i] = prfProfile.keyDEFS[i]; SetText(hwnd, TEXT_LEFT+i, &prfProfile.keyDEFS[i]); } /* Check the first radio button and let it set up id */ WinSendDlgItemMsg(hwnd, KEY_LEFT, BM_CLICK, MPFROMSHORT(TRUE), MPVOID); return (MRESULT) TRUE; case WM_HELP: i = IDH_KEYS; WinSendMsg(hwndHelp, HM_DISPLAY_HELP, MPFROMP(&i), MPFROMSHORT(HM_RESOURCEID)); return 0; case WM_COMMAND: switch (SHORT1FROMMP(mp1)) { case DID_OK: for (i=0;i<KEYS;i++) prfProfile.keyDEFS[i] = keyTmp[i]; case DID_CANCEL: WinDismissDlg(hwnd, 0); return 0; } return 0; case WM_CONTROL: if (SHORT2FROMMP(mp1) == BN_CLICKED) { switch (SHORT1FROMMP(mp1)) { case KEY_LEFT: id = TEXT_LEFT; break; case KEY_RIGHT: id = TEXT_RIGHT; break; case KEY_THRUST: id = TEXT_THRUST; break; case KEY_HYPER: id = TEXT_HYPER; break; case KEY_FIRE: id = TEXT_FIRE; break; case KEY_SHIELD: id = TEXT_SHIELD; } WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd,id)); } return 0; case WM_CHAR: if (!(CHARMSG(&msg)->fs & KC_KEYUP)) { if ((CHARMSG(&msg)->fs & KC_VIRTUALKEY) && (CHARMSG(&msg)->vkey != VK_SHIFT) && (CHARMSG(&msg)->vkey != VK_CTRL) && (CHARMSG(&msg)->vkey != VK_ALT) && (CHARMSG(&msg)->vkey != VK_F1) && (CHARMSG(&msg)->vkey-1 < MAXVKEY)) { if (CHARMSG(&msg)->vkey == VK_F3) { WinSendMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_CANCEL, 0), MPVOID); return 0; } keyTmp[id-TEXT_LEFT].vk = (CHAR) (CHARMSG(&msg)->vkey - 1); keyTmp[id-TEXT_LEFT].chr = 0; } else if ((CHARMSG(&msg)->fs & KC_CHAR) && (CHARMSG(&msg)->chr > 32) && (CHARMSG(&msg)->chr < 127)) { keyTmp[id-TEXT_LEFT].vk = 0; keyTmp[id-TEXT_LEFT].chr = (CHAR) CHARMSG(&msg)->chr; } else { keyTmp[id-TEXT_LEFT].vk = 0; keyTmp[id-TEXT_LEFT].chr = 0; } } SetText(hwnd, id, &keyTmp[id-TEXT_LEFT]); return 0; } return WinDefDlgProc(hwnd, msg, mp1, mp2); }
BOOL OListBox::selectItem(const ULONG itemIndex, const BOOL state) { return((BOOL)WinSendMsg(hwnd, LM_SELECTITEM, MPFROMSHORT(itemIndex), MPFROMSHORT(state))); }
OButton& OButton::setDefault(BOOL displayDefault) { WinSendMsg(hwnd, BM_SETDEFAULT, MPFROMSHORT(displayDefault), NULL); return(*this); }
BOOL OListBox::setItemHandle(const ULONG itemIndex, const ULONG handle) { return((BOOL)WinSendMsg(hwnd, LM_SETITEMHANDLE, MPFROMSHORT(itemIndex), MPFROMSHORT(handle))); }
OButton& OButton::click(BOOL down) { WinSendMsg(hwnd, BM_CLICK, MPFROMSHORT(down), NULL); return(*this); }
BOOL OListBox::setItemHeight(const ULONG newHeight) { return((BOOL)WinSendMsg(hwnd, LM_SETITEMHEIGHT, MPFROMSHORT(newHeight), NULL)); }
/*----------------------------------------------------------------------------*/ MRESULT EXPENTRY DLG_MAIN_Proc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) /*----------------------------------------------------------------------------*/ /* This dialog proc initializes and handles all messages for the main */ /* dialog. */ /*----------------------------------------------------------------------------*/ { static HWND ContextHwnd; /* Handle of context menu */ static SHORT ContextIndx; /* Index of item context menu was selected on */ switch (msg) { case WM_INITDLG: INSERTITEM(LIST, "Listbox item 0"); INSERTITEM(LIST, "Listbox item 1"); INSERTITEM(LIST, "Listbox item 2"); INSERTITEM(LIST, "Listbox item 3"); INSERTITEM(LIST, "Listbox item 4"); INSERTITEM(LIST, "Listbox item 5"); INSERTITEM(LIST, "Listbox item 6"); INSERTITEM(LIST, "Listbox item 7"); INSERTITEM(LIST, "Listbox item 8"); INSERTITEM(LIST, "Listbox item 9"); INSERTITEM(LIST, "Listbox item 10"); INSERTITEM(LIST, "Listbox item 11"); INSERTITEM(LIST, "Listbox item 12"); INSERTITEM(LIST, "Listbox item 13"); INSERTITEM(LIST, "Listbox item 14"); INSERTITEM(LIST, "Listbox item 15"); /* Add direct-manipulation capability to the listbox */ DMLBInitialize(CONTROLHWND(LIST), NULLHANDLE); /* Load context menu for later use */ ContextHwnd = WinLoadMenu(hwnd, NULLHANDLE, ID_MENU); return FALSE; case WM_DESTROY: /* Free resources */ WinDestroyWindow(ContextHwnd); break; case WM_COMMAND: switch (SHORT1FROMMP(mp1)) { /*******************************************************************/ /* We get WM_COMMAND messages from the context menu. The variable */ /* ContextIndx already has the index of the item on which the */ /* context menu was requested (or LIT_NONE). */ /*******************************************************************/ case ID_MENU_EDIT: { //------- Context menu "Edit" selected ----------- char Buff[MAX_LEN]; /* Run edit menu, update list if user selects OK button */ QUERYITEMTEXT(LIST, ContextIndx, Buff, sizeof(Buff)); if (WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)DLG_EDIT_Proc, NULLHANDLE, DLG_EDIT, Buff) == DID_OK) SETITEMTEXT(LIST, ContextIndx, Buff); return 0; } case ID_MENU_DELETE: //------- Context menu "Delete" selected ----------- WinSendMsg(CONTROLHWND(LIST), LM_DELETEITEM, MPFROMSHORT(ContextIndx), MPVOID); return 0; case ID_MENU_INSERT: {//------- Context menu "Insert" selected ---------- char Buff[MAX_LEN]; /* Run edit menu, insert into list if user selects OK button */ Buff[0] = '\0'; if (WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)DLG_EDIT_Proc, NULLHANDLE, DLG_EDIT, Buff) == DID_OK) { if (ContextIndx == LIT_NONE) // Insert at end of list ContextIndx = LIT_END; else ContextIndx++; // Insert AFTER selected item INSERTITEMAT(LIST, ContextIndx, Buff); } return 0; } case DID_OK: /*----------~OK (PUSHBUTTON)----------*/ // Let default dialog proc terminate us break; } break; case WM_CONTROL: switch SHORT1FROMMP(mp1) { case LIST: /*----------LIST (LISTBOX)----------*/ /*******************************************************************/ /* Notification messages from the listbox come here. These are */ /* the usual PM listbox messages, plus some new ones for DMLB. */ /*******************************************************************/ switch (SHORT2FROMMP(mp1)) { case LN_SELECT: case LN_ENTER: /* User dbl-clicked an entry or pressed ENTER. For this sample */ /* we do nothing. */ return 0; case LN_DMLB_QRYDROP: /* A listbox item is about to be dropped on this listbox. We must */ /* return a Ok-to-drop indicator, and tell what to do with the */ /* original item (copy or move). Since we have just one listbox in */ /* this sample, MOVE is the only thing that makes sense. */ return MRFROM2SHORT(TRUE, DROPMODE_MOVE); case LN_DMLB_CONTEXT: { /* The user has requested a context menu. Short 1 of mp2 is the */ /* index of the listbox item under the pointer. */ POINTL Point; ContextIndx = SHORT1FROMMP(mp2); if (ContextIndx == LIT_NONE) { // Disable Edit & Delete if pointer was not over a listbox item WinSendMsg(ContextHwnd, MM_SETITEMATTR, MPFROM2SHORT(ID_MENU_EDIT,FALSE), MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)); WinSendMsg(ContextHwnd, MM_SETITEMATTR, MPFROM2SHORT(ID_MENU_DELETE,FALSE), MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)); } else { // Otherwise, enable Edit & Delete WinSendMsg(ContextHwnd, MM_SETITEMATTR, MPFROM2SHORT(ID_MENU_EDIT,FALSE), MPFROM2SHORT(MIA_DISABLED, ~MIA_DISABLED)); WinSendMsg(ContextHwnd, MM_SETITEMATTR, MPFROM2SHORT(ID_MENU_DELETE,FALSE), MPFROM2SHORT(MIA_DISABLED, ~MIA_DISABLED)); } // It is not technically necessary to select the item on which the context // menu was selected, but it provides good visual feedback to the user to // show which item the context menu applies to. SETSELECTION(LIST, ContextIndx); // Popup the context menu at the pointer position. The menu will // send us WM_COMMAND messages if a menu item is selected. WinQueryMsgPos((HAB)0, &Point); WinPopupMenu(HWND_DESKTOP, hwnd, ContextHwnd, Point.x, Point.y, 0, PU_HCONSTRAIN| PU_VCONSTRAIN | PU_MOUSEBUTTON1 | PU_MOUSEBUTTON2 | PU_MOUSEBUTTON3 | PU_KEYBOARD ); return (MRESULT)TRUE; } } break; } break; /* End of WM_CONTROL */ } /* End of (msg) switch */ return WinDefDlgProc(hwnd, msg, mp1, mp2); } /* End dialog procedure */
BOOL OListBox::setItemText(const ULONG itemIndex, PCSZ text) { if (text) return((BOOL)WinSendMsg(hwnd, LM_SETITEMTEXT, MPFROMSHORT(itemIndex), MPFROMP(text))); return(FALSE); }
/*----------------------------------------------------------------------*/ MRESULT EXPENTRY DMLBSubclassListboxProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2) /*----------------------------------------------------------------------*/ /* This window procedure is used to subclass a standard PM listbox */ /* control. This procedure will intercept certain mouse events on the */ /* listbox to implement direct-manipulation functions. */ /*----------------------------------------------------------------------*/ { SHORT Item; /* Listbox item number */ DMLBData *InstData; /* This instance-specific data (per listbox) */ /* The lisbox window pointer is to our instance data. */ InstData = WinQueryWindowPtr(hwnd, QWL_USER); switch (msg) { /* Since this is just a subclass setup after the listbox window */ /* is created, we never get a WM_CREATE message here. */ case WM_DESTROY: /* The listbox window is being destroyed. Cleanup any */ /* resources we have allocated in this subclass. */ if (InstData->DragMIcon != NULLHANDLE) { WinDestroyPointer(InstData->DragMIcon); WinDestroyPointer(InstData->DragCIcon); WinDestroyPointer(InstData->NorthIcon); WinDestroyPointer(InstData->SouthIcon); WinDestroyPointer(InstData->DragNoDrp); WinDestroyPointer(InstData->DeletIcon); InstData->DragMIcon = NULLHANDLE; } /* Cleanup other resources */ if (InstData->Dragging) { WinStopTimer(WinQueryAnchorBlock(hwnd),hwnd,DRAG_TIMERID); } /* Release instance data */ free(InstData); WinSetWindowPtr(hwnd, 0L, NULL); break; case WM_TIMER: /* We get timer messages during dragging to implement */ /* auto-scrolling of listbox when pointer is placed */ /* north or south of the listbox while dragging. */ if (!InstData->Dragging) /* Ignore if not dragging */ break; if (SHORT1FROMMP(mp1)==DRAG_TIMERID) { switch (InstData->PrevLocation) { // Last known location of the pointer case POINT_INSIDE: case POINT_OUTSIDE: /* Do nothing */ break; case POINT_NORTH: /* Scroll up one item */ Item = (SHORT)WinSendMsg(InstData->TargetHwnd, LM_QUERYTOPINDEX, 0L, 0L); if ((Item != LIT_NONE) && (Item != 0)) WinPostMsg(InstData->TargetHwnd, LM_SETTOPINDEX, MPFROMSHORT(Item-1), 0L); break; case POINT_SOUTH: /* Scroll down one item */ Item = (SHORT)WinSendMsg(InstData->TargetHwnd, LM_QUERYTOPINDEX, 0L, 0L); if (Item != LIT_NONE) WinPostMsg(InstData->TargetHwnd, LM_SETTOPINDEX, MPFROMSHORT(Item+1), 0L); break; } /* switch on PrevLocation */ return 0; } break; case WM_CONTEXTMENU: { SHORT CursorIndx, Max; /* User requested context menu... notify our owner. */ /* First find out what item the pointer is over. */ Max = (SHORT)WinSendMsg( hwnd, LM_QUERYITEMCOUNT, 0L, 0L ); CursorIndx = DMLBLocateListboxItem(hwnd, hwnd, SHORT2FROMMP(mp1), LLI_UNDER); if ((Max == 0) || (CursorIndx+1 > Max)) CursorIndx = LIT_NONE; /* Tell our owner about it */ return WinSendMsg(WinQueryWindow(hwnd, QW_OWNER), WM_CONTROL, MPFROM2SHORT(WinQueryWindowUShort(hwnd, QWS_ID), LN_DMLB_CONTEXT), MPFROMSHORT(CursorIndx)); } case WM_MOUSEMOVE: /* Monitor the position of the mouse relative to the listbox */ /* so we can set the pointer icon correctly and note the */ /* position for use during WM_TIMER processing. */ if (!InstData->Dragging) /* Ignore if not dragging */ break; DMLBCheckTargetLocation(hwnd, InstData, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1)); /* Set pointer icon appropriate for location */ if (InstData->DragMIcon == NULLHANDLE) { // Load all the pointers (one time only) InstData->DragMIcon= WinLoadPointer(HWND_DESKTOP, InstData->ResHMod, ID_DMLB_DRAGMOVE); InstData->DragCIcon= WinLoadPointer(HWND_DESKTOP, InstData->ResHMod, ID_DMLB_DRAGCOPY); InstData->DragNoDrp= WinLoadPointer(HWND_DESKTOP, InstData->ResHMod, ID_DMLB_DRAGNONE); InstData->NorthIcon= WinLoadPointer(HWND_DESKTOP, InstData->ResHMod, ID_DMLB_DRGNORTH); InstData->SouthIcon= WinLoadPointer(HWND_DESKTOP, InstData->ResHMod, ID_DMLB_DRGSOUTH); InstData->DeletIcon= WinLoadPointer(HWND_DESKTOP, InstData->ResHMod, ID_DMLB_DRGDEL); } switch (InstData->PrevLocation) { case POINT_INSIDE: switch (InstData->TargetDropMode) { case DROPMODE_MOVE: WinSetPointer(HWND_DESKTOP, InstData->DragMIcon); // Use MOVE pointer break; case DROPMODE_COPY: WinSetPointer(HWND_DESKTOP, InstData->DragCIcon); // Use COPY pointer break; case DROPMODE_DELETE: WinSetPointer(HWND_DESKTOP, InstData->DeletIcon); // Use DELETE pointer break; } break; case POINT_OUTSIDE: WinSetPointer(HWND_DESKTOP, InstData->DragNoDrp); // No-drop pointer break; case POINT_NORTH: WinSetPointer(HWND_DESKTOP, InstData->NorthIcon); // Scroll-up pointer break; case POINT_SOUTH: WinSetPointer(HWND_DESKTOP, InstData->SouthIcon); // Scroll-down poineter break; } return (MRESULT)TRUE; /* Note we processed the message */ case WM_BEGINDRAG: { SHORT Max; SHORT i, CursorIndx, hit; /* User started dragging with the pointer on our window */ Max = (SHORT)WinSendMsg( hwnd, LM_QUERYITEMCOUNT, 0L, 0L ); /* If we are currently dragging, cancel it (should not happen) */ if ( InstData->Dragging ) { InstData->Dragging = FALSE; WinSetCapture( HWND_DESKTOP, NULLHANDLE ); return (MRESULT)FALSE; } /* Get index of item under the mouse pointer and check */ /* for reasonable numeric bounds. */ CursorIndx = DMLBLocateListboxItem(hwnd, hwnd, SHORT2FROMMP(mp1), LLI_UNDER); if ((Max == 0) || (CursorIndx+1 > Max)) { DosBeep( 440L, 50L ); // Don't allow drag if not on a listbox item return (MRESULT)FALSE; } /* Since we currently support dragging only a single item, */ /* de-select all items and just select the one under the */ /* pointer. To support multiple-drag we would probably */ /* need to notify the owner so they could set the selection*/ /* status of all items to be dragged (which may or may not */ /* include the item under the pointer). */ WinSendMsg(hwnd, LM_SELECTITEM, MPFROMSHORT(LIT_NONE), MPVOID); WinSendMsg(hwnd, LM_SELECTITEM, MPFROMSHORT(CursorIndx), MPFROMSHORT(TRUE)); /* Note we are now dragging and capture the pointer. */ InstData->Dragging = TRUE; WinSetCapture( HWND_DESKTOP, hwnd ); InstData->PrevLocation = POINT_INSIDE; WinStartTimer(WinQueryAnchorBlock(hwnd),hwnd,DRAG_TIMERID, WinQuerySysValue(HWND_DESKTOP, SV_SCROLLRATE)); return (MRESULT)TRUE; break; } case WM_ENDDRAG: { SHORT DropIndx, CurrIndx; SHORT SourceMax, TargetMax; /* Num of items in source/target listbox */ char *CopyText; /* Text to be copied/moved */ USHORT CopyTextLen; /* Length of text */ void *CopyHand; /* Handle of item to be copied/moved */ BOOL SameList = FALSE; /* Source and target are same listbox */ if (!InstData->Dragging) /* Ignore if we are not dragging */ return (MRESULT)FALSE; /* Clear dragging indicators and release pointer */ InstData->Dragging = FALSE; WinSetCapture( HWND_DESKTOP, NULLHANDLE ); WinStopTimer(WinQueryAnchorBlock(hwnd),hwnd,DRAG_TIMERID); /* See if what is under the pointer will accept the drop */ DMLBCheckTargetLocation(hwnd, InstData, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1)); if (InstData->PrevLocation != POINT_INSIDE) return (MRESULT)TRUE; /* Ignore drop outside a good listbox */ if (hwnd == InstData->TargetHwnd) // Source and target are same listbox SameList = TRUE; SourceMax = (SHORT)WinSendMsg(hwnd, LM_QUERYITEMCOUNT, 0L, 0L ) -1; TargetMax = (SHORT)WinSendMsg(InstData->TargetHwnd, LM_QUERYITEMCOUNT, 0L, 0L ) -1; /* Get drop point and original selected point */ DropIndx = DMLBLocateListboxItem(InstData->TargetHwnd, hwnd, SHORT2FROMMP(mp1), LLI_INSERTPOINT); CurrIndx = (SHORT)WinSendMsg(hwnd, LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), 0L); /* Prevent move onto same item as source, in same listbox */ /* being careful of DropIndx > SourceMax when drop after last item. */ if ((InstData->TargetDropMode==DROPMODE_MOVE) && (SameList) && ((min(DropIndx,SourceMax) == CurrIndx) || (DropIndx == CurrIndx+1))) { DosBeep( 700L, 50L ); /* Don't drop before or after original */ return (MRESULT)TRUE; } /* Make a copy of original to insert */ CopyTextLen = (SHORT)WinSendMsg(hwnd,LM_QUERYITEMTEXTLENGTH,MPFROMSHORT(CurrIndx), 0L) + 1; CopyText = malloc(CopyTextLen); WinSendMsg(hwnd, LM_QUERYITEMTEXT, MPFROM2SHORT(CurrIndx, CopyTextLen), MPFROMP(CopyText)); CopyHand = WinSendMsg(hwnd, LM_QUERYITEMHANDLE, MPFROMSHORT(CurrIndx), 0L); /* Insert before insertion point, or at end of list */ if (DropIndx > TargetMax) DropIndx = LIT_END; /* Disable update during insert/delete for smoother visual and */ /* prevent ownerdraw from occuring before new handles are set. */ WinEnableWindowUpdate(hwnd, FALSE); WinEnableWindowUpdate(InstData->TargetHwnd, FALSE); /* Insert into target list */ if (InstData->TargetDropMode != DROPMODE_DELETE) { DropIndx = (SHORT)WinSendMsg(InstData->TargetHwnd, LM_INSERTITEM, MPFROMSHORT(DropIndx), MPFROMP(CopyText)); WinSendMsg(InstData->TargetHwnd, LM_SETITEMHANDLE, MPFROMSHORT(DropIndx), MPFROMP(CopyHand)); } free(CopyText); /* Tell owner of originating listbox what we are doing. We must notify */ /* the owner before we delete items because they may keep dynamic data */ /* in the item handles that has to be freed. The item in question is */ /* the currently selected item in the listbox. */ switch (InstData->TargetDropMode) { case DROPMODE_MOVE: if (!SameList) WinSendMsg(WinQueryWindow(hwnd, QW_OWNER), WM_CONTROL, MPFROM2SHORT(WinQueryWindowUShort(hwnd, QWS_ID), LN_DMLB_DELETE_MOVE), MPFROMHWND(InstData->TargetHwnd)); break; case DROPMODE_DELETE: WinSendMsg(WinQueryWindow(hwnd, QW_OWNER), WM_CONTROL, MPFROM2SHORT(WinQueryWindowUShort(hwnd, QWS_ID), LN_DMLB_DELETE), MPFROMHWND(InstData->TargetHwnd)); break; } /* If this is a move, delete original. If it is in the same */ /* listbox as target, get new index since it may have */ /* changed due to inserted copy. */ if ((InstData->TargetDropMode == DROPMODE_MOVE) || (InstData->TargetDropMode == DROPMODE_DELETE)) { CurrIndx = (SHORT)WinSendMsg(hwnd, LM_QUERYSELECTION, MPFROMSHORT(LIT_FIRST), 0L); WinSendMsg(hwnd, LM_DELETEITEM, MPFROMSHORT(CurrIndx), 0L); } /* Select the newly inserted item. If the old copy was */ /* above it in the same list, then the item number has changed by 1 */ if ((DropIndx > CurrIndx) && (SameList) && (InstData->TargetDropMode==DROPMODE_MOVE)) DropIndx--; if (InstData->TargetDropMode != DROPMODE_DELETE) { WinSendMsg(InstData->TargetHwnd, LM_SELECTITEM, MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE)); WinSendMsg(InstData->TargetHwnd, LM_SELECTITEM, MPFROMSHORT(DropIndx), MPFROMSHORT(TRUE)); } WinEnableWindowUpdate(hwnd, TRUE); WinEnableWindowUpdate(InstData->TargetHwnd, TRUE); /* Notify target of inserted items if necessary */ switch (InstData->TargetDropMode) { case DROPMODE_MOVE: if (SameList) WinSendMsg(WinQueryWindow(InstData->TargetHwnd, QW_OWNER), WM_CONTROL, MPFROM2SHORT(WinQueryWindowUShort(InstData->TargetHwnd, QWS_ID), LN_DMLB_REORDERED), MPFROMHWND(hwnd)); else WinSendMsg(WinQueryWindow(InstData->TargetHwnd, QW_OWNER), WM_CONTROL, MPFROM2SHORT(WinQueryWindowUShort(InstData->TargetHwnd, QWS_ID), LN_DMLB_INSERT_MOVE), MPFROMHWND(hwnd)); break; case DROPMODE_COPY: WinSendMsg(WinQueryWindow(InstData->TargetHwnd, QW_OWNER), WM_CONTROL, MPFROM2SHORT(WinQueryWindowUShort(InstData->TargetHwnd, QWS_ID), LN_DMLB_INSERT_COPY), MPFROMHWND(hwnd)); break; } return (MRESULT)TRUE; } } /* Call previous window procedure to process this message */ return ( (*(InstData->OldProcAddr)) ( hwnd, msg, mp1, mp2 ) ); }
BOOL OListBox::setToTop(const ULONG itemIndex) { return((BOOL)WinSendMsg(hwnd, LM_SETTOPINDEX, MPFROMSHORT(itemIndex), NULL)); }
static void AdjustControls(int NBPwidth, int NBPheight) { SWP swpTemp; int xsize, ysize; RECTL rectl; POINTL pointl; int buttonheight; ULONG CXDLGFRAME = WinQuerySysValue(HWND_DESKTOP, SV_CXDLGFRAME); ULONG CYDLGFRAME = WinQuerySysValue(HWND_DESKTOP, SV_CYDLGFRAME); // Query button height in pixels if (WinQueryWindowPos(WinWindowFromID(hwndConfigDlg, PB_DEFAULT), &swpTemp)) buttonheight = swpTemp.cy; else buttonheight = 0; // Set the size and position of Notebook // The size is interesting. We should know how much additional space this notebook requires. // For this, we calculate how big is a notebook for a known client size (e.g., 0x0) rectl.xLeft = 0; rectl.xRight = 0; rectl.yBottom = 0; rectl.yTop = 0; WinSendMsg(hwndConfigNB, BKM_CALCPAGERECT, MPFROMP(&rectl), MPFROMSHORT(FALSE)); // Ok, this must be added to client size in order to be able to display the given client dialog: NBPwidth += rectl.xRight; NBPheight += rectl.yTop; // Now check how much shift is inside the window: // (client/notebook shift) pointl.x = 0; pointl.y = 0; WinMapWindowPoints(hwndInterfaceNBP, hwndConfigNB, &pointl, 1); // Add this too: NBPwidth += pointl.x; NBPheight += pointl.y; // Notebook position is above the buttons, which is some pixels above the bottom of window: swpTemp.x = CXDLGFRAME+2; swpTemp.y = CYDLGFRAME + buttonheight + 5; // Notebook size is just calculated: swpTemp.cx = NBPwidth; swpTemp.cy = NBPheight; WinSetWindowPos(hwndConfigNB, HWND_TOP, swpTemp.x, swpTemp.y, swpTemp.cx, swpTemp.cy, SWP_MOVE | SWP_SIZE); // Ok, the notebook is resized. Now resize the dialog window to be just // as big as it's needed for the notebook: xsize = swpTemp.cx + CXDLGFRAME*2 + 2*2; ysize = swpTemp.cy + CYDLGFRAME*2 + buttonheight + 5 + WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR) + 5; WinSetWindowPos(hwndConfigDlg, HWND_TOP, 0, 0, xsize, ysize, SWP_SIZE); // Set the position of buttons // Undo Button WinQueryWindowPos(WinWindowFromID(hwndConfigDlg, PB_UNDO), &swpTemp); swpTemp.y = CYDLGFRAME+2; swpTemp.x = (xsize/6)*1-swpTemp.cx/2; WinSetWindowPos(WinWindowFromID(hwndConfigDlg, PB_UNDO), HWND_TOP, swpTemp.x, swpTemp.y, swpTemp.cx, swpTemp.cy, SWP_MOVE); // Default Button WinQueryWindowPos(WinWindowFromID(hwndConfigDlg, PB_DEFAULT), &swpTemp); swpTemp.y = CYDLGFRAME+2; swpTemp.x = (xsize/6)*3-swpTemp.cx/2; WinSetWindowPos(WinWindowFromID(hwndConfigDlg, PB_DEFAULT), HWND_TOP, swpTemp.x, swpTemp.y, swpTemp.cx, swpTemp.cy, SWP_MOVE); // Help Button WinQueryWindowPos(WinWindowFromID(hwndConfigDlg, PB_HELP), &swpTemp); swpTemp.y = CYDLGFRAME+2; swpTemp.x = (xsize/6)*5-swpTemp.cx/2; WinSetWindowPos(WinWindowFromID(hwndConfigDlg, PB_HELP), HWND_TOP, swpTemp.x, swpTemp.y, swpTemp.cx, swpTemp.cy, SWP_MOVE); // That's all! }
/**************************************************************************** * ClientWndProc * * - Typical PM client window procedure. (see below) * * - Standard client window I/O * ****************************************************************************/ MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { RECTL rcl; SWP swp; HPS hpsPaint; static HPS hps; /* Permanent HPS */ static INT cx, cy; /* Client window dimensions */ static BOOL bSlowUpdateNow = FALSE; /* Update toggle for asteroids * * and enemy which are slow. */ static POINTL ptlCenter; /* Center of client window */ switch (msg) { /* Recieved from WinCreateStdWindow */ case WM_CREATE: /* Get permanent PS for entire window */ hps = WinGetPS(hwnd); /* Load private Asteroid fonts from ASTEROID.DLL */ if (GpiLoadFonts(hab, "ASTEROID") != GPI_OK) { WinReleasePS(hps); WinAlarm(HWND_DESKTOP, WA_WARNING); WinMessageBox(HWND_DESKTOP,NULLHANDLE, "Please put ASTEROID.DLL in a directory in your LIBPATH.", "Error reading ASTEROID.DLL", 0,MB_ICONHAND|MB_OK|MB_APPLMODAL); WinPostMsg(hwnd,WM_QUIT,(MPARAM) 0L,(MPARAM) 0L); return (MRESULT) TRUE; } /* Register/create logical fonts for use */ InitFonts(hps); /* Display About dialoge box */ WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL); return 0; /* Recieved during attract mode when user starts game */ case WM_STARTGAME: /* Determine the number of players */ cPlayers = (INT)LONGFROMMP(mp1); /* Initialize each player */ for (Player=0;Player<cPlayers;Player++) { Level[Player] = 1; Ships[Player] = prfProfile.iSHIPS; DeletePhotons(); InitAsteroids(); InitEnemy(); } /* Start with player 1 */ Player = 0; iGameMode = GAME_MODE_NEXT; iGameModeCnt = GAME_PAUSE_TIME-1; /* Hide the pointer if mouse controls are enabled */ ShowMouse(FALSE); /* Paint everything */ WinSendMsg(hwnd, WM_PAINT, MPVOID, MPVOID); return 0; /* Recieved at startup and at the completion of a game */ case WM_INITGAME: /* Make mouse visible if we hid it before */ ShowMouse(TRUE); /* Fix menu to reflect attract mode */ EnableMenuItem(hwndMenu, IDM_START, TRUE); EnableMenuItem(hwndMenu, IDM_STOP, FALSE); /* Initialize player and enemy data structures */ cPlayers = 0; Level[0] = 1; for (Player=0;Player<2;Player++) { Score[Player] = 0L; Ships[Player] = 0; DeletePhotons(); } Player = 0; /* Initialize asteroids (and enemy) for attract mode */ InitAsteroids(); InitEnemy(); /* Depending on whether ASTEROID was just started or a game just * * completed display the "High Score" or "Press 1 or 2" screen. */ if (SHORT1FROMMP(mp1) == 0) { iGameMode = GAME_MODE_INIT1; iGameModeCnt = GAME_INIT_TIME; } else { iGameMode = GAME_MODE_INIT2; iGameModeCnt = GAME_INIT_TIME; } /* Paint everything */ WinSendMsg(hwnd, WM_PAINT, MPVOID, MPVOID); return 0; /* Usually recieved from the system, sometime forced by the program to * * ensure the screen is not corrupt. */ case WM_PAINT: /* Clear entire window to insure no "droppings" */ WinQueryWindowRect(hwnd,&rcl); WinFillRect(hps, &rcl, CLR_BLACK); WinInvalidateRect(hwnd, &rcl, FALSE); /* Get the update region and paint it black */ hpsPaint = WinBeginPaint(hwnd, (HPS)NULL, &rcl); WinFillRect(hpsPaint, &rcl, CLR_BLACK); WinEndPaint(hpsPaint); /* Only in normal play mode should we draw the ship */ if ((iGameMode == GAME_MODE_PLAY) && (iShipMode[Player] != EXPLOSION) && (iShipMode[Player] != HYPERSPACE)) DrawShip(hps, cx, cy, DRAW_INIT); else if ((iGameMode == GAME_MODE_PLAY) && (iShipMode[Player] == EXPLOSION)) ExplodeShip(hps, cx, cy); /* Draw the enemy if it is on the screen */ if (iEnemyMode[Player] != NONE) if (iEnemyMode[Player] != EXPLOSION) DrawEnemy(hps, cx, cy,DRAW_INIT); else ExplodeEnemy(hps, cx, cy); /* Draw photons and asteroids in all modes but the "Enter your * * initials" mode, otherwise draw that screen. */ if (iGameMode != GAME_MODE_HIGH) { DrawPhotons(hps, cx, cy, DRAW_INIT); DrawAsteroids(hps, cx, cy, DRAW_INIT); } else DrawHighScore(hps, cx, cy, DRAW_INIT); /* Always draw the score */ DrawScore(hps, cx, cy, DRAW_INIT); return 0; /* Left mouse button down. This simulates the move/track function * * in the system menu. */ case WM_BUTTON1DOWN: if (prfProfile.bMOUSECONTROL && iGameMode != GAME_MODE_INIT1 && iGameMode != GAME_MODE_INIT2 && !TogglePause(CHECK)) { UPDATE_FIRE(iShipMode[Player], TRUE); return (MRESULT)TRUE; } return WinSendMsg(hwndFrame, WM_TRACKFRAME, (MPARAM) (SHORT1FROMMP(mp2) | TF_MOVE), MPVOID); case WM_BUTTON1UP: if (prfProfile.bMOUSECONTROL) { UPDATE_FIRE(iShipMode[Player], FALSE); return (MRESULT)TRUE; } return 0; /* Left mouse button double clicked. Toggle frame control display. */ case WM_BUTTON1DBLCLK: if (!prfProfile.bMOUSECONTROL || iGameMode == GAME_MODE_INIT1 || iGameMode == GAME_MODE_INIT2 || TogglePause(CHECK)) { if (prfProfile.bCONTROLS = !prfProfile.bCONTROLS) ShowFrameControls(); else HideFrameControls(); } return 0; case WM_BUTTON2DOWN: if (prfProfile.bMOUSECONTROL) { UPDATE_SHIELD(iShipMode[Player], iShipShieldCnt[Player]); return (MRESULT)TRUE; } return 0; case WM_BUTTON2CLICK: if (prfProfile.bMOUSECONTROL) { UPDATE_HYPERSPACE(iShipMode[Player], iShipModeCnt[Player]); return (MRESULT)TRUE; } return 0; /* Right mouse button double clicked. Display the about dialog box. */ case WM_BUTTON2DBLCLK: if (!prfProfile.bMOUSECONTROL || iGameMode == GAME_MODE_INIT1 || iGameMode == GAME_MODE_INIT2 || TogglePause(CHECK)) { WinDlgBox(HWND_DESKTOP, hwndClient, (PFNWP)AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL); } return 0; /* User typed a key. Most of this is self explanatory. */ case WM_CHAR: ProcessChar((CHAR) (CHARMSG(&msg)->vkey-1), CHARMSG(&msg)->fs & KC_VIRTUALKEY, (CHAR) (CHARMSG(&msg)->chr), (BOOL) !(CHARMSG(&msg)->fs & KC_KEYUP)); return 0; /* User entered a command via the menu bar. */ case WM_COMMAND: DoCommand(hwnd, msg, mp1, mp2); return 0; /* Suspend/un-suspend game depending on focus */ case WM_SETFOCUS: if ((BOOL) SHORT1FROMMP(mp2)) TogglePause(SUSPEND_OFF); else if (!prfProfile.bBACKGRND) TogglePause(SUSPEND_ON); return 0; /* Keep track of the client window size. Profile information is not * * updated here because there are better places (i.e. at exit) */ case WM_SIZE: cx = (INT)SHORT1FROMMP(mp2); cy = (INT)SHORT2FROMMP(mp2); /* Keep track of client window position. Also updates profile info. */ case WM_MOVE: WinQueryWindowPos(hwndFrame,&swp); if (!(swp.fl & SWP_MAXIMIZE) && !(swp.fl & SWP_MINIMIZE)) { prfProfile.x = swp.x;prfProfile.y = swp.y; prfProfile.cx = swp.cx;prfProfile.cy = swp.cy; } if (swp.fl & SWP_MINIMIZE) if (!prfProfile.bBACKGRND) { /* Set icon */ WinSendMsg(hwndFrame, WM_SETICON, (MPARAM) WinLoadPointer(HWND_DESKTOP, NULLHANDLE, ID_RESOURCE), MPVOID); TogglePause(SUSPEND_ON); } else WinSendMsg(hwndFrame, WM_SETICON, MPVOID, MPVOID); else TogglePause(SUSPEND_OFF); ptlCenter.x = swp.cx / 2; ptlCenter.y = swp.cy / 2; WinMapWindowPoints(hwndClient, HWND_DESKTOP, &ptlCenter, 1L); return 0; /* Recieved approximately 31 times a second. This is the longest and * * ugliest of the messages, partly because there are so many cases * * to keep track of, partly because it must be highly optimized. */ case WM_TIMER: if (prfProfile.bMOUSECONTROL && iGameMode != GAME_MODE_INIT1 && iGameMode != GAME_MODE_INIT2) { POINTL ptl; static BOOL bUp, bLeft, bRight; WinQueryPointerPos(HWND_DESKTOP, &ptl); if (bUp || (ptl.y - ptlCenter.y > 0)) UPDATE_THRUST(iShipMode[Player], bUp = (ptl.y - ptlCenter.y > 0)); if (bLeft || (ptlCenter.x - ptl.x > 0)) UPDATE_LEFT(iShipMode[Player], bLeft = (ptlCenter.x - ptl.x > 0)); if (bRight || (ptlCenter.x - ptl.x < 0)) UPDATE_RIGHT(iShipMode[Player], bRight = (ptlCenter.x - ptl.x < 0)); WinSetPointerPos(HWND_DESKTOP, ptlCenter.x, ptlCenter.y); } /* Determine the current game mode */ switch (iGameMode) { /* Either initialization/attract mode screen. */ case GAME_MODE_INIT1: case GAME_MODE_INIT2: /* Switch screens when count expires */ if (--iGameModeCnt == 0) { if (iGameMode == GAME_MODE_INIT1) iGameMode = GAME_MODE_INIT2; else iGameMode = GAME_MODE_INIT1; iGameModeCnt = GAME_INIT_TIME; /* Score must be redrawn because the attract mode screens * * draw the score differently. */ DrawScore(hps, cx, cy, DRAW_REINIT); } /* Update photons, asteroids, enemy, and score */ UpdatePhotons(hps, cx, cy); if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { UpdateAsteroids(hps, cx, cy); UpdateEnemy(hps, cx, cy); DrawScore(hps, cx, cy, DRAW_REFRESH); } break; /* Completion of one player's turn or new game */ case GAME_MODE_NEXT: /* Initially, erase and redraw everything for new player */ if (iGameModeCnt-- == GAME_PAUSE_TIME) { if ((cPlayers == MAXPLAYERS) && (Ships[(Player+1) % MAXPLAYERS])) { DrawAsteroids(hps, cx, cy, DRAW_ERASE); DrawPhotons(hps, cx, cy, DRAW_ERASE); Player = (Player+1) % MAXPLAYERS; } DrawScore(hps, cx, cy, DRAW_REINIT); DrawAsteroids(hps, cx, cy, DRAW_INIT); } /* During countdown update score and asteroids */ else if (iGameModeCnt > 0) { if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { DrawScore(hps, cx, cy, DRAW_REFRESH); UpdateAsteroids(hps, cx, cy); } } /* At end of countdown start the player */ else { InitShip(); InitEnemy(); iGameMode = GAME_MODE_PLAY; DrawScore(hps, cx, cy, DRAW_REINIT); } break; /* Normal play mode */ case GAME_MODE_PLAY: /* Update ship, photons, asteroids, enemy, and score */ UpdateShip(hps, cx, cy); UpdatePhotons(hps, cx, cy); if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { UpdateAsteroids(hps, cx, cy); UpdateEnemy(hps, cx, cy); /* Erase old and draw new scores if there is a change*/ if (bChangeScore) { bChangeScore = FALSE; DrawScore(hps, cx, cy, DRAW_REINIT); } /* Else just refresh the score */ else DrawScore(hps, cx, cy, DRAW_REFRESH); } break; /* Game over mode. This is the longest and ugliest case because * * conditions are highly dependent on the number of players, * * multiplayer game status, and the number and order of high * * scores. */ case GAME_MODE_OVER: /* Initially, just update the score and number of ships */ if (iGameModeCnt-- == GAME_PAUSE_TIME) DrawScore(hps, cx, cy, DRAW_REINIT); /* During countdown refresh the score and update the asteroids */ else if (iGameModeCnt > 0) { if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) { DrawScore(hps, cx, cy, DRAW_REFRESH); UpdateAsteroids(hps, cx, cy); } } /* At the end of the countdown, if there are any other players, * * continue with them. */ else { /* Countinue on with any remaining players. */ if ((cPlayers == MAXPLAYERS) && (Ships[(Player+1) % MAXPLAYERS])) { /* Erase all of the old asteroids. */ DrawAsteroids(hps, cx, cy, DRAW_ERASE); /* Setup everything for the next player */ Player = (Player+1) % MAXPLAYERS; InitShip(); InitEnemy(); iGameMode = GAME_MODE_PLAY; DrawAsteroids(hps, cx, cy, DRAW_INIT); DrawScore(hps, cx, cy, DRAW_REINIT); } /* Check for new high scores and update table as necessary. */ else { /* Erase all of the old asteroids. */ DrawAsteroids(hps, cx, cy, DRAW_ERASE); /* The following if/else block is admittedly a kludge, it is * * simple and it does work, however. Ideally it should * * sort the high scores and update the high score table in * * descending order. */ /* If player 1 scored higher than player 2 then check * * player 1 first for a high score. */ if (Score[0] > Score[1]) for (Player=0;Player<cPlayers;Player++) /* If the player's score is > than the lowest, * * update the high score table. */ if (Score[Player] > prfProfile.lSCORES[9]) { UpdateHighScores(); iGameMode = GAME_MODE_HIGH; } /* Otherwise, make sure he is not asked for his * * initials. */ else Score[Player] = 0; /* Otherwise, check player 2 first */ else for (Player=cPlayers;Player>=0;Player--) /* If the player's score is > than the lowest, * * update the high score table. */ if (Score[Player] > prfProfile.lSCORES[9]) { UpdateHighScores(); iGameMode = GAME_MODE_HIGH; } /* Otherwise, make sure he is not asked for his * * initials. */ else Score[Player] = 0L; /* If there was no high score, go into attract mode */ if (iGameMode != GAME_MODE_HIGH) WinSendMsg(hwnd,WM_INITGAME,MPFROMSHORT(1),(MPARAM) 0L); /* Else, check for player 1's initials first then 2's * * This is not faithful, in the arcade game the player * * with the higher score always goes first. */ else { if (Score[0] > 0L) Player = 0; else Player = 1; DrawScore(hps, cx, cy, DRAW_REINIT); DrawHighScore(hps, cx, cy, DRAW_INIT); } } } break; /* Mode which prompts players to enter their initials */ case GAME_MODE_HIGH: /* If the player's position is > 0 then refresh the screen */ if (Score[Player] > 0L) DrawHighScore(hps, cx, cy, DRAW_REFRESH); /* Else, the current player is done go to the next */ else if ((cPlayers == MAXPLAYERS) && (Player == 0) && (Score[1] > 0L)) { Player++; DrawHighScore(hps, cx, cy, DRAW_REINIT); } /* If there are no more high scores then go into attract mode */ else WinSendMsg(hwnd, WM_INITGAME, MPFROMSHORT(1), MPVOID); break; } return 0; /* Used by help manager */ case HM_QUERY_KEYS_HELP: return((MRESULT)IDH_CLIENTKEYS); /* Recieved always from the system or in the case of an initialization* * error. Both messages will normally save the profile information.* * Ideally the profile section should be moved to a subroutine and the* * the following should be broken into two distinct cases. */ case WM_SAVEAPPLICATION: case WM_DESTROY: /* If the fonts were not found bApplicationOk will be false, in * * that case the window profile information should not be updated.*/ if (TRUE) { /* Copy window position and size info into profile structure */ WinQueryWindowPos(hwndFrame, &swp); if (swp.fl & SWP_MAXIMIZE) prfProfile.ulMINMAX = SWP_MAXIMIZE; else if (swp.fl & SWP_MINIMIZE) prfProfile.ulMINMAX = SWP_MINIMIZE; else { prfProfile.ulMINMAX = 0; prfProfile.x = swp.x;prfProfile.y = swp.y; prfProfile.cx = swp.cx;prfProfile.cy = swp.cy; } /* Write profile information */ PrfWriteProfileData(HINI_USERPROFILE, szClientClass, "Data", &prfProfile, sizeof(PROFILEREC)); } /* If the application is terminating release the fonts and the hps. */ if (msg == WM_DESTROY) { /* Make sure mouse is visible if we hid it before */ ShowMouse(TRUE); /* Release font identifiers and DLL resource module */ GpiSetCharSet(hps, LCID_DEFAULT); GpiDeleteSetId(hps, LCID_LARGE); GpiDeleteSetId(hps, LCID_SMALL); GpiUnloadFonts(hab, "ASTEROID"); /* Release the "permanent" presentation space */ WinReleasePS(hps); } return 0; } return WinDefWindowProc(hwnd, msg, mp1, mp2); }
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); }
/* * * BrowseWndProc * * DESCRIPTION: * * Processes messages for the Browse-O-Matic client window. * */ MRESULT EXPENTRY BrowseWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { switch( msg){ case WM_CREATE: { CHAR pszTitle[ MAX_TITLE_LENGTH]; PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA)mp1; WinSetWindowPtr( hwnd, QWL_USER, pWindowData); /*******************/ /* Load the object */ /*******************/ _LoadObject( pWindowData->somSelf, pWindowData->pszObjectName, &pWindowData->ulFileLength, &pWindowData->pBuffer, &pWindowData->pLines, &pWindowData->usNumberOfTextLines, &pWindowData->usNumberOfTextColumns); _GetLinesAndColumns( pWindowData->somSelf, pWindowData->bDisplay, &pWindowData->sTotalLines, &pWindowData->sTotalColumns, pWindowData->usNumberOfTextLines, pWindowData->usNumberOfTextColumns, pWindowData->ulFileLength); /*********************************************/ /* Get the window handle for the scroll bars */ /*********************************************/ pWindowData->hwndVscroll = WinWindowFromID( WinQueryWindow( hwnd, QW_PARENT), FID_VERTSCROLL); pWindowData->hwndHscroll = WinWindowFromID( WinQueryWindow( hwnd, QW_PARENT), FID_HORZSCROLL); /*************************/ /* Save font information */ /*************************/ WinSendMsg( hwnd, IDL_SETFONTINFO, (MPARAM)0, (MPARAM)0); /*****************/ /* Get the focus */ /*****************/ WinSetFocus( HWND_DESKTOP, hwnd); /*****************************************************/ /* Create the title for the Browse-O-Matic title bar */ /*****************************************************/ if( pWindowData->bDisplay == PMBROWSE_HEX_DISPLAY_MODE) sprintf( pszTitle, "Object: %s (%d Bytes)", pWindowData->pszObjectName, pWindowData->ulFileLength); else sprintf( pszTitle, "Object: %s (%hd Lines)", pWindowData->pszObjectName, pWindowData->sTotalLines); /************************************************/ /* Register the current open view of the object */ /************************************************/ _wpAddToObjUseList( pWindowData->somSelf, &(pWindowData->UseItem)); _wpRegisterView( pWindowData->somSelf, WinQueryWindow( hwnd, QW_PARENT), pszTitle); } break; case WM_CLOSE: { HWND hwndFrame; PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); hwndFrame = WinQueryWindow( hwnd, QW_PARENT); /*****************************************************/ /* Save the window info - size, location, and fonts. */ /*****************************************************/ WinStoreWindowPos( APPL_NAME, pWindowData->pszApplKey, hwndFrame); /**********************************************************/ /* Free the window data and unload the file system object */ /**********************************************************/ if( pWindowData){ if( pWindowData->pszObjectName) _wpFreeMem( pWindowData->somSelf, ( PBYTE)pWindowData->pszObjectName); _wpFreeMem( pWindowData->somSelf, ( PBYTE)pWindowData); } _UnloadObject( pWindowData->somSelf, pWindowData->pBuffer, pWindowData->pLines); _wpDeleteFromObjUseList( pWindowData->somSelf, &pWindowData->UseItem); /*******************/ /* Kill the window */ /*******************/ WinPostMsg( hwnd, WM_QUIT, 0, 0 ); WinDestroyWindow( hwndFrame); } break; /*******************************************************************/ /* The font characteristics have changed. This happens when a font */ /* from the font palette is dropped on the client window. */ /*******************************************************************/ case WM_PRESPARAMCHANGED: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); if( (ULONG)mp1 == PP_FONTNAMESIZE){ /***********************************************/ /* Get the new font information and redraw the */ /* window with the new font/font size. */ /***********************************************/ WinSendMsg( hwnd, IDL_SETFONTINFO, (MPARAM)0, (MPARAM)0); WinSendMsg( hwnd, WM_SIZE, 0, MPFROM2SHORT( pWindowData->sClientWidth, pWindowData->sClientHeight)); } } break; case WM_SIZE: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); /***************************************/ /* Save client window size information */ /***************************************/ pWindowData->sClientWidth = SHORT1FROMMP( mp2); pWindowData->sClientHeight = SHORT2FROMMP( mp2); pWindowData->sPageHeight = pWindowData->sClientHeight/ pWindowData->sCharHeight; pWindowData->sPageWidth = pWindowData->sClientWidth / pWindowData->sCharWidth; /**************************************/ /* Set the ranges for the scroll bars */ /**************************************/ WinPostMsg( pWindowData->hwndVscroll, SBM_SETSCROLLBAR, (MPARAM)pWindowData->sCurrentLine, MPFROM2SHORT( 0, pWindowData->sTotalLines - pWindowData->sPageHeight)); WinPostMsg( pWindowData->hwndHscroll, SBM_SETSCROLLBAR, (MPARAM)pWindowData->sCurrentColumn, MPFROM2SHORT( 0, pWindowData->sTotalColumns - pWindowData->sPageWidth)); /*************************************/ /* Set scroll bar thumb control size */ /*************************************/ WinPostMsg( pWindowData->hwndVscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT( pWindowData->sPageHeight, pWindowData->sTotalLines), (MPARAM) 0); WinPostMsg( pWindowData->hwndHscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT( pWindowData->sPageWidth, pWindowData->sTotalColumns), (MPARAM) 0); /************************************************************/ /* If the all the lines and/or columns can fit in the new */ /* sized window, set the sCurrentLine and/or sCurrentColumn */ /* to the top/right side. */ /************************************************************/ if( pWindowData->sPageHeight >= pWindowData->sTotalLines) pWindowData->sCurrentLine = 0; if( pWindowData->sPageWidth >= pWindowData->sTotalColumns) pWindowData->sCurrentColumn = 0; /********************************************/ /* Repaint window with new size information */ /********************************************/ WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case WM_PAINT: { HPS hps; CHAR pszText[255]; UINT nLength = 0; RECTL rect; POINTL point; SHORT sLine; SHORT sTopLine; SHORT sBottomLine; SHORT sLinesFromTop; PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); hps = WinBeginPaint( hwnd, NULLHANDLE, &rect); /*******************************************/ /* Clear the area that needs to be redrawn */ /*******************************************/ GpiErase( hps); /********************************/ /* Determine first clipped line */ /********************************/ sLinesFromTop = ( pWindowData->sClientHeight - rect.yTop) / pWindowData->sCharHeight; rect.yTop = pWindowData->sClientHeight - ( pWindowData->sCharHeight * sLinesFromTop); /***************************************************************/ /* Determine the first position to write at. NOTE: PM handles */ /* clipping for point.x < 0. Any characters written before the */ /* the first column or after the last column are clipped. */ /***************************************************************/ point.y = rect.yTop - pWindowData->sCharHeight + pWindowData->sCharDescender; point.x = pWindowData->sCurrentColumn*pWindowData->sCharWidth * -1; /***********************************************/ /* Determine the top and bottom lines to write */ /***********************************************/ sTopLine = rect.yTop / pWindowData->sCharHeight; sBottomLine = rect.yBottom / pWindowData->sCharHeight; /*********************************************************/ /* Make sure that we aren't trying to display more lines */ /* then are available. */ /*********************************************************/ if( pWindowData->sPageHeight - sBottomLine + 1 > pWindowData->sTotalLines - pWindowData->sCurrentLine) sBottomLine=pWindowData->sPageHeight-(pWindowData->sTotalLines - pWindowData->sCurrentLine) + 1; /********************************/ /* Redraw the invalid rectangle */ /********************************/ for( sLine = sTopLine; sLine >= sBottomLine; sLine--){ /*******************************************/ /* Get the line of text or hex information */ /* that we are going to write. */ /*******************************************/ if( pWindowData->bDisplay == PMBROWSE_HEX_DISPLAY_MODE) nLength = _GetHexLine( pWindowData->somSelf, pWindowData->sPageHeight-sLine+pWindowData->sCurrentLine +1, pWindowData->pBuffer, pWindowData->ulFileLength, pszText); else nLength = _GetTextLine( pWindowData->somSelf, pWindowData->sPageHeight-sLine+pWindowData->sCurrentLine +1, pWindowData->pLines, pszText); /******************/ /* Write the text */ /******************/ if( nLength != 0) GpiCharStringAt( hps, &point, nLength, pszText); point.y -= pWindowData->sCharHeight; } WinEndPaint( hps); } return( 0); /*******************************************/ /* Keyboard support for scrolling and help */ /*******************************************/ case WM_CHAR: /****************************************/ /* Show general help if user selects F1 */ /****************************************/ if( CHARMSG( &msg)->vkey == VK_F1){ PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); _wpDisplayHelp( pWindowData->somSelf, PANEL_MAIN, "browse.hlp"); return 0; } if( (CHARMSG( &msg)->fs & KC_KEYUP)) return 0; switch( CHARMSG( &msg)->vkey){ case VK_UP: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_LINEUP)); return 0; case VK_DOWN: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_LINEDOWN)); return 0; case VK_RIGHT: /************************************************************/ /* Ctrl-Right scrolls one page to the right. Right scrolls */ /* to the right. */ /************************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)) WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT(0, SB_PAGERIGHT)); else WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT(0, SB_LINERIGHT)); return 0; case VK_LEFT: /*********************************************************/ /* Ctrl-Left scrolls one page to the left. Left scrolls */ /* to the Left. */ /*********************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)) WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT( 0, SB_PAGELEFT)); else WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT( 0, SB_LINELEFT)); return 0; case VK_PAGEUP: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_PAGEUP)); return 0; case VK_PAGEDOWN: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_PAGEDOWN)); return 0; case VK_HOME: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); /*********************************************************/ /* Ctrl-Home positions at the first line, Home positions */ /* at the beginning of the current line. */ /*********************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)){ WinPostMsg( hwnd, WM_VSCROLL, (MPARAM)0, MPFROM2SHORT( 0, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, MPFROMSHORT( 0), 0); } else{ WinPostMsg( hwnd, WM_HSCROLL, (MPARAM)0, MPFROM2SHORT( 0, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, MPFROMSHORT( 0), 0); } return 0; } case VK_END: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); /*********************************************************/ /* Ctrl-End positions at the last line, End positions at */ /* the end of the current line. */ /*********************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)){ WinPostMsg( hwnd, WM_VSCROLL, (MPARAM)0, MPFROM2SHORT( pWindowData->sTotalLines - pWindowData->sPageHeight, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, MPFROMSHORT( pWindowData->sTotalLines - pWindowData->sPageHeight), 0); } else{ WinPostMsg( hwnd, WM_HSCROLL, (MPARAM)0, MPFROM2SHORT( pWindowData->sTotalColumns - pWindowData->sPageWidth, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, MPFROMSHORT( pWindowData->sTotalColumns - pWindowData->sPageWidth), 0); } return 0; } } break; /******************/ /* Scroll Up/Down */ /******************/ case WM_VSCROLL: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); switch( SHORT2FROMMP( mp2)){ case SB_LINEUP: if( pWindowData->sCurrentLine > 0){ pWindowData->sCurrentLine--; WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine, 0); WinScrollWindow( hwnd, 0, pWindowData->sCharHeight * -1, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_LINEDOWN: if( pWindowData->sCurrentLine < pWindowData->sTotalLines - pWindowData->sPageHeight){ pWindowData->sCurrentLine++; WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine, 0); WinScrollWindow( hwnd, 0, pWindowData->sCharHeight, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_PAGEUP: if( pWindowData->sCurrentLine > 0){ pWindowData->sCurrentLine = max( 0, pWindowData->sCurrentLine - pWindowData->sPageHeight); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine,0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_PAGEDOWN: if( pWindowData->sCurrentLine < pWindowData->sTotalLines - pWindowData->sPageHeight){ pWindowData->sCurrentLine= min( pWindowData->sTotalLines - pWindowData->sPageHeight, pWindowData->sCurrentLine + pWindowData->sPageHeight); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine,0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_SLIDERPOSITION: /***********************************************************/ /* Can't change current line if all the text fits in the */ /* window. */ /***********************************************************/ if( pWindowData->sTotalLines > pWindowData->sPageHeight){ pWindowData->sCurrentLine = SHORT1FROMMP( mp2); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); } } break; /*********************/ /* Scroll Right/Left */ /*********************/ case WM_HSCROLL: { PBROWSEDATA pWindowData; pWindowData = ( PBROWSEDATA)WinQueryWindowPtr( hwnd, QWL_USER); switch( SHORT2FROMMP( mp2)){ case SB_LINELEFT: if( pWindowData->sCurrentColumn > 0){ pWindowData->sCurrentColumn = max( 0, pWindowData->sCurrentColumn - 1); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn,0); WinScrollWindow( hwnd, pWindowData->sCharWidth, 0, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_LINERIGHT: if(pWindowData->sCurrentColumn < pWindowData->sTotalColumns - pWindowData->sPageWidth){ pWindowData->sCurrentColumn=min(pWindowData->sTotalColumns, pWindowData->sCurrentColumn + 1); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn, 0); WinScrollWindow( hwnd, pWindowData->sCharWidth * -1, 0, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_PAGELEFT: if( pWindowData->sCurrentColumn > 0){ pWindowData->sCurrentColumn = max( 0, pWindowData->sCurrentColumn - pWindowData->sPageWidth); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn, 0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_PAGERIGHT: if(pWindowData->sCurrentColumn < pWindowData->sTotalColumns - pWindowData->sPageWidth){ pWindowData->sCurrentColumn=min(pWindowData->sTotalColumns - pWindowData->sPageWidth, pWindowData->sCurrentColumn + pWindowData->sPageWidth); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn, 0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_SLIDERPOSITION: /***********************************************************/ /* Can't change current column if all the text fits in the */ /* window. */ /***********************************************************/ if( pWindowData->sTotalColumns > pWindowData->sPageWidth){ pWindowData->sCurrentColumn = SHORT1FROMMP( mp2); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); } } break; /*****************************/ /* Get font size information */ /*****************************/ case IDL_SETFONTINFO: { HPS hps; FONTMETRICS fm; PBROWSEDATA pWindowData; pWindowData = ( PBROWSEDATA)WinQueryWindowPtr( hwnd, QWL_USER); hps = WinGetPS( hwnd); GpiQueryFontMetrics( hps, sizeof( fm), &fm); WinReleasePS( hps); /***********************************************************/ /* The character width is average of the average uppercase */ /* and average lower case widths. */ /***********************************************************/ pWindowData->sCharWidth = (SHORT)fm.lMaxCharInc; pWindowData->sCharHeight = (SHORT)fm.lMaxBaselineExt; pWindowData->sCharDescender = (SHORT)fm.lMaxDescender; } return( 0); /*********************************************/ /* Display no help available message to user */ /*********************************************/ case HM_HELPSUBITEM_NOT_FOUND: return( ( MRESULT)FALSE); /**************************************/ /* Return name of help for keys panel */ /**************************************/ case HM_QUERY_KEYS_HELP: return( ( MRESULT)PANEL_HELPKEYS); } /********************************************************/ /* Let the default window procedure process the message */ /********************************************************/ return( WinDefWindowProc( hwnd, msg, mp1, mp2)); }