This is a program like Screensaver.
How to Make fullscreen & colouring of the program output? and automatic exit program on mouse move?
#include<windows.h>
#include<stdio.h>
#include<time.h>
#include<math.h>
struct tm *local(){
time_t t;
t = time(NULL);
return localtime(&t);
}
const char *ClsName = "BitmapLoading";
const char *WndName = "Easy bitmaploading!";
MSG Msg;
HWND hWnd;
WNDCLASSEX WndClsEx;
HINSTANCE hInstance;
int main(void)
{
GetSystemMenu(GetForegroundWindow(),1);
ShowWindow(GetForegroundWindow(),1);
int D=100;
int m,n;
MoveWindow(GetForegroundWindow(),0,0,0,0,1);
RegisterClassEx(&WndClsEx);
// Create the window object
hWnd = CreateWindow(ClsName,
WndName,
WS_OVER开发者_如何学JAVALAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
GetForegroundWindow(),
CreatePopupMenu(),
hInstance,
NULL);
HDC hdc=GetDC(hWnd);
for(m=0;m<=(local()->tm_hour*5)+local()->tm_min;m++)rand();//Random based on time
char *Label=" ScreenMove. - 2020 ";
int a[35],b[35],c[35],d[35],e=0;
for(n=1;n<=21;n++){
a[n]=(10+n)*n;
b[n]=(10+n)*n;
c[n]=1,d[n]=1;
}
do{
for(n=1;n<=21;n++){
if(a[n]+(6+n+n)<=740 && a[n]>=0 && c[n]==1)a[n]++;
else{ a[n]--;c[n]=0; }
if(a[n]<=0)c[n]=1;
if(b[n]+(6+n+n)<=1000 && b[n]>=0 && d[n]==1)b[n]++;
else{ b[n]--;d[n]=0; }
if(b[n]<=0)d[n]=1;
e++;
if(e==4)e=0;
RoundRect(hdc,b[n]+(2+n+n)+e,a[n]+(2+n+n)+e,b[n],a[n],b[n],a[n]);
TextOut(hdc,360,10,Label,43);//TEXT
}
for(m=0;m<=D*4;m++)Rectangle(hdc,1300,0,1350,50);
for(n=100;n>=0;n--)LineTo(hdc,rand()%1100,rand()%740);
SetTextColor(hdc,rand());
}while(1);
return 0;
}
Windows GUI programs are generally event-driven. The do ... while(1)
section in your program creates an infinite loop that will waste CPU cycles as well as making it difficult to detect events such as mouse movement. Take some time and read a tutorial on developing Win32 applications. Here is one result from Google. Once you learn how to set up a window procedure for handling messages, you can use the WM_MOUSEMOVE
message to detect mouse movement and quit the application.
To make your window full-screen:
- use the
WS_POPUP
style instead ofWS_OVERLAPPEDWINDOW
; this will remove the title bar - pass in appropriate screen coordinates: instead of
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT
, use0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)
.
As for adding colour to your output, you need to do one of several things depending on what you wish to colour. Lines are drawn using a pen, solids such as rectangles are filled using a brush, and text colour is set separately by SetTextColor
. See this page for an example of using pens and brushes.
If you want to create a screen saver, you normally want to use the screen saver API. This automatically handles almost everything but the drawing (e.g., when to activate, de-activating when there's input from the screen, keyboard, etc.)
精彩评论