第319章 メニュー・リソースをdll化する


今回は、メニュー・リソースもdll化してみます。このプログラムはいろいろな関係上 (IE様メニューバーなど)一つのメニュー項目を追加するのに、3カ所の追加が必要となります。 メニュー・リソースをdll化しておくと挿入画像の追加の場合、本体の修正・追加は1カ所のみとなります。 最終的には、画像の追加・変更があってもdllのみの修正で済むようになれば理想的です。とりあえず 今回はメニュー・リソースをdll化しておきます。



では、プログラムを見てみましょう。

まずは、dll側です。

//hedll02.cpp #include <windows.h> #include "hedll.h" #include "resource.h" int WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, PVOID pvReserved) { return TRUE; }

特に変更はありません。

// hedll.h #define EXPORT extern "C" __declspec(dllexport)

これも同じですが、ファイル名をhedllxx.hからhedll.hに変更しました。

// hedll02.rcの一部 ///////////////////////////////////////////////////////////////////////////// // // GIF // WHAT GIF DISCARDABLE "what.gif" MAIL GIF DISCARDABLE "mail.gif" HOME GIF DISCARDABLE "home.gif" INDEX GIF DISCARDABLE "index.gif" BACK GIF DISCARDABLE "back.gif" CONTENTS GIF DISCARDABLE "contents.gif" ///////////////////////////////////////////////////////////////////////////// // // Menu // INSERT2 MENU DISCARDABLE BEGIN POPUP "ダミーです" BEGIN MENUITEM "基本項目入力", IDM_BASICINPUT MENUITEM "JavaScriptの挿入", IDM_SCRIPT POPUP "タグの挿入" BEGIN MENUITEM "<P>", IDM_P MENUITEM "<BR>", IDM_BR MENUITEM "<H*></H*>...", IDM_H MENUITEM "<IMG>...", IDM_IMAGE MENUITEM "<A HREF></A>...", IDM_A MENUITEM "<TABLE></TABLE>...", IDM_TABLE MENUITEM "<FORM></FORM>...", IDM_FORM MENUITEM "<INPUT>...", IDM_INPUT END POPUP "GIF画像" BEGIN MENUITEM "What's New", IDM_WHAT MENUITEM "Mail", IDM_MAILTO MENUITEM "Home", IDM_HOME MENUITEM "Index", IDM_INDEX MENUITEM "Back", IDM_BACK MENUITEM "Contents", IDM_CONTENTS END END END EDIT MENU DISCARDABLE BEGIN POPUP "ダミーです" BEGIN MENUITEM "コピー", IDM_COPY MENUITEM "切り取り", IDM_CUT MENUITEM "貼り付け", IDM_PASTE MENUITEM "削除", IDM_DELETE MENUITEM "元に戻す", IDM_UNDO END END FILE MENU DISCARDABLE BEGIN POPUP "ダミーです" BEGIN MENUITEM "新規作成", IDM_NEW MENUITEM "開く", IDM_OPEN MENUITEM "上書き保存", IDM_SAVE END END INSERT MENU DISCARDABLE BEGIN POPUP "ダミーです" BEGIN MENUITEM "<P>", IDM_P MENUITEM "<BR>", IDM_BR MENUITEM "<H*></H*>...", IDM_H MENUITEM "<IMG>...", IDM_IMAGE MENUITEM "<A HREF></A>...", IDM_A MENUITEM "<TABLE></TABLE>...", IDM_TABLE MENUITEM "<FORM></FORM>...", IDM_FORM MENUITEM "<INPUT>...", IDM_INPUT END END MYMENU MENU DISCARDABLE BEGIN POPUP "ファイル(&F)" BEGIN MENUITEM "新規作成(&N)...\tCtrl+N", IDM_NEW MENUITEM "開く(&O)...\tCtrl+O", IDM_OPEN MENUITEM SEPARATOR MENUITEM "上書き保存(&S)\tCtrl+S", IDM_SAVE MENUITEM "名前を付けて保存(&A)...", IDM_SAVEAS MENUITEM SEPARATOR MENUITEM "アプリケーションの終了(&X)", IDM_END END POPUP "編集(&E)" BEGIN MENUITEM "元に戻す(&U)\tCtrl+Z", IDM_UNDO MENUITEM "切り取り(&T)\tCtrl+X", IDM_CUT MENUITEM "コピー(&C)\tCtrl+C", IDM_COPY MENUITEM "貼り付け(&P)\tCtrl+V", IDM_PASTE MENUITEM "削除(&D)\tCtrl+D", IDM_DELETE MENUITEM SEPARATOR MENUITEM "すべて選択(&L)\tCtrl+A", IDM_ALL END POPUP "挿入(&I)" BEGIN MENUITEM "基本項目入力(&B)...\tShift+Ctrl+B", IDM_BASICINPUT MENUITEM SEPARATOR POPUP "タグの挿入" BEGIN MENUITEM "<P>", IDM_P MENUITEM "<BR>", IDM_BR MENUITEM "<H*></H*>...", IDM_H MENUITEM "<IMG>...", IDM_IMAGE MENUITEM "<A HREF></A>...", IDM_A MENUITEM "<TABLE></TABLE>...", IDM_TABLE MENUITEM "<FORM></FORM>...", IDM_FORM MENUITEM "<INPUT>...", IDM_INPUT END POPUP "JavaScriptの挿入" BEGIN MENUITEM "<SCRIPT>", IDM_SCRIPT END POPUP "GIF画像" BEGIN MENUITEM "What's New", IDM_WHAT MENUITEM "Mail", IDM_MAILTO MENUITEM "Home", IDM_HOME MENUITEM "Index", IDM_INDEX MENUITEM "Back", IDM_BACK MENUITEM "Contents", IDM_CONTENTS END END POPUP "ブラウザ(&B)" BEGIN MENUITEM "ブラウザ起動(&E)\tF12", IDM_BROWSER END POPUP "オプション(&O)" BEGIN POPUP "ツールチップ(&T)" BEGIN MENUITEM "文字色(&L)", IDM_TIPTXTCOLOR MENUITEM "背景色(&B)", IDM_TIPBKCOLOR END END END MYMENU2 MENU DISCARDABLE BEGIN POPUP "ダミーです" BEGIN POPUP "ファイル(&F)" BEGIN MENUITEM "新規作成(&N)...\tCtrl+N", IDM_NEW MENUITEM "開く(&O)...\tCtrl+O", IDM_OPEN MENUITEM SEPARATOR MENUITEM "上書き保存(&S)\tCtrl+S", IDM_SAVE MENUITEM "名前を付けて保存(&A)...", IDM_SAVEAS MENUITEM SEPARATOR MENUITEM "アプリケーションの終了(&X)", IDM_END END POPUP "編集" BEGIN MENUITEM "元に戻す(&U)\tCtrl+Z", IDM_UNDO MENUITEM "切り取り(&T)\tCtrl+X", IDM_CUT MENUITEM "コピー(&C)\tCtrl+C", IDM_COPY MENUITEM "貼り付け(&]P)\tCtrl+V", IDM_PASTE MENUITEM "削除(&D)\tCtrl+D", IDM_DELETE MENUITEM SEPARATOR MENUITEM "すべて選択(&L)\tCtrl+A", IDM_ALL END POPUP "挿入(&I)" BEGIN MENUITEM "基本項目(&B)\tShift+Ctrl+B", IDM_BASICINPUT MENUITEM SEPARATOR POPUP "タグの挿入" BEGIN MENUITEM "<P>", IDM_P MENUITEM "<BR>", IDM_BR MENUITEM "<H*></H*>...", IDM_H MENUITEM "<IMG>...", IDM_IMAGE MENUITEM "<A HREF></A>...", IDM_A MENUITEM "<TABLE></TABLE>...", IDM_TABLE MENUITEM "<FORM></FORM>...", IDM_FORM MENUITEM "<INPUT>...", IDM_INPUT END POPUP "JavaScriptの挿入" BEGIN MENUITEM "<SCRIPT>", IDM_SCRIPT END POPUP "GIF画像" BEGIN MENUITEM "What's New", IDM_WHAT MENUITEM "Mail", IDM_MAILTO MENUITEM "Home", IDM_HOME MENUITEM "Index", IDM_INDEX MENUITEM "Back", IDM_BACK MENUITEM "Contents", IDM_CONTENTS END END POPUP "ブラウザ(&B)" BEGIN MENUITEM "ブラウザの起動(&B)\tF12", IDM_BROWSER END POPUP "オプション(&O)" BEGIN POPUP "ツールチップ(&T)" BEGIN MENUITEM "文字色(&L)", IDM_TIPTXTCOLOR MENUITEM "背景色(&B)", IDM_TIPBKCOLOR END END END END

