该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

源码:

#include

#include

#include

#include

#include

HINSTANCE g_hInstance = 0;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(

HINSTANCE hInstance,

HINSTANCE hPreInstance,

LPSTR lpCmdLine,

int nShowCmd

)

{

g_hInstance = hInstance;

srand((unsigned)time(NULL));

//1.注册窗口类

WNDCLASS wc = { 0 };

wc.lpszClassName = _T("MyClass");

wc.lpfnWndProc = WndProc;

wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);

RegisterClass(&wc);

//2.创建窗口

HWND hWnd = CreateWindow(

wc.lpszClassName,

_T("顽皮的按钮"),

WS_OVERLAPPEDWINDOW,

200, 100,

640, 480,

NULL,

NULL,

g_hInstance,

0

);

//3.更新显示窗口

UpdateWindow(hWnd);

ShowWindow(hWnd, SW_SHOW);

//4.消息循环

MSG Msg = { 0 };

while (GetMessage(&Msg, 0, 0, 0))

{

TranslateMessage(&Msg);

DispatchMessage(&Msg);

}

return (int)Msg.lParam;

}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

static int nCnt = 0;

switch (uMsg)

{

case WM_CREATE:

{

HWND hButton = CreateWindow(

_T("button"),

_T("来点我"),

WS_CHILD | WS_VISIBLE,

10, 10,

80, 45,

hWnd,

HMENU(0x1000),

g_hInstance,

0

);

}break;

case WM_COMMAND:

{

DWORD nCode = HIWORD(wParam);

DWORD nId = LOWORD(wParam);

if (nId == 0x1000 && nCode == BN_CLICKED)

{

if (nCnt == 10)

{

MessageBox(hWnd, _T("恭喜你点到了!"), _T("嘿嘿"), MB_OK);

PostMessage(hWnd, WM_CLOSE, 0, 0);

}

HWND hButton1 = GetDlgItem(hWnd, 0x1000);

int x = rand() % 520;

int y = rand() % 390;

MoveWindow(hButton1, x, y, 100, 50, true);

UpdateWindow(hWnd);

nCnt++;

}

}break;

case WM_CLOSE:

PostQuitMessage(0);

break;

}

return DefWindowProc(hWnd, uMsg, wParam, lParam);

}

c语言趣味小程序,一个有趣的小程序相关推荐

  1. c语言的有趣小程序,一个有趣的小程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 源码: #include #include #include #include #include HINSTANCE g_hInstance = 0; L ...

  2. 简单有趣的c语言小程序,一个有趣的小程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 源码: #include #include #include #include #include HINSTANCE g_hInstance = 0; L ...

  3. 计算机里没有四款小游戏,电脑里一些隐藏在程序里有趣的小游戏

    如果电脑不能上网 我们能干点什么 请在一个新打开的word文档里面输入: =rand(200,99) 然后回车 > 看看会发生 什么? 据说,连比尔盖茨都不知道为什么会这样: > > ...

  4. 一个有趣的小例子,带你入门协程模块-asyncio

    上篇文章写了关于yield from的用法,简单的了解异步模式,[上次的内容链接]这次让我们通过一个有趣例子带大家了解asyncio基本使用. 目标效果图 在控制台中显示一个由ASCII字符" ...

  5. 过期域名查询php程序,一个域名查询的程序

    一个域名查询的程序 更新时间:2006年10月09日 00:00:00   作者: (主要用了两个字符串函数implode()和explode) 我制作的域名查询的源代码,主要用了两个字符串函数imp ...

  6. 有趣的c语言程序Code,一个有趣的小程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 源码: #include #include #include #include #include HINSTANCE g_hInstance = 0; L ...

  7. 具有趣味性的c语言项目,一个有趣的小程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 源码: #include #include #include #include #include HINSTANCE g_hInstance = 0; L ...

  8. c语言有趣的软件,一个有趣的小程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 源码: #include #include #include #include #include HINSTANCE g_hInstance = 0; L ...

  9. 一些简单有趣的c语言编程,一个有趣的小程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 源码: #include #include #include #include #include HINSTANCE g_hInstance = 0; L ...

最新文章

  1. SQLSERVER2014中的新功能
  2. boost::allocate_shared_noinit相关的测试程序
  3. 代码生成插件Easy Code 使用
  4. 韩国ETRI提出实时Anchor-Free实例分割算法CenterMask,代码将开源
  5. linux查看主机硬件命令
  6. Ubuntu 20.04 安装多个版本 php 并应用到 nginx
  7. 解决Selection executes are supported only in the DbVisualizer Personal edition
  8. android otg dac,随身HiFi 安卓OTG功能在音频上的妙用
  9. python omron Fins -PLC和上位机socket通讯( tcy)
  10. 087 定积分求面积应用习题
  11. Timed out waiting for /dev/.coldboot_done
  12. [转载]提升你幽默感的100句经典短语
  13. 高德打车通用可编排订单状态机引擎设计
  14. 如何跨入AI的大门 Python人工智能方向怎么样
  15. 关于使用媒体查询@meda失效原因的总结或注意事项
  16. 网络安全学习第4篇-使用特征码和MD5对勒索病毒进行专杀,并对加密文件进行解密
  17. 360视频:金字塔棱台投影TSP
  18. php怎么访问ldap,用Php如何操作LDAP_PHP
  19. vlookup使用步骤_Excel Vlookup函数的使用方法及实例图解
  20. 如何搭建一个个人博客,这么写纯粹是为了通过shen he

热门文章

  1. --Symantec AntiVirus9.0--网上已很难寻的经典防病毒软件
  2. 服务器芯片组c621,三路千兆LAN:GIGABYTE 技嘉 发布 C621-SU8 服务器主板
  3. android 字母搜索栏,android仿微信通讯录搜索示例(匹配拼音,字母,索引位置)
  4. c语言实现线程相关操作,如何用C语言实现多线程
  5. 从零开始学前端:if判断,for循环,,switch判断 --- 今天你学习了吗?(JS:Day4)
  6. Node.js下载安装及各种npm、cnpm、nvm、nrm配置(保姆式教程—提供全套安装包)—cnpm的安装与配置(3)
  7. pythonindexerror_Python index错误值不在list…on.index(value)
  8. python return函数_理解Python函数中的return关键字
  9. Python+django网页设计入门(19):创建新模型扩展自带用户表的字段
  10. 微课|中学生可以这样学Python(1.3节):Python代码编写规范