本帖最后由 woshidiyimm 于 2012-12-04 16:02:40 编辑

解决方案 »

  1.   

    BS_DEFPUSHBUTTON和BS_OWNERDRAW风格不能共存
      

  2.   


     
    WM_INITDIALOG的返回值阻止不了系统分配焦点 case WM_INITDIALOG:      //  This ensures that the control really is owner drawn.
          SetWindowLong( GetDlgItem( window, IDC_BUTTON ), GWL_STYLE, 
            GetWindowLong( GetDlgItem( window, IDC_BUTTON ), GWL_STYLE ) | 
            BS_OWNERDRAW );
          return( FALSE ); //这里打算阻止系统默认给对话框分配一个焦点
          break;资源rc:BEGIN
      PUSHBUTTON   "&Button11",IDC_BUTTON,67,54,50,14
        LTEXT           "This demonstration uses the owner draw capabiliferent.  In this case, ring old rectangle.",IDC_STATIC,7,7,281,32
        PUSHBUTTON      "&Button",IDC_BUTTON1,67,186,50,14
      //  PUSHBUTTON      "Button2",IDC_BUTTON2,59,105,50,14
    结果没有阻止成功,依然进入了按钮的自绘源码 按钮的自绘源码 按钮的自绘源码的if语句中
    具体源码://  If this is a default button or focused, then it needs a black border.
      if( defButton || focused ) //foucesd是焦点
      {
        pen = CreatePen( PS_SOLID, 1, RGB( 0, 0, 0 ) );
        oldPen = (HPEN)SelectObject( dc, pen );
        RoundRect( dc, rect.left, rect.top, rect.right, rect.bottom, 10, 10 );
        SelectObject( dc, oldPen );
        DeleteObject( pen );
      }if语句的调用源码: //  Draw the button.
      DrawRoundedButton( item->hDC,
                         item->rcItem,
                         item->itemState & ODS_DEFAULT,
                         item->itemState & ODS_SELECTED,
                         item->itemState & ODS_FOCUS ); //最后一个参数就是focused.
    WM_INITDIALOG messageReturn value
    The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control specified by wParam. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus.
    DRAWITMESTRUCT 中的字段 itemstate&ODS_FOCUS就是指 该按钮是否有默认焦点。
    WM_initDIALOG 很明显的阻止不了,一旦阻止,那么久无法进入if语句.或许这是msdn的一个bug吧
      

  3.   


    阻止的是句柄为wParam的控件获得焦点,但是只要对话框上有控件,当对话框激活时,肯定有一个控件是获得焦点的在WM_INITDIALOG里可以调用SetFocus函数设置焦点,这时就应该返回FALSE;如果返回TRUE,则总是句柄为wParam的控件获得焦点
      

  4.   


    却是我理解错了。非常感谢你呵呵顺便总结一下: windows控件的风格, 有的风格,并没有在代码里设置,也没有在rc文件中设置,但是依然有,用spy++可以看到。说明 当我们创建的时候,很多风格是默认提供的。只是没有看到,比如:WS_TAPSTOP.还有不少窗口类windclass 风格也是如此。
    可能我总结这点是:微软并没有在msdn上注释吧。呵呵