• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            動(dòng)態(tài)生成對(duì)話框

            Creating   a   Template   in   Memory
            Applications   sometimes   adapt   or   modify   the   content   of   dialog   boxes   depending   on   the   current   state   of   the   data   being   processed.   In   such   cases,   it   is   not   practical   to   provide   all   possible   dialog   box   templates   as   resources   in   the   application 's   executable   file.   But   creating   templates   in   memory   gives   the   application   more   flexibility   to   adapt   to   any   circumstances.  

            In   the   following   example,   the   application   creates   a   template   in   memory   for   a   modal   dialog   box   that   contains   a   message   and   OK   and   Help   buttons.  

            In   a   dialog   template,   all   character   strings,   such   as   the   dialog   box   and   button   titles,   must   be   Unicode   strings.   This   example   uses   the   MultiByteToWideChar   function   to   generate   these   Unicode   strings,   because   Windows   95/98   and   Windows   NT/Windows   2000   support   MultiByteToWideChar  

            The   DLGITEMTEMPLATE   structures   in   a   dialog   template   must   be   aligned   on   DWORD   boundaries.   To   align   these   structures,   this   example   uses   a   helper   routine   that   takes   an   input   pointer   and   returns   the   closest   pointer   that   is   aligned   on   a   DWORD   boundary.

            #define   ID_HELP       150
            #define   ID_TEXT       200

            LPWORD   lpwAlign   (   LPWORD   lpIn)
            {
                    ULONG   ul;

                    ul   =   (ULONG)   lpIn;
                    ul   +=3;
                    ul   > > =2;
                    ul   < <=2;
                    return   (LPWORD)   ul;
            }

            LRESULT   DisplayMyMessage(HINSTANCE   hinst,   HWND   hwndOwner,  
                    LPSTR   lpszMessage)
            {
                    HGLOBAL   hgbl;
                    LPDLGTEMPLATE   lpdt;
                    LPDLGITEMTEMPLATE   lpdit;
                    LPWORD   lpw;
                    LPWSTR   lpwsz;
                    LRESULT   ret;
                    int   nchar;

                    hgbl   =   GlobalAlloc(GMEM_ZEROINIT,   1024);
                    if   (!hgbl)
                            return   -1;
             
                    lpdt   =   (LPDLGTEMPLATE)GlobalLock(hgbl);
             
                    //   Define   a   dialog   box.
             
                    lpdt-> style   =   WS_POPUP   |   WS_BORDER   |   WS_SYSMENU
                                                  |   DS_MODALFRAME   |   WS_CAPTION;
                    lpdt-> cdit   =   3;     //   number   of   controls
                    lpdt-> x     =   10;     lpdt-> y     =   10;
                    lpdt-> cx   =   100;   lpdt-> cy   =   100;

                    lpw   =   (LPWORD)   (lpdt   +   1);
                    *lpw++   =   0;       //   no   menu
                    *lpw++   =   0;       //   predefined   dialog   box   class   (by   default)

                    lpwsz   =   (LPWSTR)   lpw;
                    nchar   =   1+   MultiByteToWideChar   (CP_ACP,   0,   "My   Dialog ",  
                                                                                    -1,   lpwsz,   50);
                    lpw       +=   nchar;

                    //-----------------------
                    //   Define   an   OK   button.
                    //-----------------------
                    lpw   =   lpwAlign   (lpw);   //   align   DLGITEMTEMPLATE   on   DWORD   boundary
                    lpdit   =   (LPDLGITEMTEMPLATE)   lpw;
                    lpdit-> x     =   10;   lpdit-> y     =   70;
                    lpdit-> cx   =   80;   lpdit-> cy   =   20;
                    lpdit-> id   =   IDOK;     //   OK   button   identifier
                    lpdit-> style   =   WS_CHILD   |   WS_VISIBLE   |   BS_DEFPUSHBUTTON;

                    lpw   =   (LPWORD)   (lpdit   +   1);
                    *lpw++   =   0xFFFF;
                    *lpw++   =   0x0080;         //   button   class

                    lpwsz   =   (LPWSTR)   lpw;
                    nchar   =   1+MultiByteToWideChar   (CP_ACP,   0,   "OK ",   -1,   lpwsz,   50);
                    lpw       +=   nchar;
                    lpw   =   lpwAlign   (lpw);   //   align   creation   data   on   DWORD   boundary
                    *lpw++   =   0;                       //   no   creation   data

                    //-----------------------
                    //   Define   a   Help   button.
                    //-----------------------
                    lpw   =   lpwAlign   (lpw);   //   align   DLGITEMTEMPLATE   on   DWORD   boundary
                    lpdit   =   (LPDLGITEMTEMPLATE)   lpw;
                    lpdit-> x     =   55;   lpdit-> y     =   10;
                    lpdit-> cx   =   40;   lpdit-> cy   =   20;
                    lpdit-> id   =   ID_HELP;         //   Help   button   identifier
                    lpdit-> style   =   WS_CHILD   |   WS_VISIBLE   |   BS_PUSHBUTTON;

                    lpw   =   (LPWORD)   (lpdit   +   1);
                    *lpw++   =   0xFFFF;
                    *lpw++   =   0x0080;                                   //   button   class   atom

                    lpwsz   =   (LPWSTR)   lpw;
                    nchar   =   1+MultiByteToWideChar   (CP_ACP,   0,   "Help ",   -1,   lpwsz,   50);
                    lpw       +=   nchar;
                    lpw   =   lpwAlign   (lpw);   //   align   creation   data   on   DWORD   boundary
                    *lpw++   =   0;                       //   no   creation   data

                    //-----------------------
                    //   Define   a   static   text   control.
                    //-----------------------
                    lpw   =   lpwAlign   (lpw);   //   align   DLGITEMTEMPLATE   on   DWORD   boundary
                    lpdit   =   (LPDLGITEMTEMPLATE)   lpw;
                    lpdit-> x     =   10;   lpdit-> y     =   10;
                    lpdit-> cx   =   40;   lpdit-> cy   =   20;
                    lpdit-> id   =   ID_TEXT;     //   text   identifier
                    lpdit-> style   =   WS_CHILD   |   WS_VISIBLE   |   SS_LEFT;

                    lpw   =   (LPWORD)   (lpdit   +   1);
                    *lpw++   =   0xFFFF;
                    *lpw++   =   0x0082;                                                   //   static   class

                    for   (lpwsz   =   (LPWSTR)lpw;        
                            *lpwsz++   =   (WCHAR)   *lpszMessage++;
                    );
                    lpw   =   (LPWORD)lpwsz;
                    lpw   =   lpwAlign   (lpw);   //   align   creation   data   on   DWORD   boundary
                    *lpw++   =   0;                       //   no   creation   data

                    GlobalUnlock(hgbl);  
                    ret   =   DialogBoxIndirect(hinst,   (LPDLGTEMPLATE)   hgbl,  
                            hwndOwner,   (DLGPROC)   DialogProc);  
                    GlobalFree(hgbl);  
                    return   ret;  
            }

            posted on 2011-03-24 10:53 wrh 閱讀(639) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            導(dǎo)航

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            統(tǒng)計(jì)

            常用鏈接

            留言簿(19)

            隨筆檔案

            文章檔案

            收藏夾

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            无码AV波多野结衣久久| 午夜精品久久久久久影视777| 中文字幕无码精品亚洲资源网久久| 久久久久无码精品| 久久久久久精品免费免费自慰| 亚洲欧美日韩久久精品第一区| 99久久精品费精品国产一区二区 | 大香网伊人久久综合网2020| 久久精品无码专区免费 | 色综合久久中文字幕综合网| 久久成人国产精品免费软件| 久久国产精品久久久| 久久久久久精品无码人妻| 精品久久久无码中文字幕天天| 久久一日本道色综合久久| 久久久久黑人强伦姧人妻| 久久久久无码精品国产| 伊人久久大香线蕉AV一区二区| 久久免费视频网站| 国产亚洲欧美精品久久久| 天天影视色香欲综合久久| 久久婷婷国产麻豆91天堂| 久久综合给合久久狠狠狠97色| 日韩精品无码久久一区二区三| 91性高湖久久久久| 久久精品国产精品国产精品污| 亚洲va中文字幕无码久久不卡| 亚洲欧美国产精品专区久久| 久久精品国产精品亚洲| 99久久国产综合精品五月天喷水 | 久久久久亚洲精品无码蜜桃| 亚洲午夜精品久久久久久浪潮 | 99久久精品国产毛片| 久久精品国产99久久久| 色婷婷综合久久久久中文| 久久午夜福利无码1000合集| 日韩精品无码久久一区二区三| 久久有码中文字幕| 亚洲欧美日韩精品久久亚洲区| 国产综合精品久久亚洲| 久久精品国产精品亚洲下载|