請問自建的window要如何收到WM_POWERBROADCAST訊息 |
尚未結案
|
17kobe
初階會員 發表:86 回覆:73 積分:31 註冊:2007-07-30 發送簡訊給我 |
[code delphi] procedure TEncodeVideo.Init; var ClassRegistered : Boolean; TempClass : TWndClass; begin try MyWinClass.style := 0; MyWinClass.lpfnWndProc := @TEncodeVideoWindowProc; //這裡是它收訊息的地方 MyWinClass.cbClsExtra := 0; MyWinClass.cbWndExtra := SizeOf(Pointer); MyWinClass.hInstance := 0; MyWinClass.hIcon := 0; MyWinClass.hCursor := 0; MyWinClass.hbrBackground := 0; MyWinClass.lpszMenuName := nil; MyWinClass.lpszClassName := 'MyTEncodeVideo'; MyWinClass.hInstance := HInstance; ClassRegistered:=GetClassInfo( HInstance, MyWinClass.lpszClassName, TempClass); //如果沒有存在此class 註冊一個 if not ClassRegistered then begin if Windows.RegisterClass(MyWinClass) = 0 then Exit; end; //DebugStr('建立擁有Timer的隱藏視窗'); FMyHideHD := CreateWindowEx( WS_EX_TOOLWINDOW, MyWinClass.lpszClassName, '', { Window name } WS_POPUP, { Window Style } 0, 0, { X, Y } 0, 0, { Width, Height } 0, { hWndParent } 0, { hMenu } HInstance, { hInstance } nil); { CreateParam } //DebugStr('create MyHideHD:' inttostr(FMyHideHD)); except end; end; function TEncodeVideoWindowProc(hWnd:HWND; iMsg:Integer; wParam:WPARAM; lParam:LPARAM): Integer; stdcall; var FIniFile: TIniFile; begin Result:=0; case iMsg of WM_CREATE : begin SetTimer(hWnd,TimerID_5,g_IntervalTime*1000,nil); //hWnd控制的把柄 TimerId_15標誌 nil指WM_TIMER將處理消息 exit; end; (* WM_DESTROY : begin KillTimer(hWnd, TimerID_5); //銷毀SetTimer建立的計時器 PostQuitMessage(0); //跟Windows說我要退出囉。 exit; end; *) WM_POWERBROADCAST: begin // DebugStr('這裡怎麼收不到'); { case wParam of PBT_APMQUERYSUSPEND:begin //DebugStr('不爽1'); end; PBT_APMSUSPEND:begin //DebugStr('不爽2'); end; end; } end; WM_QUERYENDSESSION: begin //DebugStr('關機'); end; WM_TIMER : begin //g_EncodeVideo.OnTimer(); exit; end; end; Result := DefWindowProc(hWnd,iMsg,wParam,lParam); //不感興趣的消息,由windows去處理 end; [/code] 上面程式WM_CREATE, WM_TIMER, WM_QUERYENDSESSION都收得到訊息,但是 WM_POWERBROADCAST卻收不到。 ps:對於delphi訊息處理還不是很了解中。求助~ 編輯記錄
17kobe 重新編輯於 2009-01-06 17:41:57, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |