스크린세이버 동작 못하게 막아주기

31433 
Created at 2006-09-29 06:42:09 
312   0   0   0  
Good question, and yes you can disable the Windows screen saver at runtime. It just so happens that just before Windows activates its screen saver, it sends out a SC_SCREENSAVE message to all running programs. If any of them set the message's Result field to -1, the screen saver won't be activated. So now the problem lies with trapping the message itself.

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 스크린세이버 윈도우즈 Share on Facebook Share on X

◀ PREVIOUS
DirectShow에서 비디오 출력 크기 조정해주기
▶ NEXT
how to record keyboard & mouse event
  Comments 0
Login for comment
SIMILAR POSTS

PC 셧다운 (shutdown) (created at 2006-09-29)

how to record keyboard & mouse event (created at 2006-09-29)

DirectShow에서 비디오 출력 크기 조정해주기 (created at 2006-09-29)

공유폴더 찾아주기 (created at 2006-09-29)

로컬 IP 알아내기 (created at 2006-09-29)

ShellExecute 실행 끝날때 까지 기다리기 (created at 2006-09-29)

웹브라우져에 붙이기 위한 ActiveX 프로그래밍 방법 (created at 2006-09-29)

Starting an application as an icon in the system tray (created at 2006-09-29)

Extracting a Program's Version Information (created at 2006-09-29)

투명 윈도우 구현 방법 (created at 2006-09-29)

ActiveX를 Safe한 Component로 등록하는 방법 (created at 2006-09-29)

디렉토리 복사 루틴 (하부디렉토리까지 몽땅) (created at 2006-09-29)

디렉토리와 그 안에 있는 모든 파일 지우기 (created at 2006-09-29)

Create a standard windows shortcut file (created at 2006-09-29)

ActiveX의 등록 - Safe Code 넣어주기 (updated at 2023-12-17)

File Attribute 바꾸는 방법 (created at 2006-09-29)

윈도우 찾아서 Top Most로 올려주기 (updated at 2023-12-17)

Application defined window call procedure (created at 2006-09-29)

Application Event써서 Keyboard 받아내기 (created at 2006-09-29)

Web Browser Control에서 Enter키 먹게 하기 (created at 2006-09-29)

String Find 알고리즘 (created at 2006-09-29)

HTTP Downloading Reference Source Code (created at 2006-09-29)

File Search Sample Code (created at 2006-09-29)

모니터 끄는 API (created at 2006-09-29)

wave 파일 mixing 하기. (웨이브 믹싱) (created at 2006-09-29)

ATL/ActiveX 에서 자바스크립트로 데이터(문자열) 보내기 (created at 2006-09-29)

System Log-Off, Suspend, Reboot, Shutdown 시키기 (created at 2006-09-29)

GDI+ 에서 이미지 반투명 처리하기.. (created at 2006-09-29)

자기자신 IP알아내기(로칼컴퓨터) (created at 2006-09-29)

프로세스명으로 프로세스 죽이는 함수 (created at 2006-09-29)

OTHER POSTS IN THE SAME CATEGORY

AES (Advanced Encryption Standard) Source Code (created at 2006-09-29)

File Search Sample Code (created at 2006-09-29)

Simple Socket Server based on C (created at 2006-09-29)

HTTP Downloading Reference Source Code (created at 2006-09-29)

String Find 알고리즘 (created at 2006-09-29)

UNIX에서 LOCALTIME 구하는 방법 & GetTicketCount() (created at 2006-09-29)

Web Browser Control에서 Enter키 먹게 하기 (created at 2006-09-29)

Application Event써서 Keyboard 받아내기 (created at 2006-09-29)

Application defined window call procedure (created at 2006-09-29)

윈도우 찾아서 Top Most로 올려주기 (updated at 2023-12-17)

ActiveX의 등록 - Safe Code 넣어주기 (updated at 2023-12-17)

ActiveX를 Safe한 Component로 등록하는 방법 (created at 2006-09-29)

투명 윈도우 구현 방법 (created at 2006-09-29)

웹브라우져에 붙이기 위한 ActiveX 프로그래밍 방법 (created at 2006-09-29)

how to record keyboard & mouse event (created at 2006-09-29)

DirectShow에서 비디오 출력 크기 조정해주기 (created at 2006-09-29)

공유폴더 찾아주기 (created at 2006-09-29)

로컬 IP 알아내기 (created at 2006-09-29)

