我做了一个对话框程序DlgA,DlgA上有一ButtonA,左击ButtonA,弹出对话框DlgB,
我要在DlgB中改变其对话框图标-Icon图片,怎样做?  在对话框程序DlgA很容易,在其构造孙数中加入m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);就可以了,但在DlgB中就不能这样了.

解决方案 »

  1.   

    初始化对话框B时,用SendMessage来设置图标:
    ::SendMessage(hDlg, WM_SETICON, 0, (LPARAM)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)));
      

  2.   

    an application instance only have one application icon!
      

  3.   

    to titi_lima(李马)
    非常感谢:初始化对话框B时,我这样写:
    ::SendMessage(GetDlgItem(IDD_DIALOG1)->GetSafeHwnd(), WM_SETICON, 0, (LPARAM)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ALARM)));
    但还是不成功,问题出在哪?
      

  4.   

    to phiger(phiger):
    Think u!
    If true as your said. But my DialogB's Icon is different from DialogA,There is no use if I use "AfxGetApp()->LoadIcon(IDI_ALARM)"
    in the construction function in DialogB.
      

  5.   

    Think titi_lima(李马) sincerely
    I have solve with your help.By the way, to  phiger(phiger),
    You are wrong,an application instance can have more than one application icon.
      

  6.   

    AfxGetMainWnd( )->SetIcon( 
    AfxGetApp( )-> LoadIcon (IDI_ICON1), // icon handle
    TRUE); // FALSE=16x16 bit icon
      

  7.   

    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME)
    m_hIcon沒定義??
    樓主的代碼行不通哦。
      

  8.   

    Try it!
    HICON  hicon = ::LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON1));
    SetClassLong(AfxGetMainWnd()->m_hWnd, GCL_HICON, (long)hicon);
      

  9.   

    to phiger(phiger):
    I am trying it, I will give the reasult as soon as I have finished it.
      

  10.   

    I have just failed to log in so that I answer it so late.to tang_ghost(tangyan): 
      I am unsuccessful to do as your said.to phiger(phiger):
      I am gald to tell you that you are right at this time, with your help, I have solved my problem, think u! 
      
    To all, thinks.