c语言浪漫代码

c语言浪漫代码,第1张

#include <stdio.h>

int main()

{

int i, j, k, l, m

char c = '*' //ASCII码里面 3 就是一个字符爱心

for (i = 1i <= 5i++)

printf("\n") //开头空出5行

for (i = 1i <= 4i++)

{ //前3行中间有空隙分开来写

for (j = 1j <= 32 - 2 * ij++)

printf(" ") //左边的空格,每下一行左边的空格比上一行少2个 //8*n-2*i

for (k = 1k <= 4 * i - 2k++)

printf("%c", c) //输出左半部分字符小爱心

for (l = 1l <= 17 - 4 * il++)

printf(" ") //中间的空格,每下一行的空格比上一行少4个

for (m = 1m <= 4 * i - 2m++)

printf("%c", c) //输出右半部分字符小爱心

printf("\n") //每一行输出完毕换行

}

for (i = 1i <= 3i++)

{ //下3行中间没有空格

for (j = 1j <= 22 + 1j++)

printf(" ") //左边的空格 //8*(n-1)+1

for (k = 1k <= 31k++)

printf("%c", c) //输出字符小爱心

printf("\n") //每一行输出完毕换行

}

for (i = 7i >= 1i--)

{ //下7行

for (j = 1j <= 38 - 2 * ij++)

printf(" ") //左边的空格,每下一行左边的空格比上一行少2个//8*(n+1)-2*i

for (k = 1k <= 4 * i + 1k++)

printf("%c", c) //每下一行的字符小爱心比上一行少4个(这个循环是i--)

printf("\n") //每一行输出完毕换行

}

for (i = 1i <= 38i++)

printf(" ") //最后一行左边的空格

printf("%c", c) //最后一个字符小爱心

for (i = 1i <= 5i++)

printf("\n") //最后空出5行

return 0

}

#define IdYes 1002

#define IdNo 1003

#define IdStatic 1004

#define IdTimer 1005

#define Width 640

#define Height 480

#define Tick 2000

#include<windows.h>

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))

wc.cbSize=sizeof(WNDCLASSEX)

wc.lpfnWndProc=WndProc

wc.hInstance=hInstance

wc.hCursor=LoadCursor(NULL,IDC_ARROW)

wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1)

wc.lpszClassName=TEXT("WindowClass")

wc.hIcon=LoadIcon(NULL,IDI_APPLICATION)

wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION)

if(!RegisterClassEx(&wc))

{

MessageBox(NULL,TEXT("窗口注册失败!"),TEXT("错误"),MB_ICONEXCLAMATION|MB_OK)

return 0

}

GetWindowRect(GetDesktopWindow(),&rdesk)

x=(rdesk.right-Width)/2

y=(rdesk.bottom-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 msg.wParam

}

截图

浪漫表白效果:

开发环境:Visual Studio 2019 + EasyX图形库插件即可

源码展示:

以上就是我们表白程序的源码了!最后祝大家都能和喜欢的人在一起哦~

我的C/C++编程学习基地,点击正在跳转「链接」即可加入,欢迎有问题的小伙伴一起进来学习交流嗷~


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7830113.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存