メニュー・リソースを全部dll側に持ってきました。 これで、dll側の作業は終わりです。

では、exe側を見てみましょう。

htmledit.hに変更はありません。hedll.hをインクルードするのを忘れないでください。

// htmledit14.rcの一部 ///////////////////////////////////////////////////////////////////////////// // // Dialog // MYBASICINPUT DIALOG DISCARDABLE 0, 0, 187, 121 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "基本項目入力" FONT 9, "MS Pゴシック" BEGIN EDITTEXT IDC_EDIT1,39,7,141,14,ES_AUTOHSCROLL EDITTEXT IDC_EDIT2,39,27,141,14,ES_AUTOHSCROLL EDITTEXT IDC_EDIT3,39,47,141,14,ES_AUTOHSCROLL DEFPUSHBUTTON "OK",IDOK,39,100,50,14 PUSHBUTTON "キャンセル",IDCANCEL,96,100,50,14 LTEXT "タイトル",IDC_STATIC,7,7,23,8 LTEXT "作者",IDC_STATIC,7,30,15,8 LTEXT "E-Mail",IDC_STATIC,7,47,20,8 CONTROL "色",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON,35,76,23,10 CONTROL "壁紙",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,67,76,32, 10 GROUPBOX "背景",IDC_STATIC,26,67,133,26 CONTROL "指定しない",IDC_RADIO3,"Button",BS_AUTORADIOBUTTON,108, 76,46,10 END MYHTAG DIALOG DISCARDABLE 0, 0, 187, 93 STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "見出しタグの挿入" FONT 9, "MS Pゴシック" BEGIN COMBOBOX IDC_COMBO1,51,7,18,68,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP EDITTEXT IDC_EDIT1,51,27,129,32,ES_MULTILINE | ES_AUTOHSCROLL | ES_WANTRETURN DEFPUSHBUTTON "OK",IDOK,40,72,50,14 PUSHBUTTON "キャンセル",IDCANCEL,95,72,50,14 LTEXT "大きさ",IDC_STATIC,7,7,32,11 LTEXT "コンテンツ",IDC_STATIC,7,27,39,10 END MYIMGTAG DIALOG DISCARDABLE 0, 0, 187, 91 STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "イメージの挿入" FONT 9, "MS Pゴシック" BEGIN DEFPUSHBUTTON "OK",IDOK,43,70,41,14 PUSHBUTTON "キャンセル",IDCANCEL,101,70,41,14 CONTROL "パス付き",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,7,42,15 EDITTEXT IDC_EDIT1,50,7,107,16,ES_AUTOHSCROLL LTEXT "ファイル名",IDC_STATIC,7,33,38,11 EDITTEXT IDC_EDIT2,50,29,107,16,ES_AUTOHSCROLL PUSHBUTTON "参照",IDC_BUTTON1,160,31,20,15 CONTROL "画像を確認する",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,52,61,15 END MYTABLETAG DIALOG DISCARDABLE 0, 0, 95, 133 STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "テーブルの挿入" FONT 9, "MS Pゴシック" BEGIN DEFPUSHBUTTON "OK",IDOK,7,112,33,14 PUSHBUTTON "キャンセル",IDCANCEL,46,112,33,14 LTEXT "行",IDC_STATIC,7,7,11,10 COMBOBOX IDC_COMBO1,29,7,23,58,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP LTEXT "列",IDC_STATIC,7,27,11,10 COMBOBOX IDC_COMBO2,29,25,23,55,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP CONTROL "BORDER",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,49,41,12 EDITTEXT IDC_EDIT1,51,48,34,14,ES_AUTOHSCROLL CONTROL "CAPTION",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,67,44,12 COMBOBOX IDC_COMBO3,51,67,34,45,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP EDITTEXT IDC_EDIT2,17,89,71,14,ES_AUTOHSCROLL END MYFORMTAG DIALOG DISCARDABLE 0, 0, 187, 103 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "フォームの挿入" FONT 9, "MS Pゴシック" BEGIN DEFPUSHBUTTON "OK",IDOK,38,82,50,14 PUSHBUTTON "キャンセル",IDCANCEL,97,82,50,14 CONTROL "METHOD",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,7,47,12 COMBOBOX IDC_COMBO1,65,7,52,41,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP CONTROL "ACTION",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,25,43,12 EDITTEXT IDC_EDIT1,65,25,114,12,ES_AUTOHSCROLL CONTROL "NAME",IDC_CHECK3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, 7,43,34,12 EDITTEXT IDC_EDIT2,65,43,114,12,ES_AUTOHSCROLL CONTROL "ID",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7, 61,32,12 EDITTEXT IDC_EDIT3,65,61,114,12,ES_AUTOHSCROLL END MYINPUTTAG DIALOG DISCARDABLE 0, 0, 135, 203 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "INPUTの挿入" FONT 9, "MS Pゴシック" BEGIN DEFPUSHBUTTON "OK",IDOK,17,182,50,14 PUSHBUTTON "キャンセル",IDCANCEL,71,182,50,14 LTEXT "TYPE",IDC_STATIC,7,7,24,9 COMBOBOX IDC_COMBO1,49,7,45,92,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP CONTROL "NAME",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, 7,48,35,14 CONTROL "ID",IDC_CHECK3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7, 67,25,14 CONTROL "onClick",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,86,35,14 EDITTEXT IDC_EDIT4,49,87,75,13,ES_AUTOHSCROLL EDITTEXT IDC_EDIT2,49,49,75,13,ES_AUTOHSCROLL EDITTEXT IDC_EDIT3,49,67,75,13,ES_AUTOHSCROLL EDITTEXT IDC_EDIT1,49,29,75,13,ES_AUTOHSCROLL CONTROL "VALUE",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, 7,29,37,14 CONTROL "onBlur",IDC_CHECK5,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,105,36,14 EDITTEXT IDC_EDIT5,49,105,75,13,ES_AUTOHSCROLL CONTROL "onChange",IDC_CHECK6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,124,40,14 EDITTEXT IDC_EDIT6,49,125,75,13,ES_AUTOHSCROLL CONTROL "onFocus",IDC_CHECK7,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,143,37,14 EDITTEXT IDC_EDIT7,49,143,75,13,ES_AUTOHSCROLL CONTROL "onSubmit",IDC_CHECK8,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,162,40,14 EDITTEXT IDC_EDIT8,49,163,75,13,ES_AUTOHSCROLL END ///////////////////////////////////////////////////////////////////////////// // // Icon // // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. MYICON ICON DISCARDABLE "htmledit.ico" ///////////////////////////////////////////////////////////////////////////// // // Toolbar // IDR_TOOLBAR3X TOOLBAR DISCARDABLE 16, 15 BEGIN BUTTON ID_BUTTON40035 BUTTON ID_BUTTON40036 BUTTON ID_BUTTON40037 END IDR_TOOLBAR3 TOOLBAR DISCARDABLE 16, 15 BEGIN BUTTON ID_BUTTON40041 BUTTON ID_BUTTON40042 BUTTON ID_BUTTON40043 END ///////////////////////////////////////////////////////////////////////////// // // Bitmap // IDR_TOOLBAR3X BITMAP DISCARDABLE "toolbar3x.bmp" IDR_TOOLBAR3 BITMAP DISCARDABLE "toolbar3.bmp" ///////////////////////////////////////////////////////////////////////////// // // Accelerator // MYACCEL ACCELERATORS DISCARDABLE BEGIN "A", IDM_ALL, VIRTKEY, CONTROL, NOINVERT "B", IDM_BASICINPUT, VIRTKEY, SHIFT, CONTROL, NOINVERT "D", IDM_DELETE, VIRTKEY, CONTROL, NOINVERT "N", IDM_NEW, VIRTKEY, CONTROL, NOINVERT "O", IDM_OPEN, VIRTKEY, CONTROL, NOINVERT "S", IDM_SAVE, VIRTKEY, CONTROL, NOINVERT "V", IDM_PASTE, VIRTKEY, CONTROL, NOINVERT VK_F12, IDM_BROWSER, VIRTKEY, NOINVERT END ///////////////////////////////////////////////////////////////////////////// // // String Table // STRINGTABLE DISCARDABLE BEGIN IDS_FILE "ファイル(&F)" IDS_EDIT "編集(&E)" IDS_INSERT "挿入(&I)" IDS_BROWSER "ブラウザ(&B)" IDS_OPTION "オプション(&O)" END

