2012-01-09 70 views
1

之間我喜歡我的計劃之內第二窗口創建:Win32 C++ SetLayeredWindowAttributes要麼完全不透明要麼完全透明;沒什麼所以

#define WINDOW_CLASS_NAME "WINCLASSFULL" 

WNDCLASSEX winclass; 

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 
{ 
    switch(msg) 
    { 
     case WM_CLOSE: 
      DestroyWindow(hwnd); 
     break; 
     case WM_DESTROY: 
      PostQuitMessage(0); 
     break; 
     default: 
      return DefWindowProc(hwnd, msg, wParam, lParam); 
    } 
    return 0; 
} 

some function { 

HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); 

// first fill in the window class stucture 

winclass.cbSize   = sizeof(WNDCLASSEX); 
winclass.style   = CS_DBLCLKS | CS_OWNDC | 
          CS_HREDRAW | CS_VREDRAW; 
winclass.lpfnWndProc =WndProc; 
winclass.cbClsExtra = 0;      //reserve data space 
winclass.cbWndExtra = 0;      // 
winclass.hInstance = hInstance;    //set instance of application 
winclass.hIcon  = NULL; 
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);   //load cursor type 
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); //set background brush 
winclass.lpszMenuName = NULL;        
winclass.lpszClassName = WINDOW_CLASS_NAME;     //set Windows class name 
winclass.hIconSm  = NULL; 

hWnd= CreateWindowEx(WS_EX_LAYERED,     // extended style 
          WINDOW_CLASS_NAME,  // class 
          "Demo", // title 
          WS_POPUP, 
          x,y, 
          width,height, 
          NULL, 
          NULL, 
          hInstance,// instance of this application 
          NULL))) // extra creation parms 

} 

現在我的問題是,如果我申請

其中255可以是任何東西1-255

SetLayeredWindowAttributes(hWnd,RGB(0,0,0),255,LWA_COLORKEY|LWA_ALPHA) 
之間

窗戶是完全不透明的,我看不到任何東西

這是完全透明的:

SetLayeredWindowAttributes(hWnd,RGB(0,0,0),0,LWA_COLORKEY|LWA_ALPHA) 

我怎樣才能得到

SetLayeredWindowAttributes(hWnd,RGB(0,0,0),128,LWA_COLORKEY|LWA_ALPHA) 

要變通 - 即這樣我就可以看到部分在上面我的窗口;並部分看到它後面的窗戶。我查MSDN上的DOCO在這裏,但我顯然失去了一些東西Refer Microsoft Library

+0

爲什麼這些人編譯在2012年的Windows應用程序,而'UNICODE'定義?如果你沒有設置透明度顏色,爲什麼包含'LWA_COLORKEY'? – 2012-01-09 11:36:41

+1

http://stackoverflow.com/questions/3967003/setlayeredwindowattributes-not-working-on-windows-7包含一些有用的信息;這不是這個問題的重複,而是觸及同一類問題。 – mjfgates 2012-01-09 11:47:50

+0

您是否在您提供的鏈接中閱讀過「社區增補」?我認爲它給了你答案,你不應該把'LWA_COLORKEY'和'LWA_ALPHA'結合起來。 – 2012-01-09 12:06:30

回答

2

嘗試指定唯一LWA_ALPHA,不能同時LWA_COLORKEYLWA_ALPHA