Annotation of os232sdk/toolkt20/c/samples/opendlg/hello/hello.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * HELLO.C -- A simple program which calls the OpenDlg library
                      3:  *
                      4:  * Created by Microsoft, IBM Corporation 1990
                      5:  *
                      6:  *     DISCLAIMER OF WARRANTIES.  The following [enclosed] code is 
                      7:  *     sample code created by Microsoft Corporation and/or IBM 
                      8:  *     Corporation. This sample code is not part of any standard 
                      9:  *     Microsoft or IBM product and is provided to you solely for 
                     10:  *     the purpose of assisting you in the development of your 
                     11:  *     applications.  The code is provided "AS IS", without 
                     12:  *     warranty of any kind.  Neither Microsoft nor IBM shall be 
                     13:  *     liable for any damages arising out of your use of the sample 
                     14:  *     code, even if they have been advised of the possibility of 
                     15:  *     such damages.
                     16:  */
                     17: #define INCL_PM
                     18: #include <os2.h>
                     19: #include "..\opendlg.h"
                     20: #include <string.h>
                     21: #include "hello.h"
                     22: /*
                     23:  * Globals
                     24:  */
                     25: HAB     hAB;
                     26: HMQ     hMqHello;
                     27: HWND    hWndHello;
                     28: HWND    hWndHelloFrame;
                     29: CHAR    szClassName[]  = "Hello World";
                     30: CHAR   szMessage[]     = " - File Dialog Sample";
                     31: CHAR   szExtension[]   = "\\*";
                     32: CHAR   szHelp[]        = "Help would go here.";
                     33: DLF    vdlf;
                     34: HFILE  vhFile;
                     35: /*
                     36:  * Main routine...initializes window and message queue
                     37:  */
                     38: int main( ) {
                     39:     QMSG qmsg;
                     40:     ULONG ctldata;
                     41: 
                     42:     hAB = WinInitialize(NULL);
                     43: 
                     44:     hMqHello = WinCreateMsgQueue(hAB, 0);
                     45: 
                     46:     if (!WinRegisterClass( hAB, (PCH)szClassName, (PFNWP)HelloWndProc,
                     47:                CS_SIZEREDRAW, 0))
                     48:         return( 0 );
                     49: 
                     50:     /* Create the window */
                     51:     ctldata = FCF_STANDARD & ~(FCF_ACCELTABLE);
                     52:     hWndHelloFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, &ctldata,
                     53:                                          szClassName, szMessage,
                     54:                                          0L, (HMODULE)NULL, ID_RESOURCE,
                     55:                                         &hWndHello );
                     56: 
                     57:     if (hWndHelloFrame == (HWND)NULL)
                     58:        return 0;
                     59:     WinShowWindow( hWndHelloFrame, TRUE );
                     60: 
                     61:     /* Poll messages from event queue */
                     62:     while( WinGetMsg( hAB, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )
                     63:         WinDispatchMsg( hAB, (PQMSG)&qmsg );
                     64: 
                     65:     /* Clean up */
                     66:     WinDestroyWindow( hWndHelloFrame );
                     67:     WinDestroyMsgQueue( hMqHello );
                     68:     WinTerminate( hAB );
                     69: }
                     70: 
                     71: MRESULT EXPENTRY HelloWndProc(hWnd, msg, mp1, mp2)
                     72: /*
                     73:  * This routine processes WM_COMMAND, WM_PAINT.  It passes
                     74:  * everything else to the Default Window Procedure.
                     75:  */
                     76: HWND hWnd;
                     77: USHORT msg;
                     78: MPARAM mp1;
                     79: MPARAM mp2;
                     80: {
                     81:     HPS                hPS;
                     82:     POINTL     pt;
                     83:     CHARBUNDLE cb;
                     84:     RECTL      rcl;
                     85: 
                     86:     switch (msg) {
                     87: 
                     88:        case WM_COMMAND:
                     89:            switch (LOUSHORT(mp1)) {
                     90: 
                     91:                case IDM_OPEN: /* Demonstrate Open... dialog call */
                     92:                    SetupDLF( &vdlf
                     93:                            , DLG_OPENDLG
                     94:                            , &vhFile
                     95:                            , szExtension
                     96:                            , NULL
                     97:                            , "Open Title"
                     98:                            , szHelp );
                     99:                    DlgFile(hWndHelloFrame, &vdlf);
                    100:                    break;
                    101: 
                    102:                case IDM_SAVE: /* Demonstrate Save As... dialog call */
                    103:                    SetupDLF( &vdlf
                    104:                            , DLG_SAVEDLG
                    105:                            , &vhFile
                    106:                            , szExtension
                    107:                            , NULL
                    108:                            , "Save Title"
                    109:                            , szHelp);
                    110:                    strcpy((PSZ)vdlf.szOpenFile, (PSZ)"foo.bar");
                    111:                    DlgFile(hWndHelloFrame, &vdlf);
                    112:                    break;
                    113: 
                    114:                case IDM_ABOUT:
                    115:                    WinDlgBox(HWND_DESKTOP, hWnd, AboutDlgProc,
                    116:                              NULL, IDD_ABOUT, NULL);
                    117:                    return 0;
                    118: 
                    119:                default: break;
                    120:            }
                    121:            break;
                    122: 
                    123:        case WM_PAINT:
                    124:            /* Open the presentation space */
                    125:            hPS = WinBeginPaint(hWnd, NULL, &rcl);
                    126: 
                    127:            /* Fill the background with Dark Blue */
                    128:            WinFillRect(hPS, &rcl, CLR_DARKBLUE);
                    129: 
                    130:            /* Write "Hello World" in Red */
                    131:            pt.x = pt.y = 0L;
                    132:            cb.lColor = CLR_RED;
                    133:            GpiSetAttrs(hPS, PRIM_CHAR, CBB_COLOR, 0L, &cb);
                    134:            GpiCharStringAt(hPS, &pt, (LONG)sizeof(szClassName)-1, szClassName);
                    135: 
                    136:            /* Finish painting */
                    137:            WinEndPaint(hPS);
                    138:            break;
                    139: 
                    140:        default:
                    141:            return WinDefWindowProc(hWnd, msg, mp1, mp2); break;
                    142:     }
                    143:     return 0L;
                    144: }
                    145: 
                    146: MRESULT EXPENTRY AboutDlgProc(hDlg, msg, mp1, mp2)
                    147: /*
                    148:     About... dialog procedure
                    149: */
                    150: HWND hDlg;
                    151: USHORT msg;
                    152: MPARAM mp1;
                    153: MPARAM mp2;
                    154: {
                    155:     switch(msg) {
                    156:        case WM_COMMAND:
                    157:            switch(LOUSHORT(mp1)) {
                    158:                case DID_OK: WinDismissDlg(hDlg, TRUE); break;
                    159:                default: break;
                    160:            }
                    161:        default: return WinDefDlgProc(hDlg, msg, mp1, mp2);
                    162:     }
                    163:     return FALSE;
                    164: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.