メニュー・リソースの部分がすっぽり抜けました。 これにより、ソース・ファイルはどこをどのように修正すればよいでしょうか。

// htmedit14.cpp #ifndef STRICT #define STRICT #endif #define ID_EDIT 100 #define ID_EDIT2 101 #define ID_TOOL1 102 #define ID_TOOL2 103 #define ID_TOOL3 104 #define ID_REBAR 105 #define ID_STATIC 106 #define ID_STATUS 107 #define ID_TOOLMENU 108 #define ID_TIP1 111 #define ID_TIP2 112 #define ID_TIP3 113 #define MY_BUF_SIZE 1024 * 64 - 1 #define MY_MSG WM_USER #include <windows.h> #include <windowsx.h> #include "resource.h" #include "htmledit.h" #include <commctrl.h> #include "hedll.h" LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK MyBasicInputProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK MyHProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK MyImgProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK MyAProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK MyTableProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK MyFormProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK MyInputProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK NewEditProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK KbdHook(int, WPARAM, LPARAM lParam); ATOM InitApp(HINSTANCE); BOOL InitInstance(HINSTANCE, int); BOOL MySetHTML(HWND, HWND); int MyBasicInput(HWND); BOOL MySaveAs(HWND); BOOL MySave(HWND); BOOL MyInsertTag(HWND, HWND, char *); BOOL MyInsertH(HWND, HWND); BOOL MyInsertIMG(HWND, HWND); BOOL MyGetFileTitle(HWND, HWND, BOOL); BOOL MyGetBodyColor(HWND); BOOL MyGetWallPaper(HWND); BOOL MyInsertA(HWND, HWND); BOOL MyGetHREFFile(HWND, HWND, BOOL); BOOL MyInsertTable(HWND, HWND); BOOL MyInsertForm(HWND, HWND); BOOL MyInsertInput(HWND, HWND); BOOL MyInsertScript(HWND, HWND); HWND MakeMyToolbar(HWND, int, TBBUTTON *, int); HWND MakeMyToolbar2(HWND, int, TBBUTTON *, int, int, int); HWND MakeMyToolbarMenu(HWND); BOOL MyOpen(HWND, HWND); BOOL CheckMyMenu(HMENU, HWND, HWND); BOOL CanPaste(HWND); BOOL MySetStatusText(HWND, int, char *); HWND MakeMyToolTip(HWND, HWND, int, int, TBBUTTON *, char [][256]); void SetTipColor(HWND, HWND *, COLORREF *, int); void SetTipBkColor(HWND, HWND *, COLORREF *, int); BOOL GetInitialSetting(LPMYINITIALDATA); BOOL SetInitialSetting(LPMYINITIALDATA); BOOL ShowMyPopMenu(HWND, HWND, char *, int, HWND, HWND); BOOL MyCreateFileFromResource(HWND, HWND, char *, char *, char *); char szClassName[] = "htmedit14"; //ウィンドウクラス char szExeName[] = "hedll02.dll"; //dllの名前 char *lpszWinTitleOrg = "猫でもわかるHTMLエディタ[%s]"; char *lpszHead = "<HTML>\r\n<HEAD>\r\n" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=x-sjis\">\r\n<TITLE>"; char szTitle[64] = "タイトル"; char *lpszBody1 = "</TITLE>\r\n</HEAD>\r\n<BODY"; char szBody2[256]; char *lpszBody3 =">\r\n"; char *lpszAddress = "<ADDRESS>"; char *lpszMailto = "<A HREF=\"mailto:"; char szEMail[256] = "webmaster@kumei.ne.jp"; char *lpszMailEnd = "\">"; char szAuthor[64] = "Yasutaka Kumei"; char *lpszCloseA = "</A>"; char *lpszEnd = "</ADDRESS>\r\n</BODY>\r\n</HTML>"; char szFileName[MAX_PATH]; char szFileTitle[64]; WNDPROC OrgEditProc; HIMAGELIST hImage; HWND hParent; HHOOK hHook; HWND hMytoolMenu; HWND hTool2_g, hEdit_g; HINSTANCE hDllInst; //dllのインスタンス TBBUTTON tbButton1[] = { {STD_FILENEW, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0}, {STD_FILEOPEN, IDM_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0}, {STD_FILESAVE, IDM_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0}, }; TBBUTTON tbButton2[] = { {STD_COPY, IDM_COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0}, {STD_CUT, IDM_CUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0}, {STD_PASTE, IDM_PASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0}, {STD_DELETE, IDM_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0}, {STD_UNDO, IDM_UNDO, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0}, }; TBBUTTON tbButton3[] = { {0, IDM_BASICINPUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0}, {1, IDM_SCRIPT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0}, {2, IDM_TAG, TBSTATE_ENABLED, TBSTYLE_DROPDOWN, 0, 0, 0}, }; TBBUTTON tbButtonMenu[] = { {I_IMAGENONE, IDM_FILE, TBSTATE_ENABLED, TBSTYLE_BUTTON | BTNS_AUTOSIZE, 0, 0, 0}, {I_IMAGENONE, IDM_EDIT, TBSTATE_ENABLED, TBSTYLE_BUTTON | BTNS_AUTOSIZE, 0, 0, 0}, {I_IMAGENONE, IDM_INSERT, TBSTATE_ENABLED, TBSTYLE_BUTTON | BTNS_AUTOSIZE, 0, 0, 0}, {I_IMAGENONE, IDM_BRVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON | BTNS_AUTOSIZE, 0, 0, 0}, {I_IMAGENONE, IDM_OPTION, TBSTATE_ENABLED, TBSTYLE_BUTTON | BTNS_AUTOSIZE, 0, 0, 0} }; char szTipText1[][256] = { "新規にHTMLファイルを作成します", "HTMLファイルを開きます", "上書き保存をします\nすでに名前を付けて保存してある必要があります" }; char szTipText2[][256] = { "選択された文字列をコピーします", "選択された文字列を切り取って\nクリップボードに格納します", "クリップボードから貼り付けます", "選択された文字列を削除します\n削除してしまってもUNDOで取り消すこともできます", "元に戻します" }; char szTipText3[][256] = { "HTMLの基本的枠組みを作ります", "スクリプトを挿入します", "タグを挿入します" };

インクルードファイルの名前を一部変更しました。dllの時使ったhedll.hです。

szExeNameを今回使用する"hedll02.dll"にしました。

さて、今まではインスタンスハンドルは、このプログラムのインスタンスハンドルを 使うことがほとんどでしたが、今回はdllのインスタンスハンドルが必要となります。 そこで、グローバル変数にhDllInstを作りました。最初にこれにハンドルを 取得しておくと便利です。

WinMain, InitApp, InitInstanceの各関数に変更はありません。

//ウィンドウプロシージャ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { int id, nBtn, i; static HWND hEdit, hEdit_hide, hTool1, hTool2, hTool3, hToolMenuW, hRebar, hStatic, hStatus, hTip[3]; static HINSTANCE hInst; CREATESTRUCT *lpcs; char szWinTitle[64], szMenuName[32]; INITCOMMONCONTROLSEX ic; REBARINFO ri; REBARBANDINFO rbinfo; RECT rc, rc1, rc2; static int nClientX, nClientY, nRebarH, nStatusH; LPNMHDR lpnmhdr; int sb_size[3]; static HMENU hMenu; HMENU hToolMenu, hPopup; LPNMTOOLBAR lpnmTB; TPMPARAMS tpm; static COLORREF crTipText = RGB(255, 0, 0), crTipBk = RGB(255, 255, 255); NMREBARCHEVRON *lpnmchevron; int nHideBtn = 0; HMENU hPopMenu, hSubMenu; char szResourceName[32]; POINT pt; RECT rc1_scr, rc2_scr, rc3_scr; MYINITIALDATA myinit; switch (msg) { case WM_CREATE: memset(&myinit, 0, sizeof(MYINITIALDATA)); GetInitialSetting(&myinit); if (myinit.wx != 0 && myinit.wy != 0) { MoveWindow(hWnd, myinit.x, myinit.y, myinit.wx, myinit.wy, TRUE); } ic.dwSize = sizeof(INITCOMMONCONTROLSEX); ic.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES; InitCommonControlsEx(&ic); wsprintf(szWinTitle, lpszWinTitleOrg, "無題"); SetWindowText(hWnd, szWinTitle); lpcs = (CREATESTRUCT *)lp; hInst = lpcs->hInstance; hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL | ES_AUTOHSCROLL | WS_HSCROLL | WS_VSCROLL, 0, 0, 0, 0, hWnd, (HMENU)ID_EDIT, hInst, NULL); hEdit_g = hEdit; OrgEditProc = (WNDPROC)GetWindowLong(hEdit, GWL_WNDPROC); SetWindowLong(hEdit, GWL_WNDPROC, (LONG)NewEditProc); hEdit_hide = CreateWindow("EDIT", "", WS_CHILD, 0, 0, 0, 0, hEdit, (HMENU)ID_EDIT2, hInst, NULL); hStatic = CreateWindow("STATIC", "", WS_CHILD | WS_VISIBLE | SS_SUNKEN, 0, 0, 0, 0, hWnd, (HMENU)ID_STATIC, hInst, NULL); hRebar = CreateWindowEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | RBS_BANDBORDERS | RBS_VARHEIGHT, 0, 0, 0, 0, hWnd, (HMENU)ID_REBAR, hInst, NULL); hToolMenuW = MakeMyToolbarMenu(hRebar); hMytoolMenu = hToolMenuW; hTool1 = MakeMyToolbar(hRebar, 3, tbButton1, ID_TOOL1); hTool2 = MakeMyToolbar(hRebar, 5, tbButton2, ID_TOOL2); hTool2_g = hTool2; hTool3 = MakeMyToolbar2(hRebar, 3, tbButton3, ID_TOOL3, IDR_TOOLBAR3, IDR_TOOLBAR3X); hStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE, "", hWnd, ID_STATUS); memset(&ri, 0, sizeof(REBARINFO)); ri.cbSize = sizeof(REBARINFO); ri.fMask = 0; ri.himl = NULL; SendMessage(hRebar, RB_SETBARINFO, 0, (LPARAM)&ri); memset(&rbinfo, 0, sizeof(REBARBANDINFO)); rbinfo.cbSize = sizeof(REBARBANDINFO); rbinfo.fMask = RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_IDEALSIZE; rbinfo.fStyle = RBBS_CHILDEDGE | RBBS_USECHEVRON; rbinfo.hwndChild = hToolMenuW; rbinfo.cxMinChild = 0; rbinfo.cyMinChild = 22; rbinfo.cxIdeal = 280; rbinfo.cx = 280; SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbinfo); rbinfo.fStyle = RBBS_CHILDEDGE | RBBS_USECHEVRON | RBBS_BREAK; rbinfo.hwndChild = hTool1; rbinfo.cxMinChild = 0; rbinfo.cxIdeal = 69; rbinfo.cx = 85; SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbinfo); rbinfo.fStyle = RBBS_CHILDEDGE | RBBS_USECHEVRON; GetWindowRect(hRebar, &rc); rbinfo.hwndChild = hTool2; rbinfo.cxMinChild = 0; rbinfo.cxIdeal = 115; rbinfo.cx = 131; SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbinfo); rbinfo.hwndChild = hTool3; rbinfo.cxMinChild = 0; rbinfo.cx = 79; rbinfo.cxIdeal = 95; SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbinfo); hTip[0] = MakeMyToolTip(hWnd, hTool1, 0, 2, tbButton1, szTipText1); hTip[1] = MakeMyToolTip(hWnd, hTool2, 0, 4, tbButton2, szTipText2); hTip[2] = MakeMyToolTip(hWnd, hTool3, 0, 2, tbButton3, szTipText3); if (myinit.crTipText != 0 && myinit.crTipText != 0) { crTipText = myinit.crTipText; crTipBk = myinit.crTipBackground; for (i = 0; i < 3; i++) { SendMessage(hTip[i], TTM_SETTIPBKCOLOR, (WPARAM)crTipBk, 0); SendMessage(hTip[i], TTM_SETTIPTEXTCOLOR, (WPARAM)crTipText, 0); } } hDllInst = (HINSTANCE)LoadLibrary(szExeName); SendMessage(hEdit, MY_MSG, 0, (LPARAM)hTool2); hHook = SetWindowsHookEx(WH_KEYBOARD, KbdHook, (HINSTANCE)hInst, 0); if (hHook == NULL) MessageBox(hWnd, "フック失敗", "Error", MB_OK); break; case WM_SIZE: nClientX = LOWORD(lp); nClientY = HIWORD(lp); MoveWindow(hStatic , 0, 0, nClientX, 2, TRUE); GetWindowRect(hRebar, &rc); nRebarH = rc.bottom - rc.top; GetWindowRect(hStatus, &rc); nStatusH = rc.bottom - rc.top; SendMessage(hRebar, WM_SIZE, wp, lp); sb_size[2] = nClientX; sb_size[1] = nClientX - 200; sb_size[0] = 300; SendMessage(hStatus, SB_SETPARTS, (WPARAM)3, (LPARAM)sb_size); SendMessage(hStatus, WM_SIZE, wp, lp); MoveWindow(hEdit, 0, nRebarH + 2, LOWORD(lp), HIWORD(lp) - (nRebarH + 2 + nStatusH), TRUE); SetFocus(hEdit); break; case WM_MENUSELECT: switch (LOWORD(wp)) { case IDM_NEW: MySetStatusText(hStatus, 0, szTipText1[0]); break; case IDM_OPEN: MySetStatusText(hStatus, 0, szTipText1[1]); break; case IDM_SAVE: MySetStatusText(hStatus, 0, szTipText1[2]); break; case IDM_COPY: MySetStatusText(hStatus, 0, szTipText2[0]); break; case IDM_CUT: MySetStatusText(hStatus, 0, szTipText2[1]); break; case IDM_PASTE: MySetStatusText(hStatus, 0, szTipText2[2]); break; case IDM_DELETE: MySetStatusText(hStatus, 0, szTipText2[3]); break; case IDM_UNDO: MySetStatusText(hStatus, 0, szTipText2[4]); break; case IDM_BASICINPUT: MySetStatusText(hStatus, 0, szTipText3[0]); break; case IDM_SCRIPT: MySetStatusText(hStatus, 0, szTipText3[1]); break; case IDM_SAVEAS: MySetStatusText(hStatus, 0, "名前を付けて保存します"); break; case IDM_END: MySetStatusText(hStatus, 0, "このアプリケーションを終了します"); break; case IDM_ALL: MySetStatusText(hStatus, 0, "すべてを選択状態にします"); break; case IDM_P: MySetStatusText(hStatus, 0, "<P>タグを挿入します"); break; case IDM_BR: MySetStatusText(hStatus, 0, "<BR>タグを挿入します"); break; case IDM_H: MySetStatusText(hStatus, 0, "<H>タグを挿入します"); break; case IDM_IMAGE: MySetStatusText(hStatus, 0, "<IMG>タグを挿入します"); break; case IDM_A: MySetStatusText(hStatus, 0, "<A HREF>タグを挿入します"); break; case IDM_TABLE: MySetStatusText(hStatus, 0, "<TABLE>タグを挿入します"); break; case IDM_FORM: MySetStatusText(hStatus, 0, "<FORM>タグを挿入します"); break; case IDM_INPUT: MySetStatusText(hStatus, 0, "<INPUT>タグを挿入します"); break; case IDM_BROWSER: MySetStatusText(hStatus, 0, "作成したHTML文書をブラウザで表示します"); break; case IDM_TIPTXTCOLOR: MySetStatusText(hStatus, 0, "ツールチップの文字色を設定します"); break; case IDM_TIPBKCOLOR: MySetStatusText(hStatus, 0, "ツールチップの背景色を設定します"); break; default: MySetStatusText(hStatus, 0, ""); break; } break; case WM_EXITMENULOOP: MySetStatusText(hStatus, 0, ""); SendMessage(hMytoolMenu, TB_SETHOTITEM, (WPARAM)-1, 0); break; case WM_NOTIFY: lpnmhdr = (LPNMHDR)lp; if (lpnmhdr->code == TTN_POP) { MySetStatusText(hStatus, 0, ""); return 0; } switch (wp) { case IDM_NEW: MySetStatusText(hStatus, 0, szTipText1[0]); break; case IDM_OPEN: MySetStatusText(hStatus, 0, szTipText1[1]); break; case IDM_SAVE: MySetStatusText(hStatus, 0, szTipText1[2]); break; case IDM_COPY: MySetStatusText(hStatus, 0, szTipText2[0]); break; case IDM_CUT: MySetStatusText(hStatus, 0, szTipText2[1]); break; case IDM_PASTE: MySetStatusText(hStatus, 0, szTipText2[2]); break; case IDM_DELETE: MySetStatusText(hStatus, 0, szTipText2[3]); break; case IDM_UNDO: MySetStatusText(hStatus, 0, szTipText2[4]); break; case IDM_BASICINPUT: MySetStatusText(hStatus, 0, szTipText3[0]); break; case IDM_SCRIPT: MySetStatusText(hStatus, 0, szTipText3[1]); break; case IDM_TAG: MySetStatusText(hStatus, 0, szTipText3[2]); break; case ID_TOOL3: if (lpnmhdr->hwndFrom == hTool3 && lpnmhdr->code == TBN_DROPDOWN) { lpnmTB = (LPNMTOOLBAR)lp; SendMessage(hTool3, TB_GETRECT, (WPARAM)lpnmTB->iItem, (LPARAM)&rc); MapWindowPoints(hTool3, HWND_DESKTOP, (LPPOINT)&rc, 2); tpm.cbSize = sizeof(TPMPARAMS); tpm.rcExclude.top = rc.top; tpm.rcExclude.left = rc.left; tpm.rcExclude.bottom = rc.bottom; tpm.rcExclude.right = rc.right; switch (lpnmTB->iItem) { case IDM_TAG: lstrcpy(szMenuName, "INSERT"); break; } hToolMenu = LoadMenu(hDllInst, szMenuName); hPopup = GetSubMenu(hToolMenu, 0); TrackPopupMenuEx(hPopup, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL, rc.left, rc.bottom, hWnd, &tpm); DestroyMenu(hToolMenu); } else { return (DefWindowProc(hWnd, msg, wp, lp)); } break; case ID_REBAR: switch (lpnmhdr->code) { case RBN_HEIGHTCHANGE: GetWindowRect(hRebar, &rc); nRebarH = rc.bottom - rc.top; MoveWindow(hEdit, 0, nRebarH + 2, nClientX, nClientY - nRebarH - 2 - nStatusH, TRUE); break; case RBN_CHEVRONPUSHED: lpnmchevron = (NMREBARCHEVRON *)lp; if (SendMessage(hRebar, RB_GETRECT, (WPARAM)lpnmchevron->uBand, (LPARAM)&rc1) == 0) { MessageBox(hWnd, "RB_GETRECT ERROR", "OK", MB_OK); return FALSE; } pt.x = rc1.left; pt.y = rc1.top; ClientToScreen(hRebar, &pt); rc1_scr.left = pt.x; rc1_scr.top = pt.y; pt.x = rc1.right; pt.y = rc1.bottom; ClientToScreen(hRebar, &pt); rc1_scr.right = pt.x; rc1_scr.bottom = pt.y; memset(&rbinfo, 0, sizeof(REBARBANDINFO)); rbinfo.cbSize = sizeof(REBARBANDINFO); rbinfo.fMask = RBBIM_CHILD; if (SendMessage(hRebar, RB_GETBANDINFO, (WPARAM)lpnmchevron->uBand, (LPARAM)&rbinfo) == 0) MessageBox(hWnd, "Error RB_GETBANDINFO", "Error", MB_OK); nBtn = SendMessage(rbinfo.hwndChild, TB_BUTTONCOUNT, 0, 0); for (i = 0; i < nBtn; i++) { SendMessage(rbinfo.hwndChild, TB_GETITEMRECT, (WPARAM)i, (LPARAM)&rc2); pt.x = rc2.left; pt.y = rc2.top; ClientToScreen(rbinfo.hwndChild, &pt); rc2_scr.left = pt.x; rc2_scr.top = pt.y; pt.x = rc2.right; pt.y = rc2.bottom; ClientToScreen(rbinfo.hwndChild, &pt); rc2_scr.right = pt.x; rc2_scr.bottom = pt.y; IntersectRect(&rc3_scr, &rc2_scr, &rc1_scr); if (!EqualRect(&rc2_scr, &rc3_scr)) { nHideBtn = nBtn - i; break; } } if (rbinfo.hwndChild == hToolMenuW) { strcpy(szResourceName, "MYMENU2"); } else if (rbinfo.hwndChild == hTool1) { strcpy(szResourceName, "FILE"); } else if (rbinfo.hwndChild == hTool2) { strcpy(szResourceName, "EDIT"); } else if (rbinfo.hwndChild == hTool3) { strcpy(szResourceName, "INSERT2"); } else { MessageBox(hWnd, "Error", "Error", MB_OK); return FALSE; } hPopMenu = LoadMenu(hDllInst, szResourceName); if (hPopMenu == NULL) { MessageBox(hWnd, "LoadMenu Error", "Error", MB_OK); break; } hSubMenu = GetSubMenu(hPopMenu, 0); if (nHideBtn == 0) nHideBtn = 1; for (i = 0; i < nBtn - nHideBtn; i++) { if (DeleteMenu(hSubMenu, 0, MF_BYPOSITION) == 0) { MessageBox(hWnd, "DeleteMenu Error", "Error", MB_OK); return 0; } } CheckMyMenu(hPopMenu, hEdit, hTool2); TrackPopupMenu(hSubMenu, TPM_LEFTALIGN, rc1_scr.right-10, rc1_scr.bottom, 0, hWnd, NULL); DestroyMenu(hPopMenu); break; default: return DefWindowProc(hWnd, msg, wp, lp); } break; } break; case WM_COMMAND: switch (LOWORD(wp)) { case IDM_END: SendMessage(hWnd, WM_CLOSE, 0, 0); break; case IDM_BASICINPUT: if (MyBasicInput(hEdit) == IDCANCEL) break; id = MessageBox(hWnd, "現在のソースファイルが置き換わりますがよろしいですか", "注意", MB_YESNO | MB_ICONQUESTION); if (id == IDNO) break; if (MySetHTML(hEdit, hEdit_hide)) MySetStatusText(hStatus, 0, "基本項目を入力しました"); break; case IDM_SAVEAS: MySaveAs(hEdit); wsprintf(szWinTitle, lpszWinTitleOrg, szFileTitle); SetWindowText(hWnd, szWinTitle); break; case IDM_NEW: if (SendMessage(hEdit, EM_GETMODIFY, 0, 0)) { id = MessageBox(hWnd, "変更を保存しますか", "注意", MB_YESNO | MB_ICONQUESTION); if (id == IDYES) MySave(hEdit); } SendMessage(hEdit, EM_SETSEL, (WPARAM)0, (LPARAM)-1); SendMessage(hEdit, WM_CLEAR, 0, 0); strcpy(szFileName, ""); strcpy(szFileTitle, ""); wsprintf(szWinTitle, lpszWinTitleOrg, "無題"); SetWindowText(hWnd, szWinTitle); break; case IDM_SAVE: id = MessageBox(hWnd, "上書きしてもよろしいですか", "上書き保存", MB_YESNO | MB_ICONQUESTION); if (id == IDYES) { MySave(hEdit); wsprintf(szWinTitle, lpszWinTitleOrg, szFileTitle); SetWindowText(hWnd, szWinTitle); } break; case IDM_P: MyInsertTag(hEdit, hEdit_hide, "<P>"); MySetStatusText(hStatus, 0, "<P>タグを挿入しました"); break; case IDM_BR: MyInsertTag(hEdit, hEdit_hide, "<BR>"); MySetStatusText(hStatus, 0, "<BR>タグを挿入しました"); break; case IDM_H: if (MyInsertH(hEdit, hEdit_hide)) MySetStatusText(hStatus, 0, "<H>タグを挿入しました");; break; case IDM_IMAGE: if (MyInsertIMG(hEdit, hEdit_hide)) MySetStatusText(hStatus, 0, "イメージを挿入しました"); break; case IDM_BROWSER: if (strcmp(szFileName, "") == 0) { MessageBox(hWnd, "まだHTMLファイルが保存されていません", "Error", MB_OK); break; } if (ShellExecute(NULL, "open", szFileName, NULL, NULL, SW_SHOWNORMAL) > (HINSTANCE)32) { MySetStatusText(hStatus, 0, "ブラウザが起動しました"); } else { MySetStatusText(hStatus, 0, "ブラウザの起動に失敗"); } return 0; case IDM_A: if (MyInsertA(hEdit, hEdit_hide)) MySetStatusText(hStatus, 0, "<A>タグを挿入しました"); break; case IDM_TABLE: if (MyInsertTable(hEdit, hEdit_hide)) MySetStatusText(hStatus, 0, "テーブルを挿入しました"); break; case IDM_FORM: if (MyInsertForm(hEdit, hEdit_hide)) MySetStatusText(hStatus, 0, "<FORM>タグを挿入しました"); break; case IDM_INPUT: if (MyInsertInput(hEdit, hEdit_hide)) MySetStatusText(hStatus, 0, "<INPUT>タグを挿入しました"); break; case IDM_SCRIPT: if (MyInsertScript(hEdit, hEdit_hide)) MySetStatusText(hStatus, 0, "<SCRIPT>タグを挿入しました"); break; case IDM_OPEN: MyOpen(hEdit, hEdit_hide); break; case IDM_COPY: SendMessage(hEdit, WM_COPY, 0, 0); break; case IDM_CUT: SendMessage(hEdit, WM_CUT, 0, 0); break; case IDM_PASTE: SendMessage(hEdit, WM_PASTE, 0, 0); break; case IDM_UNDO: SendMessage(hEdit, WM_UNDO, 0, 0); break; case IDM_DELETE: SendMessage(hEdit, WM_CLEAR, 0, 0); break; case IDM_ALL: SendMessage(hEdit, EM_SETSEL, (WPARAM)0, (LPARAM)-1); break; case IDM_TIPTXTCOLOR: SetTipColor(hEdit, hTip, &crTipText, 3); break; case IDM_TIPBKCOLOR: SetTipBkColor(hEdit, hTip, &crTipBk, 3); break; //メニュー型ツールバー case IDM_FILE: ShowMyPopMenu(hWnd, hToolMenuW, "MYMENU", 0, hEdit, hTool2); break; case IDM_EDIT: ShowMyPopMenu(hWnd, hToolMenuW, "MYMENU", 1, hEdit, hTool2); break; case IDM_INSERT: ShowMyPopMenu(hWnd, hToolMenuW, "MYMENU", 2, hEdit, hTool2); break; case IDM_BRVIEW: ShowMyPopMenu(hWnd, hToolMenuW, "MYMENU", 3, hEdit, hTool2); break; case IDM_OPTION: ShowMyPopMenu(hWnd, hToolMenuW, "MYMENU", 4, hEdit, hTool2); break; //画像ファイルGIFの呼び出し・出力 case IDM_WHAT: MyCreateFileFromResource(hEdit, hEdit_hide, "WHAT", "GIF", "what.gif"); break; case IDM_MAILTO: MyCreateFileFromResource(hEdit, hEdit_hide, "MAIL", "GIF", "mail.gif"); break; case IDM_HOME: MyCreateFileFromResource(hEdit, hEdit_hide, "HOME", "GIF", "home.gif"); break; case IDM_INDEX: MyCreateFileFromResource(hEdit, hEdit_hide, "INDEX", "GIF", "index.gif"); break; case IDM_BACK: MyCreateFileFromResource(hEdit, hEdit_hide, "BACK", "GIF", "back.gif"); break; case IDM_CONTENTS: MyCreateFileFromResource(hEdit, hEdit_hide, "CONTENTS", "GIF", "contents.gif"); break; } CheckMyMenu(hMenu, hEdit, hTool2); SetFocus(hEdit); break; case WM_CLOSE: id = MessageBox(hWnd, "終了してもよいですか", "終了確認", MB_YESNO | MB_ICONQUESTION); if (id == IDYES) { if (SendMessage(hEdit, EM_GETMODIFY, 0, 0)) { id = MessageBox(hWnd, "変更を保存しますか", "保存", MB_YESNO | MB_ICONQUESTION); if (id == IDYES) MySave(hEdit); } FreeLibrary(hDllInst); UnhookWindowsHookEx(hHook); GetWindowRect(hWnd, &rc); myinit.x = rc.left; myinit.y = rc.top; myinit.wx = rc.right - rc.left; myinit.wy = rc.bottom - rc.top; myinit.crTipText = crTipText; myinit.crTipBackground = crTipBk; SetInitialSetting(&myinit); SetWindowLong(hEdit, GWL_WNDPROC, (LONG)OrgEditProc); ImageList_Destroy(hImage); DestroyWindow(hTip[0]); DestroyWindow(hTip[1]); DestroyWindow(hTip[2]); DestroyWindow(hTool1); DestroyWindow(hTool2); DestroyWindow(hTool3); DestroyWindow(hRebar); DestroyWindow(hStatus); DestroyWindow(hStatic); DestroyWindow(hEdit_hide); DestroyWindow(hEdit); DestroyWindow(hWnd); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return (DefWindowProc(hWnd, msg, wp, lp)); } return 0; }