ShellExecute 실행 끝날때 까지 기다리기 (created at 2006-09-29)

Starting an application as an icon in the system tray (created at 2006-09-29)

Extracting a Program's Version Information (created at 2006-09-29)

디렉토리 복사 루틴 (하부디렉토리까지 몽땅) (created at 2006-09-29)

디렉토리와 그 안에 있는 모든 파일 지우기 (created at 2006-09-29)

Create a standard windows shortcut file (created at 2006-09-29)

File Attribute 바꾸는 방법 (created at 2006-09-29)

wave 파일 mixing 하기. (웨이브 믹싱) (created at 2006-09-29)

ATL/ActiveX 에서 자바스크립트로 데이터(문자열) 보내기 (created at 2006-09-29)

System Log-Off, Suspend, Reboot, Shutdown 시키기 (created at 2006-09-29)

GDI+ 에서 이미지 반투명 처리하기.. (created at 2006-09-29)

자기자신 IP알아내기(로칼컴퓨터) (created at 2006-09-29)

UPDATES

글루코사민 vs. 콘드로이친: 무엇이 더 나은 관절 건강 보조제일까? (created at 2024-04-22)

광주 5·18 민주화운동 알린 테리 앤더슨 前 AP 기자 (created at 2024-04-22)

햄과 소세지가 우리 몸에 일으키는 부작용 (updated at 2024-04-22)

콘드로이친의 염증 감소효과 (updated at 2024-04-22)

코사민 DS - 글루코사민+콘드로이친 복합물이 함유된 퇴행성 관절 건강보조제 (updated at 2024-04-22)

삼겹살 먹을때 환상조합 (created at 2024-04-22)

일본 여중생의 특이한 취향 (created at 2024-04-22)

우리가 먹는 약물이 바꿔버린 생태계 (created at 2024-04-21)

일본에서 그린 상상속의 사무직과 현실속의 사무직 (updated at 2024-04-21)

북한 미대생들이 그린 북한 최고존엄 김정은 (created at 2024-04-21)

입사 후 1년도 되지 않은 회사에서 구조조정에 의한 퇴직 불응에 따른 해고 처리시 대응 가능한 방법 (updated at 2024-04-20)

한고은님의 옛날 사진 (updated at 2024-04-20)

소녀대 - Bye Bye Girl (updated at 2024-04-13)

대한민국 날씨 근황 (created at 2024-04-13)

성일종 인재육성 강조하며 이토 히로부미 언급 - 인재 키운 선례? (updated at 2024-04-13)

일제강점기가 더 살기 좋았을지도 모른다는 조수연 국민의힘 후보 - 친일파? (updated at 2024-04-13)

Marshall Ha님의 샤오미 SU7 시승기 - 테슬라의 일론 머스크님이 긴장할만한 느낌 (updated at 2024-04-09)

윙크하는 귀염둥이 반려견들 (created at 2024-04-08)

달콤 살벌한 고백 (created at 2024-04-08)

북한 최정예 공수부대 훈련 모습 (updated at 2024-04-02)

맛있었던 친구 어머니의 주먹밥이 먹고 싶어요 (created at 2024-04-02)

자리 마음에 안든다고 6급 공무원 패는 농협 조합장 (created at 2024-03-26)

85세 딸 짜장면 사주는 102세 어머니 (created at 2024-03-26)

1990년대 감각파 도둑 (created at 2024-03-26)

치매에 걸린 69살의 브루스 윌리스가 전부인 데미무어를 보고 한 말 (updated at 2024-03-22)

경제는 대통령이 살리는 것이 아닙니다 라던 윤석열대통령 - 상황 안좋아지자 여러 전략을 펼쳤지만, 부작용 속출했던 2024년의 봄 (updated at 2024-03-13)

극빈의 생활을 하고 배운것이 없는 사람은 자유가 뭔지도 모를 뿐 아니라 왜 개인에게 필요한지에 대한 필요성을 못느낀다는 윤석열 대통령 (updated at 2024-03-08)

조선일보를 안본다는 사람들이 말하는 그 이유 - 천황폐하, 전두환 각하, 김일성 장군 만세? (created at 2024-03-07)

광폭타이어를 장착하면 성능이 좋아질거라는 착각 (updated at 2024-03-03)

면허시험장에서 면허갱신하면 하루만에 끝나나? (updated at 2024-03-03)