Annotation of mstools/samples/sdktools/imagedit/imagedlg.c, revision 1.1.1.1

1.1       root        1: /***************************************************************************
                      2:  *                                                                         *
                      3:  *  MODULE      : Imagedlg.c                                               *
                      4:  *                                                                         *
                      5:  *  PURPOSE     : Dialog functions for ImagEdit's dialogs.                 *
                      6:  *                                                                         *
                      7:  *  HISTORY     : 3/03/89 by LR                                            *
                      8:  *                                                                         *
                      9:  ***************************************************************************/
                     10: 
                     11: #include "imagedit.h"
                     12: #include "dialogs.h"
                     13: #include "iehelp.h"
                     14: 
                     15: 
                     16: STATICFN BOOL NEAR NewImageOK(HWND hwnd, INT iType);
                     17: STATICFN VOID NEAR SelectImageInit(HWND hwnd);
                     18: STATICFN BOOL NEAR SelectImageOK(HWND hwnd);
                     19: 
                     20: 
                     21: 
                     22: /************************************************************************
                     23: * DlgBox
                     24: *
                     25: * This function basically does a DialogBox.
                     26: *
                     27: * Arguments:
                     28: *   INT idDlg       = Ordinal name of the dialog.
                     29: *   WNDPROC lpfnDlg = Dialog procedure to use (this function will
                     30: *                     call Make/FreeProcInstance).
                     31: *
                     32: * Returns:
                     33: *     What DialogBox returned.
                     34: *
                     35: * History:
                     36: *
                     37: ************************************************************************/
                     38: 
                     39: INT DlgBox(
                     40:     INT idDlg,
                     41:     WNDPROC lpfnDlg)
                     42: {
                     43:     WNDPROC lpfnDlgInst;
                     44:     INT nResult;
                     45:     INT idPrevDlg;
                     46: 
                     47:     EnteringDialog(idDlg, &idPrevDlg, TRUE);
                     48:     lpfnDlgInst = (WNDPROC)MakeProcInstance((FARPROC)lpfnDlg, ghInst);
                     49:     nResult = DialogBox(ghInst, MAKEINTRESOURCE(idDlg),
                     50:             ghwndMain, lpfnDlgInst);
                     51:     FreeProcInstance(lpfnDlgInst);
                     52:     EnteringDialog(idPrevDlg, NULL, FALSE);
                     53: 
                     54:     return nResult;
                     55: }
                     56: 
                     57: 
                     58: 
                     59: /************************************************************************
                     60: * EnteringDialog
                     61: *
                     62: * This function enables or disables things based on whether we are
                     63: * going to show one of the editor's dialogs.  It must be called
                     64: * before and after showing a dialog box.
                     65: *
                     66: * Arguments:
                     67: *   INT idDlg       - Ordinal name of the dialog.
                     68: *   PINT pidPrevDlg - Points to where to save the id of the previous
                     69: *                     (current) dialog.  If fEntering is FALSE, this
                     70: *                     is not used and should be NULL.
                     71: *   BOOL fEntering  - TRUE if about ready to show the dialog.  FALSE if
                     72: *                     the dialog was just dismissed.  For the FALSE case,
                     73: *                     the idDlg should be zero, or the id of the previous
                     74: *                     dialog.
                     75: *
                     76: * History:
                     77: *
                     78: ************************************************************************/
                     79: 
                     80: VOID EnteringDialog(
                     81:     INT idDlg,
                     82:     PINT pidPrevDlg,
                     83:     BOOL fEntering)
                     84: {
                     85:     /*
                     86:      * If we are entering a new dialog, save the previous dialog
                     87:      * in the place specified.
                     88:      */
                     89:     if (fEntering)
                     90:         *pidPrevDlg = gidCurrentDlg;
                     91: 
                     92:     gidCurrentDlg = idDlg;
                     93: 
                     94:     if (ghwndToolbox)
                     95:         EnableWindow(ghwndToolbox, !fEntering);
                     96: 
                     97:     if (ghwndColor)
                     98:         EnableWindow(ghwndColor, !fEntering);
                     99: 
                    100:     if (ghwndView)
                    101:         EnableWindow(ghwndView, !fEntering);
                    102: }
                    103: 
                    104: 
                    105: 
                    106: /************************************************************************
                    107: * ImageNewDialog
                    108: *
                    109: *
                    110: *
                    111: * History:
                    112: *
                    113: ************************************************************************/
                    114: 
                    115: VOID ImageNewDialog(
                    116:     INT iType)
                    117: {
                    118:     switch (iType) {
                    119:         case FT_ICON:
                    120:             DlgBox(DID_NEWICONIMAGE, (WNDPROC)NewIconImageDlgProc);
                    121:             break;
                    122: 
                    123:         case FT_CURSOR:
                    124:             DlgBox(DID_NEWCURSORIMAGE, (WNDPROC)NewCursorImageDlgProc);
                    125:             break;
                    126:     }
                    127: }
                    128: 
                    129: 
                    130: 
                    131: /************************************************************************
                    132: * ImageSelectDialog
                    133: *
                    134: *
                    135: *
                    136: * History:
                    137: *
                    138: ************************************************************************/
                    139: 
                    140: VOID ImageSelectDialog(VOID)
                    141: {
                    142:     switch (giType) {
                    143:         case FT_ICON:
                    144:             DlgBox(DID_SELECTICONIMAGE, (WNDPROC)SelectImageDlgProc);
                    145:             break;
                    146: 
                    147:         case FT_CURSOR:
                    148:             DlgBox(DID_SELECTCURSORIMAGE, (WNDPROC)SelectImageDlgProc);
                    149:             break;
                    150:     }
                    151: }
                    152: 
                    153: 
                    154: 
                    155: /************************************************************************
                    156: * ResourceTypeDlgProc
                    157: *
                    158: * Gets from the user the type of resource image that they want
                    159: * to edit (bitmap, icon or cursor).
                    160: *
                    161: * History:
                    162: *
                    163: ************************************************************************/
                    164: 
                    165: DIALOGPROC ResourceTypeDlgProc(
                    166:     HWND hwnd,
                    167:     UINT msg,
                    168:     WPARAM wParam,
                    169:     LPARAM lParam)
                    170: {
                    171:     INT idChecked;
                    172: 
                    173:     switch (msg) {
                    174:         case WM_INITDIALOG:
                    175:             switch (giType) {
                    176:                 case FT_BITMAP:
                    177:                     idChecked = DID_RESOURCETYPEBITMAP;
                    178:                     break;
                    179: 
                    180:                 case FT_ICON:
                    181:                     idChecked = DID_RESOURCETYPEICON;
                    182:                     break;
                    183: 
                    184:                 case FT_CURSOR:
                    185:                     idChecked = DID_RESOURCETYPECURSOR;
                    186:                     break;
                    187:             }
                    188: 
                    189:             CheckDlgButton(hwnd, idChecked, 1);
                    190: 
                    191:             CenterWindow(hwnd);
                    192: 
                    193:             break;
                    194: 
                    195:         case WM_COMMAND:
                    196:             switch (LOWORD(wParam)) {
                    197:                 case IDOK:
                    198:                     if (IsDlgButtonChecked(hwnd, DID_RESOURCETYPEBITMAP))
                    199:                         iNewFileType = FT_BITMAP;
                    200:                     else if (IsDlgButtonChecked(hwnd, DID_RESOURCETYPEICON))
                    201:                         iNewFileType = FT_ICON;
                    202:                     else
                    203:                         iNewFileType = FT_CURSOR;
                    204: 
                    205:                     EndDialog(hwnd, IDOK);
                    206:                     break;
                    207: 
                    208:                 case IDCANCEL:
                    209:                     EndDialog(hwnd, IDCANCEL);
                    210:                     break;
                    211: 
                    212:                 case IDHELP:
                    213:                     WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT,
                    214:                             HELPID_RESOURCETYPE);
                    215:                     break;
                    216:             }
                    217: 
                    218:             break;
                    219: 
                    220:         default:
                    221:             return FALSE;
                    222:     }
                    223: 
                    224:     return TRUE;
                    225: }
                    226: 
                    227: 
                    228: 
                    229: /************************************************************************
                    230: * NewIconImageDlgProc
                    231: *
                    232: *
                    233: *
                    234: * Arguments:
                    235: *
                    236: * History:
                    237: *
                    238: ************************************************************************/
                    239: 
                    240: DIALOGPROC NewIconImageDlgProc(
                    241:     HWND hwnd,
                    242:     UINT msg,
                    243:     WPARAM wParam,
                    244:     LPARAM lParam)
                    245: {
                    246:     HWND hwndList;
                    247:     INT iSel;
                    248:     PDEVICE pDevice;
                    249: 
                    250:     switch (msg) {
                    251:         case WM_INITDIALOG:
                    252:             hwndList = GetDlgItem(hwnd, DID_NEWIMAGELIST);
                    253:             SendMessage(hwndList, LB_RESETCONTENT, 0, 0);
                    254: 
                    255:             for (pDevice = gpIconDeviceHead; pDevice;
                    256:                     pDevice = pDevice->pDeviceNext) {
                    257:                 if (!DeviceLinkUsed(pDevice)) {
                    258:                     iSel = (INT)SendMessage(hwndList, LB_INSERTSTRING, (WPARAM)-1,
                    259:                             (LONG)(LPSTR)pDevice->szDesc);
                    260:                     SendMessage(hwndList, LB_SETITEMDATA, iSel,
                    261:                             (DWORD)(LPSTR)pDevice);
                    262:                 }
                    263:             }
                    264: 
                    265:             /*
                    266:              * Select the first item.
                    267:              */
                    268:             SendMessage(hwndList, LB_SETCURSEL, 0, 0L);
                    269: 
                    270:             CenterWindow(hwnd);
                    271: 
                    272:             break;
                    273: 
                    274:         case WM_COMMAND:
                    275:             switch (LOWORD(wParam)) {
                    276:                 case DID_NEWIMAGELIST:
                    277:                     if (HIWORD(wParam) == LBN_DBLCLK) {
                    278:                         if (NewImageOK(hwnd, FT_ICON))
                    279:                             EndDialog(hwnd, IDOK);
                    280:                     }
                    281: 
                    282:                     break;
                    283: 
                    284:                 case IDOK:
                    285:                     if (NewImageOK(hwnd, FT_ICON))
                    286:                         EndDialog(hwnd, IDOK);
                    287: 
                    288:                     break;
                    289: 
                    290:                 case IDCANCEL:
                    291:                     EndDialog(hwnd, IDCANCEL);
                    292:                     break;
                    293: 
                    294:                 case IDHELP:
                    295:                     WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT,
                    296:                             HELPID_NEWICONIMAGE);
                    297:                     break;
                    298:             }
                    299: 
                    300:             break;
                    301: 
                    302:         default:
                    303:             return FALSE;
                    304:     }
                    305: 
                    306:     return TRUE;
                    307: }
                    308: 
                    309: 
                    310: 
                    311: /************************************************************************
                    312: * NewImageOK
                    313: *
                    314: * Processes the selection of a new image from the New Icon (Cursor)
                    315: * Image dialog procedures.
                    316: *
                    317: * History:
                    318: *
                    319: ************************************************************************/
                    320: 
                    321: STATICFN BOOL NEAR NewImageOK(
                    322:     HWND hwnd,
                    323:     INT iType)
                    324: {
                    325:     HWND hwndLB;
                    326:     INT iSelect;
                    327:     PDEVICE pDevice;
                    328: 
                    329:     hwndLB = GetDlgItem(hwnd, DID_NEWIMAGELIST);
                    330: 
                    331:     if ((iSelect = (INT)SendMessage(hwndLB, LB_GETCURSEL, 0, 0)) != LB_ERR) {
                    332:         /*
                    333:          * Save away the current image.
                    334:          */
                    335:         ImageSave();
                    336: 
                    337:         pDevice = (PDEVICE)SendMessage(hwndLB, LB_GETITEMDATA, iSelect, 0);
                    338: 
                    339:         if (ImageNew(pDevice))
                    340:             return TRUE;
                    341:     }
                    342: 
                    343:     return FALSE;
                    344: }
                    345: 
                    346: 
                    347: 
                    348: /************************************************************************
                    349: * NewCursorImageDlgProc
                    350: *
                    351: *
                    352: *
                    353: * Arguments:
                    354: *
                    355: * History:
                    356: *
                    357: ************************************************************************/
                    358: 
                    359: DIALOGPROC NewCursorImageDlgProc(
                    360:     HWND hwnd,
                    361:     UINT msg,
                    362:     WPARAM wParam,
                    363:     LPARAM lParam)
                    364: {
                    365:     HWND hwndList;
                    366:     INT iSel;
                    367:     PDEVICE pDevice;
                    368: 
                    369:     switch (msg) {
                    370:         case WM_INITDIALOG:
                    371:             hwndList = GetDlgItem(hwnd, DID_NEWIMAGELIST);
                    372:             SendMessage(hwndList, LB_RESETCONTENT, 0, 0);
                    373: 
                    374:             for (pDevice = gpCursorDeviceHead; pDevice;
                    375:                     pDevice = pDevice->pDeviceNext) {
                    376:                 if (!DeviceLinkUsed(pDevice)) {
                    377:                     iSel = (INT)SendMessage(hwndList, LB_INSERTSTRING, (WPARAM)-1,
                    378:                             (LONG)(LPSTR)pDevice->szDesc);
                    379:                     SendMessage(hwndList, LB_SETITEMDATA, iSel,
                    380:                             (DWORD)(LPSTR)pDevice);
                    381:                 }
                    382:             }
                    383: 
                    384:             /*
                    385:              * Select the first item.
                    386:              */
                    387:             SendMessage(hwndList, LB_SETCURSEL, 0, 0L);
                    388: 
                    389:             CenterWindow(hwnd);
                    390: 
                    391:             break;
                    392: 
                    393:         case WM_COMMAND:
                    394:             switch (LOWORD(wParam)) {
                    395:                 case DID_NEWIMAGELIST:
                    396:                     if (HIWORD(wParam) == LBN_DBLCLK) {
                    397:                         if (NewImageOK(hwnd, FT_CURSOR))
                    398:                             EndDialog(hwnd, IDOK);
                    399:                     }
                    400: 
                    401:                     break;
                    402: 
                    403:                 case IDOK:
                    404:                     if (NewImageOK(hwnd, FT_CURSOR))
                    405:                         EndDialog(hwnd, IDOK);
                    406: 
                    407:                     break;
                    408: 
                    409:                 case IDCANCEL:
                    410:                     EndDialog(hwnd, IDCANCEL);
                    411:                     break;
                    412: 
                    413:                 case IDHELP:
                    414:                     WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT,
                    415:                             HELPID_NEWCURSORIMAGE);
                    416:                     break;
                    417:             }
                    418: 
                    419:             break;
                    420: 
                    421:         default:
                    422:             return FALSE;
                    423:     }
                    424: 
                    425:     return TRUE;
                    426: }
                    427: 
                    428: 
                    429: 
                    430: /************************************************************************
                    431: * SelectImageDlgProc
                    432: *
                    433: * This is the Select Image dialog procedure.  This proc is used for both
                    434: * icon and cursor images.
                    435: *
                    436: * History:
                    437: *
                    438: ************************************************************************/
                    439: 
                    440: DIALOGPROC SelectImageDlgProc(
                    441:     HWND hwnd,
                    442:     UINT msg,
                    443:     WPARAM wParam,
                    444:     LPARAM lParam)
                    445: {
                    446:     switch (msg) {
                    447:         case WM_INITDIALOG:
                    448:             SelectImageInit(hwnd);
                    449:             return TRUE;
                    450: 
                    451:         case WM_COMMAND:
                    452:             switch (LOWORD(wParam)) {
                    453:                 case DID_SELECTIMAGELIST:
                    454:                     if (HIWORD(wParam) == LBN_DBLCLK) {
                    455:                         if (SelectImageOK(hwnd))
                    456:                             EndDialog(hwnd, IDOK);
                    457:                     }
                    458: 
                    459:                     break;
                    460: 
                    461:                 case IDOK:
                    462:                     if (SelectImageOK(hwnd))
                    463:                         EndDialog(hwnd, IDOK);
                    464: 
                    465:                     break;
                    466: 
                    467:                 case IDCANCEL:
                    468:                     EndDialog(hwnd, IDCANCEL);
                    469:                     break;
                    470: 
                    471:                 case IDHELP:
                    472:                     WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT,
                    473:                             (giType == FT_ICON) ?
                    474:                             HELPID_SELECTICONIMAGE : HELPID_SELECTCURSORIMAGE);
                    475:                     break;
                    476:             }
                    477: 
                    478:             return TRUE;
                    479: 
                    480:         default:
                    481:             return FALSE;
                    482:     }
                    483: }
                    484: 
                    485: 
                    486: 
                    487: /************************************************************************
                    488: * SelectImageInit
                    489: *
                    490: * Processes the WM_INITDIALOG message for the Open Image dialog
                    491: * procedure.
                    492: *
                    493: * This function fills the listbox with the names of all the current
                    494: * images for the current icon/cursor file.
                    495: *
                    496: * History:
                    497: *
                    498: ************************************************************************/
                    499: 
                    500: STATICFN VOID NEAR SelectImageInit(
                    501:     HWND hwnd)
                    502: {
                    503:     HWND hwndLB;
                    504:     INT i;
                    505:     PIMAGEINFO pImage;
                    506: 
                    507:     hwndLB = GetDlgItem(hwnd, DID_SELECTIMAGELIST);
                    508: 
                    509:     for (pImage = gpImageHead; pImage; pImage = pImage->pImageNext) {
                    510:         i = (INT)SendMessage(hwndLB, LB_INSERTSTRING, (WPARAM)-1,
                    511:                 pImage->pDevice ?
                    512:                 (DWORD)(LPSTR)pImage->pDevice->szDesc :
                    513:                 (DWORD)(LPSTR)ids(IDS_UNKNOWNIMAGEFORMAT));
                    514: 
                    515:         SendMessage(hwndLB, LB_SETITEMDATA, i, (DWORD)(LPSTR)pImage);
                    516:     }
                    517: 
                    518:     /*
                    519:      * Select the first item.
                    520:      */
                    521:     SendMessage(hwndLB, LB_SETCURSEL, 0, 0L);
                    522: 
                    523:     CenterWindow(hwnd);
                    524: }
                    525: 
                    526: 
                    527: 
                    528: /************************************************************************
                    529: * SelectImageOK
                    530: *
                    531: * Processes the selection of a new image from the Open Image
                    532: * dialog procedure.
                    533: *
                    534: * History:
                    535: *
                    536: ************************************************************************/
                    537: 
                    538: STATICFN BOOL NEAR SelectImageOK(
                    539:     HWND hwnd)
                    540: {
                    541:     HWND hwndLB;
                    542:     INT iSelect;
                    543:     PIMAGEINFO pImage;
                    544: 
                    545:     hwndLB = GetDlgItem(hwnd, DID_SELECTIMAGELIST);
                    546: 
                    547:     if ((iSelect = (INT)SendMessage(hwndLB, LB_GETCURSEL, 0, 0)) == LB_ERR)
                    548:         return FALSE;
                    549: 
                    550:     /*
                    551:      * Get a pointer to the selected image (stored in the listbox
                    552:      * items data field).
                    553:      */
                    554:     pImage = (PIMAGEINFO)SendMessage(hwndLB, LB_GETITEMDATA, iSelect, 0L);
                    555: 
                    556:     return ImageOpen(pImage);
                    557: }
                    558: 
                    559: 
                    560: 
                    561: /************************************************************************
                    562: * BitmapSizeDlgProc
                    563: *
                    564: * Dialog that asks for the width, height and number of colors for
                    565: * a new bitmap file.
                    566: *
                    567: * The last values that the user successfully entered are remembered,
                    568: * and these values will be the defaults the next time that the
                    569: * dialog is invoked.
                    570: *
                    571: * History:
                    572: *
                    573: ************************************************************************/
                    574: 
                    575: DIALOGPROC BitmapSizeDlgProc(
                    576:     HWND hwnd,
                    577:     UINT msg,
                    578:     WPARAM wParam,
                    579:     LPARAM lParam)
                    580: {
                    581:     static INT cxLast = DEFAULTBITMAPWIDTH;
                    582:     static INT cyLast = DEFAULTBITMAPHEIGHT;
                    583:     static INT nColorsLast = DEFAULTBITMAPCOLORS;
                    584:     INT cx;
                    585:     INT cy;
                    586:     BOOL fTranslated;
                    587:     INT nColors;
                    588: 
                    589:     switch (msg) {
                    590:         case WM_INITDIALOG:
                    591:             SetDlgItemInt(hwnd, DID_BITMAPSIZEWIDTH, cxLast, TRUE);
                    592:             SetDlgItemInt(hwnd, DID_BITMAPSIZEHEIGHT, cyLast, TRUE);
                    593: 
                    594:             if (nColorsLast == 16)
                    595:                 CheckRadioButton(hwnd, DID_BITMAPSIZE2, DID_BITMAPSIZE16,
                    596:                         DID_BITMAPSIZE16);
                    597:             else
                    598:                 CheckRadioButton(hwnd, DID_BITMAPSIZE2, DID_BITMAPSIZE16,
                    599:                         DID_BITMAPSIZE2);
                    600: 
                    601:             CenterWindow(hwnd);
                    602: 
                    603:             break;
                    604: 
                    605:         case WM_COMMAND:
                    606:             switch (LOWORD(wParam)) {
                    607:                 case IDOK:
                    608:                     cx = GetDlgItemInt(hwnd, DID_BITMAPSIZEWIDTH, &fTranslated, FALSE);
                    609:                     if (!fTranslated) {
                    610:                         SetFocus(GetDlgItem(hwnd, DID_BITMAPSIZEWIDTH));
                    611:                         Message(MSG_ENTERANUMBER);
                    612:                         break;
                    613:                     }
                    614: 
                    615:                     cy = GetDlgItemInt(hwnd, DID_BITMAPSIZEHEIGHT, &fTranslated, FALSE);
                    616:                     if (!fTranslated) {
                    617:                         SetFocus(GetDlgItem(hwnd, DID_BITMAPSIZEHEIGHT));
                    618:                         Message(MSG_ENTERANUMBER);
                    619:                         break;
                    620:                     }
                    621: 
                    622:                     if (IsDlgButtonChecked(hwnd, DID_BITMAPSIZE2))
                    623:                         nColors = 2;
                    624:                     else
                    625:                         nColors = 16;
                    626: 
                    627:                     if (ImageNewBitmap(cx, cy, nColors)) {
                    628:                         cxLast = cx;
                    629:                         cyLast = cy;
                    630:                         nColorsLast = nColors;
                    631: 
                    632:                         EndDialog(hwnd, IDOK);
                    633:                     }
                    634: 
                    635:                     break;
                    636: 
                    637:                 case IDCANCEL:
                    638:                     EndDialog(hwnd, IDCANCEL);
                    639:                     break;
                    640: 
                    641:                 case IDHELP:
                    642:                     WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT,
                    643:                             HELPID_BITMAPSIZE);
                    644:                     break;
                    645:             }
                    646: 
                    647:             break;
                    648: 
                    649:         default:
                    650:             return FALSE;
                    651:     }
                    652: 
                    653:     return TRUE;
                    654: }

unix.superglobalmegacorp.com

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