| 
    
     |  | ▼Yuki さん: 参考になるかならないかはわかりませんが、全部は長くなるので
 関係部分だけUPしておきます。
 なお、中央表示の部分はどこかから拾ってきました。(どこか忘れました^ ^)
 
 ///////////////CALLBACK WndProcの該当部分だけ///////////////
 case WM_COMMAND:
 wmId  = LOWORD(wParam);
 wmEvent = HIWORD(wParam);
 // 選択されたメニューの解析:
 
 switch (wmId)
 {
 case IDC_BUTTON1:
 int iret;
 iret = ShowMessageBox(hWnd);
 
 if (iret == IDOK){
 MessageBox(hOwner,L"OKが押されました。",L"文字列の大きさ変更テスト",MB_OK | MB_ICONEXCLAMATION);
 }
 break;
 /////////////////////////////////////////////////////////////////
 
 ////////////////////ShowMessageBox 関数////////////////////////////////
 INT ShowMessageBox(HWND hWnd){
 INT iRet;
 
 hHook = SetWindowsHookEx(WH_CBT,&CBTHookProc,hInst,GetCurrentThreadId());
 iRet = MessageBox(hWnd,L"移動テスト",L"MessageBoxSample",MB_OK);
 return iRet;
 }
 ////////////////////////////////////////////////////////
 
 ////////////////CBTHook/////////////////////////////////////
 //hFont ,hOwner は広域変数としている。
 LRESULT CALLBACK CBTHookProc(INT nCode, WPARAM wParam, LPARAM lParam)
 {
 RECT rc,rectMsg;
 HWND hbutton;
 
 switch (nCode)
 {
 case HCBT_ACTIVATE:
 {
 //'Get the coordinates of the form and the message box so that
 //'you can determine where the center of the form is located
 GetWindowRect(hOwner, &rc);
 GetWindowRect(HWND(wParam), &rectMsg);
 
 int x,y;
 x = (rc.left + (rc.right - rc.left) / 2) -
 ((rectMsg.right - rectMsg.left) / 2);
 y = (rc.top + (rc.bottom - rc.top) / 2) -
 ((rectMsg.bottom - rectMsg.top) / 2);
 //Position the msgbox
 SetWindowPos(HWND(wParam), 0, x, y, 0, 0,
 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 
 ///テキストの変更(OKボタンのみのテスト)///
 //ボタンの取得
 hbutton = FindWindowEx(HWND(wParam),NULL,L"BUTTON",L"OK");
 if (hbutton!=NULL)
 {
 SendMessage(hbutton,WM_SETTEXT,NULL,(LPARAM)L"良し");
 
 //フォントを変更してみる
 //CreateNewFontSize(hbutton,12,L"MS明朝");
 CreateNewFontSize(hbutton,12,L"HG行書体");
 
 //背景色も変更してみる。 オーナードロー?・・・面倒なのでこれは止めた。
 
 }
 //Release the CBT hook
 UnhookWindowsHookEx(hHook);
 break;
 }
 case HCBT_DESTROYWND:
 {
 DeleteObject( hFont );  // 作成した論理フォントを削除する
 }
 default:
 {
 CallNextHookEx(hHook, nCode, wParam, lParam);
 break;
 }
 }
 return FALSE;
 }
 
 //////////////////////////////////////////////////////
 //-------------------------------------------------
 //関数名:CreateNewFontSize
 //--------------------------------------------------
 //新しいフォントサイズを作成してコントロールのフォントサイズを変更する
 //フォント名の変更はまだしてない。
 //---------------------------------------------------
 //引数
 //hbutton(HWND)    :ボタンのHWND
 //PointSize        :フォントサイズ。単位はポイント
 //fname       :フォント名
 //////////////////////////////////////////////////////////
 BOOL CreateNewFontSize(HWND hbutton,int PointSize,WCHAR *fname)
 {
 LOGFONT lf;
 HGDIOBJ hGdiobj;
 int objsize;
 int iHeight;
 HFONT hFont;
 
 HDC hDC = GetDC(hbutton);
 iHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
 //フォントのハンドル取得
 hGdiobj = GetCurrentObject(hDC,OBJ_FONT);
 ReleaseDC(hbutton,hDC);
 
 //初期化
 ZeroMemory( &lf, sizeof(lf) );
 
 //LOGFONT構造体の取得、変更
 objsize = GetObject(hGdiobj,sizeof(lf),(LPVOID)&lf);    //LOGFONT構造体の取得
 lf.lfHeight = iHeight;            //フォントの大きさ変更
 lf.lfWidth = 0;
 wcscpy(lf.lfFaceName,fname);    //フォント変更
 //フォント作成
 hFont = CreateFontIndirect(&lf);
 
 int iret = SendMessage(hbutton, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);
 
 return TRUE;
 }
 
 |  |