Home > Tips > Win32APIでリッチエディットを実装する際の注意点
To create the Richedit control you must call the LoadLibrary function on the appropriate Richedit dynamic-How To Create Richedit Control Version 2.0 and 3.0 with the Visual Studio Resource Editorより引用しました。
link library (DLL) somewhere prior to attempting to create the control. Doing this allows the control to
register its class name. For example, to use a Richedit version 2.0 or version 3.0 control in a dialog box,
you must call LoadLibrary("riched20.dll") prior to attempting to load and initialize the dialog box resource.
1 2 3 4 5 6 7 8 9 | int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){ hInst=hInstance; hRichDll=LoadLibrary( "Riched20.dll" ); // The user interface is a modal dialog box return DialogBox(hInstance,MAKEINTRESOURCE(DLG_MAIN),NULL,(DLGPROC)DialogProc); } |
1 2 3 4 5 | case WM_CLOSE: EndDialog(hwndDlg,0); FreeLibrary(hRichDll); return TRUE; |
1 2 3 4 5 6 7 8 9 10 11 12 13 | int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){ hInst=hInstance; hRichDll=LoadLibrary( "Riched20.dll" ); // The user interface is a modal dialog box int iResult=DialogBox(hInstance,MAKEINTRESOURCE(DLG_MAIN),NULL,(DLGPROC)DialogProc); if (hRichDll!=NULL)FreeLibrary(hRichDll); return iResult; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <richedit.h> #include "resource.h" HINSTANCE hInst; HINSTANCE hRichDll; BOOL CALLBACK DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch (uMsg){ case WM_INITDIALOG: /* * TODO: Add code to initialize the dialog. */ CHARFORMAT cfm; memset (&cfm,0, sizeof (CHARFORMAT)); cfm.cbSize= sizeof (CHARFORMAT); cfm.dwMask=CFM_COLOR; cfm.crTextColor=RGB(255,0,0); cfm.dwEffects=0; SendMessage(GetDlgItem(hwndDlg,IDC_RICHEDIT1),EM_SETCHARFORMAT,( WPARAM )SCF_SELECTION,( LPARAM )&cfm); SendMessage(GetDlgItem(hwndDlg,IDC_RICHEDIT1),EM_REPLACESEL,( WPARAM )FALSE,( LPARAM ) "リリカル・トカレフ・キルゼムオール♪" ); return TRUE; case WM_CLOSE: EndDialog(hwndDlg,0); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)){ /* * TODO: Add more control ID's, when needed. */ case IDC_BTN_QUIT: EndDialog(hwndDlg,0); return TRUE; case IDC_BTN_TEST: MessageBox(hwndDlg, "You clicked \"Test\" button!" , "Information" ,MB_ICONINFORMATION); return TRUE; default : break ; } } return FALSE; } int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){ hInst=hInstance; hRichDll=LoadLibrary( "Riched20.dll" ); // The user interface is a modal dialog box int iResult=DialogBox(hInstance,MAKEINTRESOURCE(DLG_MAIN),NULL,(DLGPROC)DialogProc); if (hRichDll!=NULL)FreeLibrary(hRichDll); return iResult; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | // Generated by ResEdit 1.5.10 // Copyright (C) 2006-2012 #include <windows.h> #include <commctrl.h> #include <richedit.h> #include "resource.h" // // Dialog resources // LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL DLG_MAIN DIALOGEX 6, 5, 194, 106 STYLE DS_3DLOOK | DS_CENTER | DS_SETFONT | WS_CAPTION | WS_VISIBLE | WS_GROUP | WS_THICKFRAME | WS_SYSMENU CAPTION "Code::Blocks Template Dialog App" FONT 8, "Tahoma" , 0, 0, 1 { PUSHBUTTON "&Test" , IDC_BTN_TEST, 138, 5, 46, 15 PUSHBUTTON "&Quit" , IDC_BTN_QUIT, 138, 29, 46, 15 CONTROL "" , IDC_RICHEDIT1, RICHEDIT_CLASS, WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL, 9, 5, 120, 80 } // // Manifest resources // LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 1 RT_MANIFEST ".\\manifest.xml" |
1 2 3 4 5 6 7 8 9 | #ifndef IDC_STATIC #define IDC_STATIC (-1) #endif #define DLG_MAIN 101 #define IDC_RICHEDIT1 1000 #define IDC_BTN_TEST 1001 #define IDC_BTN_QUIT 1002 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?xml version= "1.0" encoding= "UTF-8" standalone= "yes" ?> <assembly xmlns= "urn:schemas-microsoft-com:asm.v1" manifestVersion= "1.0" > <dependency> <dependentAssembly> <assemblyIdentity type= "win32" name= "Microsoft.Windows.Common-Controls" version= "6.0.0.0" processorArchitecture= "*" publicKeyToken= "6595b64144ccf1df" language= "*" /> </dependentAssembly> </dependency> <trustInfo xmlns= "urn:schemas-microsoft-com:asm.v3" > <security> <requestedPrivileges> <requestedExecutionLevel level= "asInvoker" uiAccess= "false" /> </requestedPrivileges> </security> </trustInfo> </assembly> |