스크린세이버 동작 못하게 막아주기 | |||
| |||
Since SC_SCREENSAVE is a system message, the best way to trap it is by writing a custom message handler for the WM_SYSCOMMAND message. It can be argued that you can just trap the message in the WndProc handler, but why go so low-level? Oh well, let's continue.... To create the custom message handler for WM_SYSCOMMAND, we need to make a declaration for it in the private section of our code, then write a few simple lines to handle the SC_SCREENSAVE message. Here's the code: unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) private procedure WMSysCommand(var Msg : TWMSysCommand); message WM_SYSCOMMAND; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.WMSysCommand(var Msg : TWMSysCommand); begin //trap the message and set its result to -1 if (Msg.CmdType = SC_SCREENSAVE) then Msg.Result := -1 else inherited; end; end. Notice the declaration of the procedure in the private section. You can actually name the handler anything you want. But by convention, you name your procedure to closest approximation of the message that you're handling; thus the name WMSysCommand. In the procedure itself, notice as well that unlike most other handlers, the inherited message is not called first. The reason should be obvious - if we called it first, the Result type would remain unchanged. Thus, we subject the cmdType parameter of Msg to a conditional statement to evaluate it prior to taking any action. The net result of all this? While you're program is running, the Windows Screen saver will not activate. Have fun! Tags: screensaver 스크린세이버 윈도우즈 | |||
| |||
| |||
Login for comment |