メイン・ウィンドウのプロシージャです。

WM_CREATEメッセージが来たら、LoadLibrary関数でモジュールハンドルを 取得しておきます。このハンドルは同一のプロセス内でしか使わないので、 グローバル変数にコピーして使い回してかまいません。

WM_NOTIFYメッセージが来てwpがID_TOOL3の時、LoadMenu関数の第1引数はhDllInstになります。

RBN_CHEVRONPUSHEDの時も同じです。

プログラム終了時にFreeLibrary関数を呼んでおきます。

MySetHTML, MyBasicInput, MyBasicInputProc, MySaveAs, MySave, MyInsertTag, MyInsertH, MyHProc, MyInsertIMG, MyImgProc, MyGetFileTitle, MyGetBodyColor, MyGetWallPaper, MyInsertA, MyAProc, MyGetHREFFile, MyInsertTable, MyTableProc, MyInsertForm, MyFormProc, MyInputProc, MyInsertInput, MyInsertScript, MakeMyToolbar, MyOpen, CheckMyMenu, CanPaste, NewEditProc, MySetStatusText, MakeMyToolbar2, MakeMyToolTip, SetTipColor, SetTipBkColor, GetInitialSetting, SetInitialSetting, MakeMyToolbarMenu これらの関数に変更はありません。

