浪漫表白效果:
开发环境:Visual Studio 2019 + EasyX图形库插件即可
源码展示:
以上就是我们表白程序的源码了!最后祝大家都能和喜欢的人在一起哦~
我的C/C++编程学习基地,点击正在跳转「链接」即可加入,欢迎有问题的小伙伴一起进来学习交流嗷~
#define IdYes 1002
#define IdNo 1003
#define IdStatic 1004
#define IdTimer 1005
#define Width 640
#define Height 480
#define Tick 2000
#include<windowsh>
int x,y;
RECT rdesk;
HINSTANCE hinst;
HWND hyes,hno;
BOOL quit=FALSE;
LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rclient;
HBRUSH hbrbkgnd;
static COLORREF c;
static BYTE r,g,b;
switch(Message)
{
case WM_TIMER:
if(IdTimer==LOWORD(wParam))
{
r=(BYTE)(rand()%256);
g=(BYTE)(rand()%256);
b=(BYTE)(rand()%256);
c=RGB(r,g,b);
InvalidateRect(hwnd,NULL,TRUE);
UpdateWindow(hwnd);
}
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
hbrbkgnd=CreateSolidBrush(c);
SelectObject(hdc,hbrbkgnd);
GetClientRect(hwnd,&rclient);
FillRect(hdc,&rclient,hbrbkgnd);
DeleteObject(hbrbkgnd);
EndPaint(hwnd,&ps);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IdYes:
quit=TRUE;
MessageBox(hwnd,TEXT("回答正确,太太太好了!"),TEXT("宝贝"),MB_ICONEXCLAMATION|MB_OK);
SendMessage(hwnd,WM_CLOSE,0,0);
break;
case IdNo:
MessageBox(hwnd,TEXT("回答错误哦,我很生气呢!"),TEXT("宝贝"),MB_ICONEXCLAMATION|MB_OK);
break;
}
break;
case WM_SIZE:
case WM_MOVE:
SetWindowPos(hwnd,HWND_TOPMOST,x,y,Width,Height,SWP_SHOWWINDOW);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
if(quit)
{
KillTimer(hwnd,IdTimer);
DestroyWindow(hwnd);
}
break;
case WM_CREATE:
CreateWindow(TEXT("Static"),
TEXT("请回答:做我女朋友好吗?"),
WS_CHILD|WS_VISIBLE|SS_CENTER,
200,
200,
240,
20,
hwnd,
(HMENU)IdStatic,
hinst,
NULL
);
hyes=CreateWindow(TEXT("Button"),
TEXT("好"),
WS_CHILD|WS_VISIBLE|BS_CENTER,
270,
230,
45,
20,
hwnd,
(HMENU)IdYes,
hinst,
NULL
);
hno=CreateWindow(TEXT("Button"),
TEXT("不好"),
WS_CHILD|WS_VISIBLE|BS_CENTER,
325,
230,
45,
20,
hwnd,
(HMENU)IdNo,
hinst,
NULL
);
SetTimer(hwnd,IdTimer,Tick,NULL);
break;
default:
return DefWindowProc(hwnd,Message,wParam,lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
hinst=hInstance;
srand(time(NULL));
memset(&wc,0,sizeof(wc));
wccbSize=sizeof(WNDCLASSEX);
wclpfnWndProc=WndProc;
wchInstance=hInstance;
wchCursor=LoadCursor(NULL,IDC_ARROW);
wchbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wclpszClassName=TEXT("WindowClass");
wchIcon=LoadIcon(NULL,IDI_APPLICATION);
wchIconSm=LoadIcon(NULL,IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,TEXT("窗口注册失败!"),TEXT("错误"),MB_ICONEXCLAMATION|MB_OK);
return 0;
}
GetWindowRect(GetDesktopWindow(),&rdesk);
x=(rdeskright-Width)/2;
y=(rdeskbottom-Height)/2,
hwnd = CreateWindowEx(WS_EX_TOPMOST,
TEXT("WindowClass"),
TEXT("I Love You"),
WS_THICKFRAME|WS_VISIBLE,
x,
y,
Width,
Height,
NULL,NULL,hInstance,NULL);
if(NULL==hwnd)
{
MessageBox(NULL,TEXT("窗口创建失败!"),TEXT("错误!"),MB_ICONEXCLAMATION|MB_OK);
return 0;
}
while(GetMessage(&msg,NULL,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msgwParam;
}
截图
#include<stdioh>
int main()
{
char name[30];
int i;
float y,x,a;
printf("输入你最爱的人的名字:");
scanf("%s",&name);
printf("%s,我爱你\n",name);
for (y = 15f; y > -15f; y -= 01f) {
for (x = -15f; x < 15f; x += 005f) {
a = x x + y y - 1;
putchar(a a a - x x y y y <= 00f '' : ' ');
}
putchar('\n');
}
system("pause");
}
#include<iostreamh>
#include<stdioh>
#include<ctypeh>
struct ca {
char c;
ca next;
};
void InitList(ca L) {
cout<<"输入一页文字(以#结束): "<<endl;
while((L->c = getchar()) != '#') {
L->next = new ca;
L = L->next;
}
L->next = NULL;
}
void StrNo(ca L) {
int n = 0;
char s[80], q;
ca p;
cout<<"输入一字符串: ";
cin>>s;
while(L->next) {
for (p = L, q = s; q != '\0' && p->next; p = p->next, q++)
if (p->c != q) break;
if (q == '\0') n++;
L = L->next;
}
cout<<"字符串 "<<s<<" 出现 "<<n<<" 次\n";
}
ca DelStr(ca L) {
ca H = L;
char s[80], q;
ca p;
cout<<"输入该子串: ";
cin>>s;
if (H->c == s) {
for (p = H->next, q = s+1; q != '\0' && p->next; p = p->next, q++)
if (p->c != q) break;
if (q == '\0') H = p;
}
while(L->next) {
for (p = L->next, q = s; q != '\0' && p->next; p = p->next, q++)
if (p->c != q) break;
if (q == '\0') L->next = p;
else L = L->next;
}
return H;
}
void print1(ca L) {
while(L->next) {
cout<<L->c;
L = L->next;
}
cout<<endl;
}
void print2(ca L, int &p1, int &p2, int &p3, int &n) {
n = p1 = p2 = p3 = 0;
for( ; L->next; L = L->next, n++)
if(isalpha(L->c)) p1++;
else if(isdigit(L->c)) p2++;
else if(L->c == ' ') p3++;
else if(L->c == '\n') n--;
cout<<"\n全部字母数: "<<p1;
cout<<"\n数字个数: "<<p2;
cout<<"\n空格个数: "<<p3;
cout<<"\n文章总字数: "<<n<<endl;
}
void main() {
ca L = new ca;
int p1, p2, p3, n, c;
InitList(L);
do {cout<<"\n0:退出\n"
"1:统计中英文字母和空格数以及整篇文章总字数\n"
"2:统计某一字符串在文章中出现次数\n"
"3:删除某一子串\n"
"4:分行输出用户输入的各行字符\n";
cin>>c;
switch(c) {
case 1:print2(L, p1, p2, p3, n);break;
case 2:StrNo(L);break;
case 3:DelStr(L);
case 4:print1(L);
}
}while(c);
欢迎分享,转载请注明来源:表白网
评论列表(0条)