//=========================================================================== // // Parameters -------------------------------------------------------------- // HWND hwnd : window handle // VOID // Return value ------------------------------------------------------------ // BOOL : TRUE/FALSE (success/error) // VOID //=========================================================================== static VOID endHelp(HWND hwnd, HWND hHlp) { if (hHlp) { WinAssociateHelpInstance(NULLHANDLE, hwnd); WinDestroyHelpInstance(hHlp); } /* endif */ }
/****************************************************************\ * Destroys the help instance *-------------------------------------------------------------- * * Name: DestroyHelpInstance(VOID) * * Purpose: Destroys the help instance for the application * * Usage: Called after exit from message loop * * Method: Calls WinDestroyHelpInstance() to destroy the * help instance * * Returns: * \****************************************************************/ VOID DestroyHelpInstance(PAGECFG *pstCFG) { WinReleaseHook(pstCFG->hab,HMQ_CURRENT,HK_HELP,(PFN)pfnMessageBoxHelpHook,0L); if(hwndHelpInstance) WinDestroyHelpInstance(hwndHelpInstance); hwndHelpInstance = 0; }
static gui_help_instance InitHelp( HWND hwnd, WPI_INST inst, char *title, char *help_lib ) { HWND hwndHelpInstance; HELPINIT help; help.cb = sizeof( HELPINIT ); help.pszTutorialName = NULL; help.phtHelpTable = NULL; help.hmodHelpTableModule = 0; help.hmodAccelActionBarModule = 0; help.idAccelTable = 0; help.idActionBar = 0; help.pszHelpWindowTitle = title; #ifdef __FLAT__ help.fShowPanelId = CMIC_HIDE_PANEL_ID; #else help.usShowPanelId = CMIC_HIDE_PANEL_ID; #endif help.pszHelpLibraryName = help_lib; hwndHelpInstance = WinCreateHelpInstance( inst.hab, &help ); if( hwndHelpInstance != (HWND)NULL ) { if( !WinAssociateHelpInstance( hwndHelpInstance, hwnd ) ) { WinDestroyHelpInstance( hwndHelpInstance ); hwndHelpInstance = NULLHANDLE; } } return( (gui_help_instance)hwndHelpInstance ); }
/************************************************************************** * * Name : HelpDestroyInstance() * * Description: Destroys the help instance for the application * * Concepts : Called during Exit list processing * * Calls WinDestroyHelpInstance() to destroy the * help instance * * API's : WinDestroyHelpInstance * * Parameters : [none] * * Return : [none] * *************************************************************************/ VOID HelpDestroyInstance(VOID) { if(hwndHelpInstance != 0L) { WinDestroyHelpInstance(hwndHelpInstance); } vfHelpEnabled = FALSE; } /* End of HelpDestroyInstance */
static void FiniHelp( gui_help_instance inst, HWND hwnd, char *file ) { hwnd=hwnd; file=file; if( (HWND)inst != (HWND)NULL ) { WinAssociateHelpInstance( (HWND)inst, NULLHANDLE ); WinDestroyHelpInstance( (HWND)inst ); } }
/*--------------------------------------------------------------------------------------*\ * Procedure to close a window and its message queue. * * Req: * * pHwndHelp ..... A pointer to HELP window handle * * pHab .......... A pointer to extract the anchor block of the window * * pHmq .......... A pointer to extract message queue of the window * * Returns: * * TRUE/FALSE .... If called sucessfully/unsucessfully * \*--------------------------------------------------------------------------------------*/ BOOL WinCloseDown(HWND *pHwndHelp, HAB *pHab, HMQ *pHmq) { if(!*pHwndHelp) /* Release HELP */ WinDestroyHelpInstance(*pHwndHelp); if(*pHmq!=NULLHANDLE) /* Release handle of message queue */ WinDestroyMsgQueue(*pHmq); if(*pHab!=NULLHANDLE) /* Release handle of anchor block */ WinTerminate(*pHab); /* Any error during WinStartUp */ if((*pHab==NULLHANDLE) || (*pHmq==NULLHANDLE)) return(FALSE); else return(TRUE); }
HWND HlpInit( HWND hwnd, HMODULE hmod, USHORT idHelpTable, const CHAR *szHelpFile, const CHAR *szTitle ) { HAB hab = WinQueryAnchorBlock(hwnd); HWND hwndHelp; CHAR sz[256+1]; hinit.cb = sizeof(HELPINIT); hinit.ulReturnCode = 0L; /* HELPTABLE resource handle */ hinit.hmodHelpTableModule = hmod; hinit.phtHelpTable = (HELPTABLE *) (0xffff0000L | idHelpTable); /* Help window title bar */ strcpy(sz, szTitle); strcat(sz, " Help"); hinit.pszHelpWindowTitle = sz; /* Not showing panel IDs */ hinit.fShowPanelId = CMIC_HIDE_PANEL_ID; /* No tutorial program */ hinit.pszTutorialName = NULL; /* Action bar is not tailored */ hinit.hmodAccelActionBarModule = (HMODULE) NULL; hinit.idAccelTable = (USHORT) NULL; hinit.idActionBar = (USHORT) NULL; /* No default librarys */ hinit.pszHelpLibraryName = ""; if ( (hwndHelp = WinCreateHelpInstance(hab, &hinit)) == (HWND) NULL ) { HlpWarning(hwnd, "Unable to create help instance"); return ( (HWND) NULL ); } if ( WinSendMsg(hwndHelp, HM_SET_HELP_LIBRARY_NAME, MPFROMP(szHelpFile), NULL) ) { WinDestroyHelpInstance(hwndHelp); HlpWarning(hwnd, "Unable to find help libraries"); return ( (HWND) NULL ); } return ( hwndHelp ); }
//=========================================================================== // // Parameters -------------------------------------------------------------- // HWND hwnd : window handle // VOID // Return value ------------------------------------------------------------ // BOOL : TRUE/FALSE (success/error) // VOID //=========================================================================== static HWND initHelp(HWND hwnd) { HWND hHlp; CHAR buf[256]; HELPINIT hi; memset(&hi, 0, sizeof(HELPINIT)); hi.cb = sizeof(HELPINIT); hi.phtHelpTable = PHLPTBLFROMID(HLP_MAIN); hi.pszHelpWindowTitle = SZ_TITLE; hi.fShowPanelId = CMIC_HIDE_PANEL_ID; hi.pszHelpLibraryName = SZFILE_HLP; if (!(hHlp = WinCreateHelpInstance(WinQueryAnchorBlock(hwnd), &hi))) return NULLHANDLE; if (hi.ulReturnCode) { WinDestroyHelpInstance(hHlp); hHlp = NULLHANDLE; } else { WinAssociateHelpInstance(hHlp, hwnd); } /* endif */ return hHlp; }
int main( void ) { HAB hab; HMQ hmq; HWND hwndHelpInstance; /* Handle to Help window */ HWND hwndDlg; // Main dlg window static SWCNTRL swctl; freopen ("err", "w", stderr); assert ((hab = WinInitialize (0)) != 0); assert ((hmq = WinCreateMsgQueue (hab, 0)) != 0); // Load main application dialog hwndDlg = WinLoadDlg (HWND_DESKTOP, HWND_DESKTOP, AirTrafficControlDlg, 0, IDDLG_CNRSAMP, 0); swctl.hwnd = hwndDlg; strcpy( swctl.szSwtitle, "Air Traffic Control Container" ); WinAddSwitchEntry( &swctl ); hwndHelpInstance = InitializeHelp (hab, hwndDlg, IDDLG_CNRSAMP, (PSZ) "atccnr.HLP", ( PSZ) "Air Traffic Control Container Help Window", 0); WinProcessDlg (hwndDlg); if (hwndHelpInstance) WinDestroyHelpInstance (hwndHelpInstance); WinDestroyWindow (hwndDlg); WinDestroyMsgQueue (hmq); WinTerminate (hab); return 0; }
/**************************************************************************** * Shutdown * * - Cleans up and terminates ASTEROID, returning any error conditions. * * - Receives error code. * ****************************************************************************/ VOID Shutdown(ULONG ulErrLevel) { /* Stop the timer. */ TogglePause(FORCE_PAUSE); /* Destroy the help instance if it was created */ if (hwndHelp != NULLHANDLE) { WinAssociateHelpInstance(NULLHANDLE, hwndFrame); WinDestroyHelpInstance(hwndHelp); } /* Destroy Object and Frame windows. */ if (hwndObject != NULLHANDLE) WinDestroyWindow(hwndObject); if (hwndFrame != NULLHANDLE) WinDestroyWindow(hwndFrame); /* Destroy the message queue and let PM clean up. */ WinDestroyMsgQueue(hmq); WinTerminate(hab); /* Return error code if any. */ DosExit(EXIT_PROCESS, ulErrLevel); }
/*...sHlpDeinit:0:*/ VOID HlpDeinit(HWND hwndHelp) { WinDestroyHelpInstance(hwndHelp); }
/************************************************************************** * * Name : main(argc, argv) * * Description: Initializes the application, gets and dispatches messages * for the client window on thread 1 and terminates the * application when a WM_QUIT message is received. It then * saves the configuration in os2.ini, destroys all OS/2 * PM resources, and terminates. * * The following routine is the Presentation Manager program * main body. The main body of a PM program is concerned with * associating the application with the Presentation Manager * system, creating its message queue, registering and displaying * its main window, servicing its message queue during the time * that the application is active, and disassociating the * application from PM when the user is finished with the * it. The remaining parts of this source module that are * concerned with the Presentation Manager are the application's * window procedures (main window procedure, child window * procedures, and dialog window procedures) that process the * messages associated with the application's various windows. * * Concepts : - obtains anchor block handle and creates message * queue * - creates the main frame window which creates the * main client window * - polls the message queue via Get/Dispatch Msg loop * - upon exiting the loop, exits * * API's : WinInitialize * WinCreateMsgQueue * WinRegisterClass * WinLoadString * WinCreateHelpInstance * WinMessageBox * WinCreateStdWindow * WinQueryWindowULong * WinAssociateHelpInstance * WinAddSwitchEntry * WinGetMsg * WinDispatchMsg * WinRemoveSwitchEntry * WinDestroyHelpInstance * WinDestroyWindow * WinDestroyMsgQueue * WinTerminate * * Parameters : [none] * * Return : Always returns zero. The ANSI standard requires that * main be declared as an INT. * *************************************************************************/ INT main(INT argc, CHAR **argv) { /* Define variables by type */ BOOL bOK; /* Boolean used for return code */ HAB hab; /* PM anchor block handle */ HMQ hmq; /* Message queue handle */ QMSG qmsg; /* Message from message queue */ ULONG ulCtlData; /* Standard window create flags */ HWND hwndFrame; /* Frame window handle */ HWND hwndClient; /* Client area window handle */ HWND hwndHelp; /* Help window handle */ PMAIN_PARM pmp; /* Main parameters structure */ SWCNTRL swctl; /* Struct to add to window list */ HSWITCH hsw; /* Window list handle ret'd */ HELPINIT hmi; /* Struct for help creation */ CHAR szWork[ LEN_WORKSTRING ]; /* General use string work area */ PSZ pszTitle; /* Pointer to program title */ /* normal PM application startup */ hab = WinInitialize( 0 ); hmq = WinCreateMsgQueue( hab, 0 ); /* * Register a class for my client window's behavior. * This class has enough extra window words to hold a pointer. */ bOK = WinRegisterClass( hab, CLASSNAME, WinProc, CS_SIZEREDRAW, sizeof( PMAIN_PARM )); /* * Ensure WinRegisterClass worked ok; if not, present a message box. * ( See pmassert.h. ) */ pmassert( hab, bOK ); /* Load program title and allocate a local copy. Use it in help creation. */ WinLoadString( hab, (HMODULE)NULLHANDLE, PROGRAM_TITLE, LEN_WORKSTRING, szWork ); pszTitle = strdup( szWork ); /* Create help. */ memset( &hmi, 0, sizeof( hmi )); hmi.cb = sizeof( HELPINIT ); hmi.phtHelpTable = (HELPTABLE *)(0xffff0000 | ID_PRTSAMP); hmi.pszHelpWindowTitle = pszTitle; hmi.pszHelpLibraryName = HELP_FILE; hwndHelp = WinCreateHelpInstance( hab, &hmi ); if( ! hwndHelp ) { WinLoadString(hab, (HMODULE)NULLHANDLE, ERRMSG_NO_HELP, LEN_WORKSTRING, szWork); WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, szWork, pszTitle, (USHORT)0, MB_OK | MB_MOVEABLE | MB_CUAWARNING | MB_APPLMODAL); } /* done with local copy of title text */ free( pszTitle ); /* flags to control creation of window; use on call to WinCreateStdWindow */ ulCtlData = FCF_SYSMENU | FCF_TITLEBAR | FCF_SIZEBORDER | FCF_MINMAX | FCF_MENU | FCF_ACCELTABLE | FCF_HORZSCROLL | FCF_VERTSCROLL; hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE | FS_ICON | FS_SHELLPOSITION, &ulCtlData, CLASSNAME, NULL, /* title text set in prtcreat.c */ 0, /* client style */ (HMODULE)NULLHANDLE, /* resources in exe */ ID_PRTSAMP, &hwndClient ); pmassert( hab, hwndFrame ); pmassert( hab, hwndClient ); /* create.c placed pointer to main params in client's window words; get it */ pmp = (PMAIN_PARM) WinQueryWindowULong( hwndClient, QWL_USER ); /* store help instance handle in main parameter block */ pmp->hwndHelp = hwndHelp; bOK = WinAssociateHelpInstance( hwndHelp, hwndFrame ); pmassert( hab, bOK ); /* Add program to task list. */ memset( &swctl, 0, sizeof( SWCNTRL )); strcpy( swctl.szSwtitle, pmp->pszTitle ); swctl.hwnd = hwndFrame; swctl.uchVisibility = SWL_VISIBLE; swctl.fbJump = SWL_JUMPABLE; hsw = WinAddSwitchEntry( &swctl ); /* first parameter could be a filename, so store for later use */ if (argc > 1) { argv++; strcpy( pmp->szArgFilename, *argv); } /* message loop */ while( WinGetMsg( hab, &qmsg, (HWND)NULLHANDLE, 0, 0 )) { WinDispatchMsg( hab, &qmsg ); } /* clean up */ WinRemoveSwitchEntry( hsw ); WinDestroyHelpInstance( hwndHelp ); WinDestroyWindow( hwndFrame ); WinDestroyMsgQueue( hmq ); WinTerminate( hab ); DosWaitThread( &pmp->tidObjectThread, DCWW_WAIT ); return 0; } /* End of main() */
Helper :: ~Helper (VOID) { if (hwndHelpInstance) WinDestroyHelpInstance (hwndHelpInstance); }
BOOL CALLBACK CDialogDlgProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) #endif { int i; class CDialog *dlgClass; CPC_MSGMAP_ENTRY *msgMap = NULL; #if defined(__OS2__) dlgClass = (class CDialog *)WinQueryWindowULong (hwnd, QWL_USER); #elif defined(__NT__) dlgClass = (class CDialog *)GetWindowLong (hwnd, GWL_USERDATA); #endif if (dlgClass != NULL) { dlgClass->m_msg = msg; #if defined(__OS2__) dlgClass->m_mp1 = mp1; dlgClass->m_mp2 = mp2; #elif defined(__NT__) dlgClass->m_wParam = wParam; dlgClass->m_lParam = lParam; #endif msgMap = dlgClass->GetMessageMap (); } switch (msg) { #if defined(__OS2__) case WM_INITDLG: { CDIALOG_DATA *cData = (CDIALOG_DATA *)mp2; #elif defined(__NT__) case WM_INITDIALOG: { CDIALOG_DATA *cData = (CDIALOG_DATA *)lParam; #endif dlgClass = cData->Dlg; dlgClass->m_hWnd = hwnd; dlgClass->lv_Selected = -1; #if defined(__OS2__) WinSetWindowULong (hwnd, QWL_USER, (ULONG)dlgClass); #elif defined(__NT__) SetWindowLong (hwnd, GWL_USERDATA, (LONG)dlgClass); #endif dlgClass->OnInitDialog (); #if defined(__OS2__) break; #elif defined(__NT__) return ((BOOL)TRUE); #endif } #if defined(__OS2__) case WM_CONTROL: for (i = 0; msgMap[i].pfn != NULL; i++) { if (msgMap[i].nMessage == msg) { if (msgMap[i].nID >= SHORT1FROMMP (mp1) && msgMap[i].nLastID <= SHORT1FROMMP (mp1)) { if (msgMap[i].nCode == SHORT2FROMMP (mp1)) { (dlgClass->*msgMap[i].pfn) (); break; } } } } return (0); #endif #if defined(__NT__) case WM_NOTIFY: { LPNMHDR pnmh = (LPNMHDR)lParam; NM_LISTVIEW *pnmv = (NM_LISTVIEW *)lParam; if (pnmh->code == NM_DBLCLK) dlgClass->OnOK (); else if (pnmh->code == LVN_ITEMCHANGED) { if (!(pnmv->uNewState & LVIS_SELECTED) && (pnmv->uOldState & LVIS_SELECTED)) dlgClass->lv_Selected = -1; if (pnmv->uNewState & LVIS_SELECTED) dlgClass->lv_Selected = (SHORT)pnmv->iItem; } else { for (i = 0; msgMap[i].pfn != NULL; i++) { if (msgMap[i].nMessage == msg && msgMap[i].nCode == pnmh->code) { if (msgMap[i].nID >= pnmh->idFrom && msgMap[i].nLastID <= pnmh->idFrom) { (dlgClass->*msgMap[i].pfn) (); break; } } } } return (0); } #endif #if defined(__OS2__) case WM_CHAR: if (SHORT1FROMMP (mp1) & KC_VIRTUALKEY && SHORT2FROMMP (mp2) == VK_F1) dlgClass->OnHelp (); break; #endif case WM_HELP: dlgClass->OnHelp (); break; /* #if defined(__OS2__) case WM_HELP: { USHORT id; HWND hwndHelpInstance; id = WinQueryWindowUShort (hwnd, QWS_ID); hwndHelpInstance = WinQueryHelpInstance (dlgClass->owner_hWnd); WinSendMsg (hwndHelpInstance, HM_DISPLAY_HELP, MPFROM2SHORT (id, 0), MPFROMSHORT (HM_RESOURCEID)); break; } #endif */ case WM_COMMAND: #if defined(__OS2__) switch (SHORT1FROMMP (mp1)) { #elif defined(__NT__) switch (LOWORD (wParam)) { #endif case IDOK: dlgClass->OnOK (); break; case IDCANCEL: dlgClass->OnCancel (); break; case IDHELP: dlgClass->OnHelp (); break; default: for (i = 0; msgMap[i].pfn != NULL; i++) { #if defined(__OS2__) if (msgMap[i].nMessage == msg) { if (msgMap[i].nID >= SHORT1FROMMP (mp1) && msgMap[i].nLastID <= SHORT1FROMMP (mp1)) { #elif defined(__NT__) if (msgMap[i].nMessage == msg && msgMap[i].nCode == HIWORD (wParam)) { if (msgMap[i].nID >= LOWORD (wParam) && msgMap[i].nLastID <= LOWORD (wParam)) { #endif (dlgClass->*msgMap[i].pfn) (); break; } } } break; } return (0); #if defined(__NT__) case WM_CLOSE: EndDialog (hwnd, FALSE); break; #endif default: if (msgMap != NULL) { for (i = 0; msgMap[i].pfn != NULL; i++) { if (msgMap[i].nMessage == msg) { (dlgClass->*msgMap[i].pfn) (); return (0); } } } break; } #if defined(__OS2__) return (WinDefDlgProc (hwnd, msg, mp1, mp2)); #elif defined(__NT__) return ((BOOL)FALSE); #endif } CDialog::CDialog (PSZ dialogTemplate, HWND p_hWnd) { strcpy (dlgTemplate, dialogTemplate); owner_hWnd = p_hWnd; help_hWnd = NULL; #if defined(__OS2__) WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (HWND_DESKTOP, SPTR_WAIT, FALSE)); #elif defined(__NT__) #endif } CDialog::~CDialog () { #if defined(__OS2__) if (help_hWnd != NULL) WinDestroyHelpInstance (help_hWnd); #elif defined(__NT__) #endif } VOID CDialog::Center () { #if defined(__OS2__) RECTL rc; #elif defined(__NT__) RECT rc; #endif #if defined(__OS2__) WinQueryWindowRect (m_hWnd, &rc); rc.yTop = (WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN) - (rc.yTop - rc.yBottom)) / 2; rc.xLeft = (WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN) - (rc.xRight - rc.xLeft)) / 2; WinSetWindowPos (m_hWnd, NULL, rc.xLeft, rc.yTop, 0, 0, SWP_MOVE); #elif defined(__NT__) GetWindowRect (m_hWnd, &rc); rc.top = (GetSystemMetrics (SM_CYSCREEN) - (rc.bottom - rc.top)) / 2; rc.left = (GetSystemMetrics (SM_CXSCREEN) - (rc.right - rc.left)) / 2; SetWindowPos (m_hWnd, NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE|SWP_NOZORDER); #endif } LONG CDialog::DoModal () { LONG ulResult = 0L; CDIALOG_DATA cDialog; cDialog.cbSize = sizeof (CDIALOG_DATA); cDialog.Dlg = this; #if defined(__OS2__) WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (HWND_DESKTOP, SPTR_ARROW, FALSE)); ulResult = WinDlgBox (HWND_DESKTOP, owner_hWnd, CDialogDlgProc, NULLHANDLE, atoi (dlgTemplate), &cDialog); #elif defined(__NT__) ulResult = DialogBoxParam (hinst, MAKEINTRESOURCE (atoi (dlgTemplate)), owner_hWnd, (DLGPROC)CDialogDlgProc, (LPARAM)&cDialog); #endif return (ulResult); } // ---------------------------------------------------------------------- // Windowing API replacement // ---------------------------------------------------------------------- VOID CDialog::EndDialog (USHORT Result) { #if defined(__OS2__) WinDismissDlg (m_hWnd, Result); #elif defined(__NT__) ::EndDialog (m_hWnd, Result); #endif } VOID CDialog::GetDlgItemText (int id, PSZ text, USHORT size) { #if defined(__OS2__) WinQueryDlgItemText (m_hWnd, id, size, text); #elif defined(__NT__) ::GetDlgItemText (m_hWnd, id, text, size); #endif } VOID CDialog::GetDlgItemText (int id, USHORT size, PSZ text) { #if defined(__OS2__) WinQueryDlgItemText (m_hWnd, id, size, text); #elif defined(__NT__) ::GetDlgItemText (m_hWnd, id, text, size); #endif }