フック関係のプロトタイプ宣言やら、グローバル変数が追加になっています。// htmedit11.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> 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); char szClassName[] = "htmedit11"; //ウィンドウクラス 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; 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の基本的枠組みを作ります", "スクリプトを挿入します", "タグを挿入します" };
また、hTool2やhEditをどうしてもグローバル変数にしておかなくてはならない事情が できてやむを得ずhTol2_g, hEdit_gという変数を作りました。
これは、いつもと同じです。int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow) { MSG msg; HACCEL hAccel; if (!InitApp(hCurInst)) return FALSE; if (!InitInstance(hCurInst, nCmdShow)) return FALSE; hAccel = LoadAccelerators(hCurInst, "MYACCEL"); if (hParent == NULL) { MessageBox(NULL, "ハンドルなし", "", MB_OK); return 0; } while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(hParent, hAccel, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } //ウィンドウ・クラスの登録 ATOM InitApp(HINSTANCE hInst) { WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; //プロシージャ名 wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInst;//インスタンス wc.hIcon = LoadIcon(hInst, "MYICON"); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // wc.lpszMenuName = "MYMENU"; //メニュー名, 今回は不要 wc.lpszClassName = (LPCSTR)szClassName; wc.hIconSm = LoadIcon(hInst, "MYICON"); return (RegisterClassEx(&wc)); } //ウィンドウの生成 BOOL InitInstance(HINSTANCE hInst, int nCmdShow) { HWND hWnd; hWnd = CreateWindow(szClassName, "猫でもわかるHTMLエディタ", //タイトルバーにこの名前が表示されます WS_OVERLAPPEDWINDOW, //ウィンドウの種類 CW_USEDEFAULT, //X座標 CW_USEDEFAULT, //Y座標 CW_USEDEFAULT, //幅 CW_USEDEFAULT, //高さ NULL, //親ウィンドウのハンドル、親を作るときはNULL NULL, //メニューハンドル、クラスメニューを使うときはNULL hInst, //インスタンスハンドル NULL); if (!hWnd) return FALSE; hParent = hWnd; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; }
メインウィンドウのプロシージャです。//ウィンドウプロシージャ 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); } } hMenu = GetMenu(hWnd); 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(hInst, 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(hInst, 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; } 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); } 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メッセージが来たときに、hEdit, hToolMenuW, hTool2をグローバル変数に コピーしています。
また、キーボードフックをしています。
WM_EXITMENULOOPメッセージが来たときに、メニュー様ツールバーのホットアイテムを 解除しています。
プログラム終了時に、フックを解除しています。
この続きは、次章に表示します。BOOL MySetHTML(HWND hEdit, HWND hEdit_hide) { char szBuf[1024*10]; strcpy(szBuf, lpszHead); strcat(szBuf, szTitle); strcat(szBuf, lpszBody1); strcat(szBuf, szBody2); strcat(szBuf, lpszBody3); strcat(szBuf, lpszAddress); strcat(szBuf, lpszMailto); strcat(szBuf, szEMail); strcat(szBuf, lpszMailEnd); strcat(szBuf, szAuthor); strcat(szBuf, lpszCloseA); strcat(szBuf, lpszEnd); SetWindowText(hEdit, ""); MyInsertTag(hEdit, hEdit_hide, szBuf); return TRUE; } int MyBasicInput(HWND hEdit) { HINSTANCE hInst; int id; hInst = (HINSTANCE)GetWindowLong(hEdit, GWL_HINSTANCE); id = DialogBox(hInst, "MYBASICINPUT", hEdit, (DLGPROC)MyBasicInputProc); return id; } LRESULT CALLBACK MyBasicInputProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp) { static HWND hTitle, hName, hEMail, hWallPaper, hColor, hNotSpecify; static int nBack; //0:nothing 1:Color 2:WallPaper switch (msg) { case WM_INITDIALOG: strcpy(szBody2, ""); hTitle = GetDlgItem(hDlg, IDC_EDIT1); hName = GetDlgItem(hDlg, IDC_EDIT2); hEMail = GetDlgItem(hDlg, IDC_EDIT3); hWallPaper = GetDlgItem(hDlg, IDC_RADIO2); hColor = GetDlgItem(hDlg, IDC_RADIO1); hNotSpecify = GetDlgItem(hDlg, IDC_RADIO3); SetWindowText(hTitle, szTitle); SetWindowText(hName, szAuthor); SetWindowText(hEMail, szEMail); SetFocus(hTitle); switch (nBack) { case 0: Button_SetCheck(hNotSpecify, BST_CHECKED); break; case 1: Button_SetCheck(hColor, BST_CHECKED); break; case 2: Button_SetCheck(hWallPaper, BST_CHECKED); break; default: MessageBox(hDlg, "内部エラーです", "Error", MB_OK); break; } return TRUE; case WM_COMMAND: switch (LOWORD(wp)) { case IDOK: Edit_GetText(hTitle, szTitle, sizeof(szTitle)); Edit_GetText(hName, szAuthor, sizeof(szAuthor)); Edit_GetText(hEMail, szEMail, sizeof(szEMail)); if (Button_GetCheck(hColor) == BST_CHECKED) { if (!MyGetBodyColor(hDlg)) break; nBack = 1; } if (Button_GetCheck(hWallPaper) == BST_CHECKED) { if (!MyGetWallPaper(hDlg)) break; nBack = 2; } if (Button_GetCheck(hNotSpecify) == BST_CHECKED) { nBack = 0; } EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; } return FALSE; } return FALSE; } BOOL MySaveAs(HWND hEdit) { OPENFILENAME ofn; HANDLE hFile; char szBuf[MY_BUF_SIZE]; DWORD dwWritten; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hEdit; ofn.lpstrFilter = "htmlファイル\0*.htm;*.html\0All Files(*.*)\0*.*\0\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = sizeof(szFileTitle); ofn.lpstrDefExt = "html"; ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; if (GetSaveFileName(&ofn)) { hFile = CreateFile(szFileName, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { MessageBox(hEdit, "ファイルのオープンに失敗しました", "Error", MB_OK); return FALSE; } Edit_GetText(hEdit, szBuf, MY_BUF_SIZE); WriteFile(hFile, szBuf, strlen(szBuf), &dwWritten, NULL); SetEndOfFile(hFile); CloseHandle(hFile); SendMessage(hEdit, EM_SETMODIFY, (WPARAM)FALSE, 0); } return TRUE; } BOOL MySave(HWND hEdit) { HANDLE hFile; char szBuf[MY_BUF_SIZE]; DWORD dwWritten; if (strcmp(szFileName, "") == 0) { MessageBox(hEdit, "まず名前を付けて保存してください。", "確認", MB_OK); MySaveAs(hEdit); return TRUE; } Edit_GetText(hEdit, szBuf, MY_BUF_SIZE); hFile = CreateFile(szFileName, GENERIC_WRITE, 0, 0, TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { MessageBox(hEdit, "ファイルをオープンできません", "Error", MB_OK); return FALSE; } WriteFile(hFile, szBuf, strlen(szBuf), &dwWritten, NULL); if (strlen(szBuf) != dwWritten) { MessageBox(hEdit, "書き込みに失敗しました", "Error", MB_OK); CloseHandle(hFile); return FALSE; } CloseHandle(hFile); SendMessage(hEdit, EM_SETMODIFY, (WPARAM)FALSE, 0); return TRUE; } BOOL MyInsertTag(HWND hEdit1, HWND hEdit2, char *lpszTag) { SetWindowText(hEdit2, lpszTag); SendMessage(hEdit2, EM_SETSEL, (WPARAM)0, (LPARAM)-1); SendMessage(hEdit2, WM_COPY, 0, 0); SendMessage(hEdit1, WM_PASTE, 0, 0); return TRUE; } BOOL MyInsertH(HWND hEdit, HWND hEdit_hide) { HINSTANCE hInst; MYHTAG myh; char szBuf[512]; hInst = (HINSTANCE)GetWindowLong(hEdit, GWL_HINSTANCE); if (DialogBoxParam(hInst, "MYHTAG", hEdit, (DLGPROC)MyHProc, (LPARAM)&myh) == IDCANCEL) return FALSE; strcpy(szBuf, "<H"); strcat(szBuf, myh.szTagNo); strcat(szBuf, ">"); strcat(szBuf, myh.szContents); strcat(szBuf, "</H"); strcat(szBuf, myh.szTagNo); strcat(szBuf, ">"); MyInsertTag(hEdit, hEdit_hide, szBuf); return TRUE; } LRESULT CALLBACK MyHProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp) { static HWND hCombo, hEditContents; static LPMYHTAG lpmyh; switch (msg) { case WM_INITDIALOG: lpmyh = (LPMYHTAG)lp; hCombo = GetDlgItem(hDlg, IDC_COMBO1); hEditContents = GetDlgItem(hDlg, IDC_EDIT1); ComboBox_AddString(hCombo, "1"); ComboBox_AddString(hCombo, "2"); ComboBox_AddString(hCombo, "3"); ComboBox_AddString(hCombo, "4"); ComboBox_AddString(hCombo, "5"); ComboBox_AddString(hCombo, "6"); return TRUE; case WM_COMMAND: switch (LOWORD(wp)) { case IDOK: ComboBox_GetText(hCombo, lpmyh->szTagNo, sizeof(lpmyh->szTagNo)); Edit_GetText(hEditContents, lpmyh->szContents, sizeof(lpmyh->szContents)); EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; case IDC_COMBO1: if (HIWORD(wp) == CBN_SELCHANGE) { SetFocus(hEditContents); return TRUE; } else { return FALSE; } } return FALSE; } return FALSE; } BOOL MyInsertIMG(HWND hEdit, HWND hEdit_hide) { HINSTANCE hInst; MYIMGTAG myimg; char szBuf[1024]; hInst = (HINSTANCE)GetWindowLong(hEdit, GWL_HINSTANCE); if (DialogBoxParam(hInst, "MYIMGTAG", hEdit, (DLGPROC)MyImgProc, (LPARAM)&myimg) == IDCANCEL) return FALSE; strcpy(szBuf, "<IMG SRC=\""); if (myimg.bPath) strcat(szBuf, myimg.szPath); strcat(szBuf, myimg.szFileName); strcat(szBuf, "\">"); MyInsertTag(hEdit, hEdit_hide, szBuf); return TRUE; } LRESULT CALLBACK MyImgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp) { static HWND hButton, hPath, hFile, hCheck, hImg; static LPMYIMGTAG lpimg; static BOOL bImg, bPath; switch (msg) { case WM_INITDIALOG: lpimg = (LPMYIMGTAG)lp; hButton = GetDlgItem(hDlg, IDC_BUTTON1); hCheck = GetDlgItem(hDlg, IDC_CHECK1); hPath = GetDlgItem(hDlg, IDC_EDIT1); hFile = GetDlgItem(hDlg, IDC_EDIT2); hImg = GetDlgItem(hDlg, IDC_CHECK2); if (bImg) Button_SetCheck(hImg, BST_CHECKED); else Button_SetCheck(hImg, BST_UNCHECKED); if (bPath) { EnableWindow(hPath, TRUE); Button_SetCheck(hCheck, BST_CHECKED); } else { EnableWindow(hPath, FALSE); Button_SetCheck(hCheck, BST_UNCHECKED); } return TRUE; case WM_COMMAND: switch (LOWORD(wp)) { case IDOK: Edit_GetText(hFile, lpimg->szFileName, MAX_PATH); if (Button_GetCheck(hCheck) == BST_CHECKED) { Edit_GetText(hPath, lpimg->szPath, MAX_PATH); lpimg->bPath = TRUE; } else { strcpy(lpimg->szPath, ""); lpimg->bPath = FALSE; } EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; case IDC_CHECK1: if (Button_GetCheck(hCheck) == BST_CHECKED) { EnableWindow(hPath, TRUE); SetFocus(hPath); bPath = TRUE; } else { EnableWindow(hPath, FALSE); bPath = FALSE; } return TRUE; case IDC_BUTTON1: MyGetFileTitle(hDlg, hFile, bImg); return TRUE; case IDC_CHECK2: if (Button_GetCheck(hImg) == BST_CHECKED) bImg = TRUE; else bImg = FALSE; return TRUE; } return FALSE; } return FALSE; } BOOL MyGetFileTitle(HWND hDlg, HWND hFile, BOOL bImg) { OPENFILENAME ofn; char szFileTitle[MAX_PATH], szFileName[MAX_PATH]; szFileTitle[0] = '\0'; szFileName[0] = '\0'; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hDlg; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = MAX_PATH; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = "gifファイル\0*.gif\0jpegファイル\0*.jpg;*.jpeg\0すべてのファイル\0*.*\0\0"; ofn.Flags = OFN_HIDEREADONLY; if (!GetOpenFileName(&ofn)) return FALSE; SetWindowText(hFile, szFileTitle); if (bImg) { if (ShellExecute(hDlg, "open", szFileName, NULL, NULL, SW_SHOWNORMAL) <= (HINSTANCE)32) { MessageBox(hDlg, "画像を表示できません", "Error", MB_OK); return FALSE; } } return TRUE; } BOOL MyGetBodyColor(HWND hDlg) { CHOOSECOLOR cc; static COLORREF crResult = RGB(0, 0, 0); static DWORD dwCustColor[16]; char szRed[8], szGreen[8], szBlue[8]; memset(&cc, 0, sizeof(CHOOSECOLOR)); cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = hDlg; cc.rgbResult = crResult; cc.Flags = CC_RGBINIT; cc.lpCustColors = dwCustColor; if (!ChooseColor(&cc)) return FALSE; crResult = cc.rgbResult; wsprintf(szRed, "%02X", GetRValue(crResult)); wsprintf(szGreen, "%02X", GetGValue(crResult)); wsprintf(szBlue, "%02X", GetBValue(crResult)); strcpy(szBody2, " BGCOLOR=\"#"); strcat(szBody2, szRed); strcat(szBody2, szGreen); strcat(szBody2, szBlue); strcat(szBody2, "\""); return TRUE; } BOOL MyGetWallPaper(HWND hDlg) { HINSTANCE hInst; MYIMGTAG myimg; hInst = (HINSTANCE)GetWindowLong(hDlg, GWL_HINSTANCE); if (DialogBoxParam(hInst, "MYIMGTAG", hDlg, (DLGPROC)MyImgProc, (LPARAM)&myimg) == IDCANCEL) return FALSE; strcpy(szBody2, " BACKGROUND=\""); if (myimg.bPath) strcat(szBody2, myimg.szPath); strcat(szBody2, myimg.szFileName); strcat(szBody2, "\""); return TRUE; } BOOL MyInsertA(HWND hEdit, HWND hEdit_hide) { HINSTANCE hInst; MYIMGTAG myatag; char szBuf[1024]; hInst = (HINSTANCE)GetWindowLong(hEdit, GWL_HINSTANCE); if (DialogBoxParam(hInst, "MYIMGTAG", hEdit, (DLGPROC)MyAProc, (LPARAM)&myatag) == IDCANCEL) return FALSE; strcpy(szBuf, "<A HREF=\""); if (myatag.bPath) strcat(szBuf, myatag.szPath); strcat(szBuf, myatag.szFileName); strcat(szBuf, "\"></A>"); MyInsertTag(hEdit, hEdit_hide, szBuf); return TRUE; } LRESULT CALLBACK MyAProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp) { static HWND hPath, hFile, hCheck1, hCheck2; static LPMYIMGTAG lpatag; static BOOL bPath, bKakunin; switch (msg) { case WM_INITDIALOG: lpatag = (LPMYIMGTAG)lp; hPath = GetDlgItem(hDlg, IDC_EDIT1); hFile = GetDlgItem(hDlg, IDC_EDIT2); hCheck1 = GetDlgItem(hDlg, IDC_CHECK1); hCheck2 = GetDlgItem(hDlg, IDC_CHECK2); SetWindowText(hDlg, "A HREFの挿入"); SetWindowText(hCheck2, "ファイルの確認"); if (bKakunin) Button_SetCheck(hCheck2, BST_CHECKED); else Button_SetCheck(hCheck2, BST_UNCHECKED); if (bPath) { EnableWindow(hPath, TRUE); Button_SetCheck(hCheck1, BST_CHECKED); } else { EnableWindow(hPath, FALSE); Button_SetCheck(hCheck1, BST_UNCHECKED); } return TRUE; case WM_COMMAND: switch (LOWORD(wp)) { case IDOK: Edit_GetText(hFile, lpatag->szFileName, MAX_PATH); if (bPath) { Edit_GetText(hPath, lpatag->szPath, MAX_PATH); lpatag->bPath = TRUE; } else { strcpy(lpatag->szPath, ""); lpatag->bPath = FALSE; } EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; case IDC_CHECK1: if (Button_GetCheck(hCheck1) == BST_CHECKED) { EnableWindow(hPath, TRUE); bPath = TRUE; } else { EnableWindow(hPath, FALSE); bPath = FALSE; } return TRUE; case IDC_CHECK2: if (Button_GetCheck(hCheck2) == BST_CHECKED) bKakunin = TRUE; else bKakunin = FALSE; return TRUE; case IDC_BUTTON1: MyGetHREFFile(hDlg, hFile, bKakunin); return TRUE; } return FALSE; } return FALSE; } BOOL MyGetHREFFile(HWND hDlg, HWND hFile, BOOL bKakunin) { OPENFILENAME ofn; char szFileTitle[MAX_PATH], szFileName[MAX_PATH]; szFileTitle[0] = '\0'; szFileName[0] = '\0'; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hDlg; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = MAX_PATH; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = "HTMLファイル\0*.htm;*.html\0すべてのファイル\0*.*\0\0"; ofn.Flags = OFN_HIDEREADONLY; if (!GetOpenFileName(&ofn)) return FALSE; SetWindowText(hFile, szFileTitle); if (bKakunin) { if (ShellExecute(hDlg, "edit", szFileName, NULL, NULL, SW_SHOWNORMAL) <= (HINSTANCE)32) { MessageBox(hDlg, "ファイルを表示できません", "Error", MB_OK); return FALSE; } } return TRUE; } BOOL MyInsertTable(HWND hEdit, HWND hEdit_hide) { HINSTANCE hInst; MYTABLETAG mytable; char szBuf[1024 * 2]; int i, j, nRow, nCol; hInst = (HINSTANCE)GetWindowLong(hEdit, GWL_HINSTANCE); if (DialogBoxParam(hInst, "MYTABLETAG", hEdit, (DLGPROC)MyTableProc, (LPARAM)&mytable) == IDCANCEL) return FALSE; nRow = atoi(mytable.szRow); nCol = atoi(mytable.szColumn); strcpy(szBuf, "<TABLE"); if (mytable.bBorder) { strcat(szBuf, " BORDER=\""); strcat(szBuf, mytable.szBorder); strcat(szBuf, "\""); } strcat(szBuf, ">\r\n"); if (mytable.bTitle) { strcat(szBuf, "<CAPTION ALIGN=\""); strcat(szBuf, mytable.szTitleAlign); strcat(szBuf, "\">"); strcat(szBuf, mytable.szTitle); strcat(szBuf, "</CAPTION>\r\n"); } for (j = 1; j <= nRow; j++) { for (i = 1; i <= nCol; i++) { strcat(szBuf, "<TD></TD>"); } if (j != nRow) strcat(szBuf, "<TR>\r\n"); } strcat(szBuf, "\r\n</TABLE>"); MyInsertTag(hEdit, hEdit_hide, szBuf); return TRUE; } LRESULT CALLBACK MyTableProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp) { static HWND hRow, hCol, hBorderCheck, hBorderEdit, hCapCheck, hCapCombo, hCapEdit; static LPMYTABLETAG lpmytable; char szNum[][4] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; int i; static BOOL bBorder, bCaption; switch (msg) { case WM_INITDIALOG: lpmytable = (LPMYTABLETAG)lp; hRow = GetDlgItem(hDlg, IDC_COMBO1); hCol = GetDlgItem(hDlg, IDC_COMBO2); hBorderCheck = GetDlgItem(hDlg, IDC_CHECK1); hCapCheck = GetDlgItem(hDlg, IDC_CHECK2); hBorderEdit = GetDlgItem(hDlg, IDC_EDIT1); hCapCombo = GetDlgItem(hDlg, IDC_COMBO3); hCapEdit = GetDlgItem(hDlg, IDC_EDIT2); for (i = 0; i < 10; i++) { ComboBox_AddString(hRow, szNum[i]); ComboBox_AddString(hCol, szNum[i]); } ComboBox_SetText(hRow, "1"); ComboBox_SetText(hCol, "1"); ComboBox_AddString(hCapCombo, "top"); ComboBox_AddString(hCapCombo, "bottom"); if (bBorder) { Button_SetCheck(hBorderCheck, BST_CHECKED); ShowWindow(hBorderEdit, SW_SHOW); } else { Button_SetCheck(hBorderCheck, BST_UNCHECKED); ShowWindow(hBorderEdit, SW_HIDE); } if (bCaption) { Button_SetCheck(hCapCheck, BST_CHECKED); ShowWindow(hCapCombo, SW_SHOW); ShowWindow(hCapEdit, SW_SHOW); } else { Button_SetCheck(hCapCheck, BST_UNCHECKED); ShowWindow(hCapCombo, SW_HIDE); ShowWindow(hCapEdit, SW_HIDE); } return TRUE; case WM_COMMAND: switch (LOWORD(wp)) { case IDOK: ComboBox_GetText(hRow, lpmytable->szRow, sizeof(lpmytable->szRow)); ComboBox_GetText(hCol, lpmytable->szColumn, sizeof(lpmytable->szColumn)); if (bBorder) { Edit_GetText(hBorderEdit, lpmytable->szBorder, sizeof(lpmytable->szBorder)); lpmytable->bBorder = TRUE; } else { strcpy(lpmytable->szBorder, ""); lpmytable->bBorder = FALSE; } if (bCaption) { ComboBox_GetText(hCapCombo, lpmytable->szTitleAlign, sizeof(lpmytable->szTitleAlign)); Edit_GetText(hCapEdit, lpmytable->szTitle, sizeof(lpmytable->szTitle)); lpmytable->bTitle = TRUE; } else { strcpy(lpmytable->szTitle, ""); strcpy(lpmytable->szTitleAlign, ""); lpmytable->bTitle = FALSE; } EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; case IDC_CHECK1: if (Button_GetCheck(hBorderCheck) == BST_CHECKED) { ShowWindow(hBorderEdit, SW_SHOW); bBorder = TRUE; } else { ShowWindow(hBorderEdit, SW_HIDE); bBorder = FALSE; } return TRUE; case IDC_CHECK2: if (Button_GetCheck(hCapCheck) == BST_CHECKED) { ShowWindow(hCapCombo, SW_SHOW); ShowWindow(hCapEdit, SW_SHOW); bCaption = TRUE; } else { ShowWindow(hCapCombo, SW_HIDE); ShowWindow(hCapEdit, SW_HIDE); bCaption = FALSE; } return TRUE; } return FALSE; } return FALSE; }
Update 11/Aug/2001 By Y.Kumei