BOOL ShowMyPopMenu(HWND hWnd, HWND hToolMenuW, char *szMenuName, int nId, HWND hEdit, HWND hTool2) { RECT rc, rc_scr; POINT pt; HMENU hMenu, hSubMenu; int nCommandID[] = {IDM_FILE, IDM_EDIT, IDM_INSERT, IDM_BRVIEW, IDM_OPTION}; SendMessage(hToolMenuW, TB_GETITEMRECT, (WPARAM)nId, (LPARAM)&rc); pt.x = rc.left; pt.y = rc.top; ClientToScreen(hToolMenuW, &pt); rc_scr.left = pt.x; rc_scr.top = pt.y; pt.x = rc.right; pt.y = rc.bottom; ClientToScreen(hToolMenuW, &pt); rc_scr.right = pt.x; rc_scr.bottom = pt.y; hMenu = LoadMenu(hDllInst, szMenuName); if (hMenu == NULL) { MessageBox(hWnd, "LoadMenu Error", "Error", MB_OK); return FALSE; } hSubMenu = GetSubMenu(hMenu, nId); CheckMyMenu(hMenu, hEdit, hTool2); SendMessage(hToolMenuW, TB_SETHOTITEM, (WPARAM)-1, 0); SendMessage(hToolMenuW, TB_SETSTATE, (WPARAM)nCommandID[nId], ((LPARAM)MAKELONG(TBSTATE_ENABLED | TBSTATE_PRESSED, 0))); TrackPopupMenu(hSubMenu, TPM_LEFTALIGN, rc_scr.left, rc_scr.bottom, 0, hWnd, NULL); DestroyMenu(hMenu); SendMessage(hToolMenuW, TB_SETSTATE, (WPARAM)nCommandID[nId], ((LPARAM)MAKELONG(TBSTATE_ENABLED, 0))); return TRUE; }

この関数内でもLoadMenu関数の第1引数はhDllInstを使います。

KbdHook, MyCreateFileFromResourceの各関数に変更はありません。

今回は、ちょっと面倒くさいでしたが全体としてはたいした変更はありませんでした。
[SDK第4部 Index] [総合Index] [Previous Chapter] [Next Chapter]

Update 28/Aug/2001 By Y.Kumei
当ホーム・ページの一部または全部を無断で複写、複製、 転載あるいはコンピュータ等のファイルに保存することを禁じます。