在一对话框中:
OnInitDialog()
{
   CDialog::OnInitDialog();
   SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
   //-------------------------窗体透明----------------------
   HINSTANCE hInst = LoadLibrary("User32.DLL");
   if(hInst != NULL) 
   { 
       typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD); 
       MYFUNC fun = NULL;
       //取得SetLayeredWindowAttributes函数指针 
       fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
       if(fun)fun(this->GetSafeHwnd(),0,128,2); 
       FreeLibrary(hInst); 
    }
    CGameImage m_BackBitmap;   m_BackBitmap.SetLoadInfo".\\image\\mj\\usertalk2.bmp",CGameImageLink::m_bAutoLock);  //为背景图片
    CGameImageHelper ImageHandle(&m_BackBitmap);    //======创建bmp不规则对话框,RGB(0,0,150)是透明色=========
    HRGN hRgn=AFCBmpToRgn(ImageHandle,RGB(0,0,150),RGB(1,1,1)); 
    if (hRgn!=NULL)
    {
        SetWindowPos(NULL,0,0,ImageHandle.GetWidth(),ImageHandle.GetHeight(),SWP_NOMOVE);
        SetWindowRgn(hRgn,TRUE);
    }
 
   运行后,对话框是实现半透明了,可是将bmp中的透明色也显示出来了(显示出来为黑色)。本来是要实现将透明色不显示的。如果不透明对话框,则显示出来的是正确的。
   
   哪位帮我看看啊。郁闷中。

解决方案 »

  1.   

    改成
    if(fun)fun(this->GetSafeHwnd(),RGB(0,0,150),128,3); RGB(0,0,150)变全透明,窗体半透明
      

  2.   

    The SetLayeredWindowAttributes function sets the opacity and transparency color key of a layered window.SyntaxBOOL SetLayeredWindowAttributes(          HWND hwnd,
        COLORREF crKey,
        BYTE bAlpha,
        DWORD dwFlags
    );Parametershwnd 
    [in] Handle to the layered window. A layered window is created by specifying WS_EX_LAYERED when creating the window with the CreateWindowEx function or by setting WS_EX_LAYERED via SetWindowLong after the window has been created. 
    crKey 
    [in] COLORREF structure that specifies the transparency color key to be used when composing the layered window. All pixels painted by the window in this color will be transparent. To generate a COLORREF, use the RGB macro. 
    bAlpha 
    [in] Alpha value used to describe the opacity of the layered window. Similar to the SourceConstantAlpha member of the BLENDFUNCTION structure. When bAlpha is 0, the window is completely transparent. When bAlpha is 255, the window is opaque. 
    dwFlags 
    [in] Specifies an action to take. This parameter can be one or more of the following values. 
    LWA_COLORKEY 
    Use crKey as the transparency color. 
    LWA_ALPHA 
    Use bAlpha to determine the opacity of the layered window.
      

  3.   

    http://www.codeproject.com/dialog/BitmapHandling.asp
      

  4.   

    把下面这段放在
    //======创建bmp不规则对话框,RGB(0,0,150)是透明色=========
        HRGN hRgn=AFCBmpToRgn(ImageHandle,RGB(0,0,150),RGB(1,1,1)); 
        if (hRgn!=NULL)
        {
            SetWindowPos(NULL,0,0,ImageHandle.GetWidth(),ImageHandle.GetHeight(),SWP_NOMOVE);
            SetWindowRgn(hRgn,TRUE);
        }//-------------------------窗体透明----------------------
    这段的前面
      

  5.   

    看看我滴,呵呵
    http://www.cppblog.com/wlwlxj/archive/2006/12/03/15930.html
      

  6.   

    AFCBmpToRgn
    最好到这个函数里面去看一下,在透明之后,得到的rgn是否正确
    看透明对AFCBmpToRgn这个函数中的对位图读取的象素色彩值是否有影响!