开发精彩实例:窗体自动隐藏

C# WinForms停靠布局:DockPanel类源码解析与实战 布局是桌面软件开发中的关键环节,尤其对于工具型软件,灵活的窗口管理直接影响用户体验。传统SplitContainer或TabControl难以实现窗口的拖拽、浮动和自动隐藏,而停靠布局正成为IDE类应用程序的标配。本文以C# WinForms为背景,深入解析DockPanelSuite开源类库的核心设计,从IDockContent接口、DockState状态与DockAreas权限等类源码层面,阐述其如何实现完整的停靠运行时。通过一个数据采集项目案例,详细介绍DockPanel的初始化、内容窗口派生、布局序 阅读详情

 最近写个小程序,想让窗体自动隐藏,到csdn搜索,发现不少网友问这个问题,可是具体实现的例子不多,我经过琢磨,实现可记录停靠位置,可左上右三方停靠并隐藏。现将实现的例子拿出来供大家参考。
 实现窗体自动隐藏方法有多种,可以使用定时器,不断监视鼠标,当鼠标移动到窗体边缘时,显示窗体,当鼠标离开后隐藏窗体。也可以在鼠标收到WM_NCMOUSEMOVE或 WM_MOUSEMOVE(无边框窗体)时激活窗体,然后在窗体消息WM_ACTIVE中设置显示或隐藏,这种方法在窗体未失去焦点时不会隐藏。我在原本的设计中便使用这种方法,只是在设计时发现非主窗体不太合适,激活窗体时会出现两个键盘焦点,而且我所需要的焦点是虚假的,可能我的设计不当,那位朋友若能完美实现,不妨交流一下。
 本代码的流程如下:
 1. 初始化窗体时设置窗体位置,并设置依靠状态窗体状态。
 2. 当接收到WM_MOUSEMOVE消息时,检查窗体是否显示,若否,显示,并打开定时器。
 3. 在WM_MOVING中检测窗体位置,并自动靠拢边界。
 4. 在定时器中检测鼠标,当鼠标离开窗体后,关闭定时器,隐藏窗体。
 当然,在隐藏窗体时首先判断位置,若停靠在边缘,则隐藏,否则,不隐藏。
 现在我们一步步看代码。
 int alignType;   //全局变量,用于记录窗体停靠状态
 enum
 {
  ALIGN_NONE,          //不停靠
  ALIGN_TOP,          //停靠上边
  ALIGN_LEFT,          //停靠左边
  ALIGN_RIGHT          //停靠右边
 };
 #define NEAR_SIZE 20 //定义自动停靠有效距离
 #define NEAR_SIDE 2 //窗体隐藏后在屏幕上保留的像素,以使鼠标可以触及
 /*
 下面代码处理窗体消息WM_MOVING,pRect是由参数lParam传来的指针
 */
 void OnMoving(HWND hWnd, LPRECT pRect)
 {
 //未靠边界由pRect测试
  if (alignType == ALIGN_NONE)
  {
   if (pRect->top < NEAR_SIZE) //在上边有效距离内,自动靠拢。
   {
    alignType = ALIGN_TOP;
    pRect->bottom -= pRect->top;
    pRect->top = 0;
   }
   if (pRect->left < NEAR_SIZE) //在左边有效距离内
   {
    alignType = ALIGN_LEFT;
    pRect->right -= pRect->left;
    pRect->left = 0;
   }
   else if (pRect->right + NEAR_SIZE > ScreenX) //在右边有效距离内,ScreenX为屏幕宽度,可由GetSystemMetrics(SM_CYSCREEN)得到。
   {
    alignType = ALIGN_RIGHT;
    pRect->left += (ScreenX - pRect->right);
    pRect->right = ScreenX;
   }

  }
  else
  {
   //靠边界由鼠标测试
   POINT           pt;
   GetCursorPos(&pt);
   if (alignType == ALIGN_TOP)
   {
    if (pt.y > NEAR_SIZE) //由于我们移动窗体时,鼠标在标题栏内,当鼠标位置超过有效距离后,我们可以考虑用户要向下拖动鼠标。我们便解除上部停靠。
    {
     alignType = ALIGN_NONE;
     pRect->bottom += NEAR_SIZE;
     pRect->top = NEAR_SIZE;
    }
    else
    {
     pRect->bottom -= pRect->top;
     pRect->top = 0;
     if (pRect->left < NEAR_SIZE) //在上部停靠时,我们也考虑左右边角。
     {
      pRect->right -= pRect->left;
      pRect->left = 0;
     }
     else if (pRect->right + NEAR_SIZE > ScreenX)
     {
      pRect->left += (ScreenX - pRect->right);
      pRect->right = ScreenX;
     }
    }
   }
   if (alignType == ALIGN_LEFT)
   {
    if (pt.x - pRect->right > 0) //鼠标可以在整个标题条来回移动,所以我们不能简单用左边界和鼠标的距离来解除停靠,这里我们在鼠标离开右边界时解除停靠。
    {
     alignType = ALIGN_NONE;
     pRect->right += NEAR_SIZE;
     pRect->left = NEAR_SIZE;
    }
    else
    {
     pRect->right -= pRect->left;
     pRect->left = 0;
     if (pRect->top < NEAR_SIZE) //考虑左上角。
     {
      pRect->bottom -= pRect->top;
      pRect->top = 0;
     }
    }
   }
   else if (alignType == ALIGN_RIGHT)
   {
    if (pt.x < pRect->left) //当鼠标离开左边界时,解除停靠。
    {
     alignType = ALIGN_NONE;
     pRect->left -= NEAR_SIZE;
     pRect->right -= NEAR_SIZE;
    }
    else
    {
     pRect->left += (ScreenX - pRect->right);
     pRect->right = ScreenX;
     if (pRect->top < NEAR_SIZE) //考虑右上角。
     {
      pRect->bottom -= pRect->top;
      pRect->top = 0;
     }
    }
   }
  }
 }
 /*
 在窗体初始化是设定窗体状态,如果可以停靠,便停靠在边缘
 我本想寻求其他方法来解决初始化,而不是为它专一寻求一个函数,可是,窗体初始化时不发送WM_MOVING消息,我不得不重复类似任务.
 */
 void            NearSide(HWND hWnd)
 {
  int change = 0;
  RECT rect;
  GetWindowRect(hWnd, &rect);
  alignType = ALIGN_NONE;
  if (rect.left < NEAR_SIZE)
  {
   alignType = ALIGN_LEFT;
   if ((rect.left != 0) && rect.right != NEAR_SIDE)
   {
   rect.right -= rect.left;
   rect.left = 0;
   change = 1;
   }
  }
  else if (rect.right > ScreenX - NEAR_SIZE)
  {
   alignType = ALIGN_RIGHT;
   if (rect.right != ScreenX && rect.left != ScreenX - NEAR_SIDE)
   {
   rect.left += (ScreenX - rect.right);
   rect.right = ScreenX;
   change = 1;
   }
  }
  //调整上
  else if (rect.top < NEAR_SIZE)
  {
   alignType = ALIGN_TOP;
   if (rect.top != 0 && rect.bottom != NEAR_SIDE)
   {
    rect.bottom -= rect.top;
    rect.top = 0;
    change = 1;
   }
  }
  if (change)
  {
   MoveWindow(hWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE);
  }

 }

 /*
 窗体的显示隐藏由该函数完成,参数hide决定显示还是隐藏.
 */
 void HideSide(HWND hWnd, BOOL hide)
 {
  RECT rc;
  int moves = 20;  //动画滚动窗体的步数,如果你觉得不够平滑,可以增大该值.
  int xStep, yStep;
  int xEnd, yEnd;
  int width;
  int height;
  register int i;
  GetWindowRect(hWnd, &rc);
  width = rc.right - rc.left;
  height = rc.bottom - rc.top;

  //下边判断窗体该如何移动,由停靠方式决定
  switch (alignType)
  {
   case ALIGN_TOP:
   {
    //向上移藏
    xStep = 0;
    xEnd = rc.left;
    if (hide)
    {
    yStep = -rc.bottom / moves;
    yEnd = -height + NEAR_SIDE;
    }
    else
    {
    yStep = -rc.top / moves;
    yEnd = 0;
    }
    break;
   }
   case ALIGN_LEFT:
   {
    //向左移藏
    yStep = 0;
    yEnd = rc.top;
    if (hide)
    {
     xStep = -rc.right / moves;
     xEnd = -width + NEAR_SIDE;
    }
    else
    {
     xStep = -rc.left / moves;
     xEnd = 0;
    }
    break;
   }
   case ALIGN_RIGHT:
   {
    //向右移藏
    yStep = 0;
    yEnd = rc.top;
    if (hide)
    {
     xStep = (ScreenX - rc.left) / moves;
     xEnd = ScreenX - NEAR_SIDE;
    }
    else
    {
     xStep = (ScreenX - rc.right) / moves;
     xEnd = ScreenX - width;
    }
    break;
   }
   default:
    return;
  }
  //动画滚动窗体.
  for (i = 0; i < moves; i++)
  {
   rc.left += xStep;
   rc.top += yStep;
   SetWindowPos(hWnd, NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOSENDCHANGING);
   RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
   Sleep(5);
  }
  SetWindowPos(hWnd, NULL, xEnd, yEnd, 0, 0, SWP_NOSIZE);
  if (!hide) //如果窗体已被显示,设置定时器.监视鼠标.
  {
   SetTimer(hWnd, WM_TIMER, 500, NULL);
  }
 }
 //下面就是通过窗体回调函数将这些函数组织起来.
 //这里仅列出使用的消息
 case WM_TIMER: //定时器消息
 {
  POINT           pt;
  RECT            rc;
  GetCursorPos(&pt);
  GetWindowRect(hWnd, &rc);
  if (!PtInRect(&rc, pt)) //若鼠标不在窗体内,隐藏窗体.
  {
    KillTimer(hWnd, WM_TIMER);
    HideSide(hWnd, TRUE);
  }
  break;
 }
 case WM_CREATE:
 case WM_INITDIALOG: //初始化消息
 {
  SetWindowPos(...) //程序保存窗体上次靠位置,在这里恢复.
  NearSide(hWnd);
  break;
 }
 //这两个消息是在窗体移动开始时和结束时产生的,我们在窗体开始移动时关闭定时器,移动结束后再打开,这样避免窗体移动时隐藏,金山快译的浮动条就有这种情况出现.
 case WM_ENTERSIZEMOVE:
 {
  KillTimer(hWnd, WM_TIMER);
  break;
 }
 case WM_EXITSIZEMOVE:
 {
  SetTimer(hWnd, WM_TIMER, 500, NULL);
  break;
 }
 case WM_MOUSEMOVE: //受到窗体移动消息时,判断窗体是否显示,
 {
  RECT rc;
  GetWindowRect(hWnd, &rc);
  if (rc.left < 0 || rc.top < 0 || rc.right > ScreenX) //未显示
   HideSide(hWnd, FALSE);
  break;
 }
 case WM_MOVING: //处理窗体移动时消息,实现自动停靠
 {
  OnMoving(hWnd, (LPRECT) lParam);
  break;
 }
 case WM_MOVE:
 {
 //保存窗体位置
 }

关于C# 窗体自动隐藏和加载的问题 近在写一个小项目,开发一个小程序配合其他软件使用,其中一款软件在使用工作时需要截图生成报告,此时不能有其他应用程式界面在显示器桌面显示,故需要自动隐藏和加载窗体,通过阅读Windows API实现了这一功能与大伙分享交流一下:原本C#自带Hide()和Show()方法;但是在项目开发时将窗体定义为静态类型;故无法通过this关键字来调用其对应的隐藏和显示窗体方法。这里通过Windows API提供的函数来实现,首先要获取当前运行窗体的句柄,方法如下:   定义一个全局变量   IntPtr Handle;   [DllImport("user32.dll", EntryPoint = " 立即下载

相关推荐

AI Agent + 大数据 + RAG:电商用户行为分析的低成本落地

本文探讨了AIAgent与大数据技术在电商用户行为分析中的应用。通过构建"数据采集-实时分析-智能决策"的全自治链路,解决了传统大数据分析的三大痛点:人工建模周期长、实时性不足和决策闭环断裂。系统采用Flink+Spark处理实时数据,结合基于DeepSeek-V3.1的AIAgent实现智能分析,并通过飞书RAG模块动态获取业务知识。落地效果显示,分析响应时间从2-3天缩短至30秒,推荐转化率提升134%,验证了该方案在提升电商数据决策效率方面的显著价值。

想~ai抽 1617

createprocess创建进程并隐藏新进程的窗口

<br /><br />方法很简单,在createprocess调用时修改一下STARTUPINFO的参数,使其隐藏即可。<br />下面是代码示例:<br />PROCESS_INFORMATION pi;<br />STARTUPINFO si;      //隐藏进程窗口<br />si.cb = sizeof(STARTUPINFO);<br />si.lpReserved = NULL;<br />si.lpDesktop = NULL;<br />si.lpTitle = NULL;<b

highyyy的专栏 1万+

python blp模型 估计_随机系数Logit模型及Stata实现

欢迎投稿(荐稿)计量经济圈,计量相关都行邮箱:econometrics666@sina.cn作者:北京交通大学经济管理学院博士生,王琦珀。欢迎你加入计量经济圈社群,一起探讨前沿计量理论和实证方法。一、随机系数Logit模型1.背景实证产业组织(Empirical Industrial Organization,EIO)是目前产业组织理论的前沿,其中又以Ariel Pakes为带头人,其近期工作论文...

weixin_42298927的博客 2641

拖动窗口的问题 (转)

拖动窗口的问题 (转)[@more@]在VC++论坛里有人提问说: “我拖动我的窗口,只拖动一个虚线框,如何在拖动窗口时显示窗口内容?” 有人告诉提问人更改系统的显示属性:在“效果”里的“拖动窗口时显示内容”前打勾。 ...

csd3176的博客 205

完整IC设计流程解析&Makefile学习

本文介绍了decorder38项目的文件结构、自动化综合流程和Makefile使用方法。项目包含RTL到GDSII全流程文件,重点关注syn目录中的综合脚本。通过make dc命令运行综合流程,生成网表、约束和时序文件。关键报告如qor.rpt、area.rpt和min_vio.rpt用于分析综合质量、面积和时序。Makefile部分解释了其基本语法、IC设计中的典型结构,包括目标定义、命令执行和特殊声明,强调了其在自动化构建和依赖管理中的重要性。

m0_63352623的博客 855

dxf-viewer 查看器

dxf-viewer SDK 的示例,它是一个基于 Three.js 和 Vue3 构建的基于 WebGL 的 BIM 模型查看器。它用于查看 DWG/DXF/PDF 文件。面积测量 - 角度测量 -标记。

qq_25547755的博客 863

【MFC】实现子对话框透明并锚定于父对话框

在父对话框下新创建一个子窗体,要求1.子对话框没有边框,完全透明,文字颜色为白色;2.子对话框的初始位置在父对话框右下角;3.子对话框锚定于父对话框,父对话框移动时子对话框随之一起移动,视觉上融为一体。...

weixin_46283339的博客 1700

数学建模:相关性分析学习——皮尔逊(pearson)相关系数与斯皮尔曼(spearman)相关系数

相关性分析:求解相关系数并绘制热力图进行对比

weixin_67565775的博客 8万+

MFC限制子窗口只在父窗口内移动

1,响应WM_MOVE消息 在里面判断就完了 进消息向导找到它然后双击吧,然后添加你自己的限制代码(获取父窗口的clientRect,就是限制区域) 取得父窗口的顶点和右下角坐标,利用子窗口的顶点坐标和右下角坐标进行范围的判断即可 例如父窗口A(50.50)(100.100)子窗口的顶点坐标应该大于等于X1>=50&&Y1>=50 右下角坐标X2 2,应该是WM_MOVING消息

hyz5525的专栏 2939

菜鸟哥玩蓝牙Ble4.0系列 ESP32初玩篇③ Beacon —— 广播应用,室内定位,内容推送

文章目录1、前言1.1 什么叫做Beacon?1.2 Beacon使用场景1.3 Beacon协议落地实现2、ESP32 Beacon案例3、Beacon核心库 —— BLEBeacon、BLEEddystoneTLM、BLEEddystoneURL3.1 BLEBeacon3.2 BLEEddystoneTLM3.3 BLEEddystoneURL 授人以鱼不如授人以渔,目的不是为了教会你具体项目开发,而是学会学习的能力。希望大家分享给你周边需要的朋友或者同学,说不定大神成长之路有博哥的奠基石。。。

单片机菜鸟哥的博客 2万+

YOLO 系列专栏(二十九)YOLO26 × StarNet 轻量化涨点方案(CVPR 2024)轻量化、主干改进篇 | 星星卷积虽小,却蕴藏着巨大的高效潜力

StarNet 出自 CVPR 2024 轻量化主干网络工作,核心创新是,依靠逐元素乘法实现高阶特征融合,在几乎不增加参数量与 FLOPs 的前提下,大幅提升特征表达能力,天然适合等多任务统一建模。本文将 StarNet 完整替换 YOLO26 原有主干,保留 YOLO26 无 NMS 检测头与轻量化结构,实现,并提供。

qq_36130719的博客 409

WM_SIZE 改变窗口大小 消息

// DEMO3_9.CPP - WM_SIZE demo// INCLUDES ///////////////////////////////////////////////#define WIN32_LEAN_AND_MEAN  // just say no to MFC#include    // include all the windows headers#include   /

清风一吹(清风博客) 9729

【ATC/DTC方法第一期】经典平均/昼夜温度周期ATC/DTC方法介绍(含Python代码实现)

【ATC/DTC方法第一期】经典平均/昼夜温度周期ATC/DTC方法介绍(含Python代码实现)

WW、forever的博客 484

Windows 禁止悬浮窗移出屏幕外的有效实现

不对悬浮窗的移动加以处理是一件让用户很头疼的事。如果我们仅仅在按下左键时发送 WM_NCLBUTTONDOWN 消息,用户不能轻轻松松地让悬浮窗靠边,或者一不小心就把窗口移出屏幕外了。这就要求我们开发者要对其奋力优化。假设我们移动悬浮窗的基本代码如下: case WM_LBUTTONDOWN: { SendMessage(hwnd, WM_NCLBUTTONDOWN,

Orange Software 2961

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

VC窗口屏幕边缘吸附

现在需要实现窗口屏幕边缘吸附的效果,现在只考虑屏幕右边缘。思路如下: 当窗口右侧与屏幕右侧距离小于某个值(假设是20px)的时候,改变窗口的水平位置,使窗口右边框紧贴屏幕右侧。 这个动作时通过WM_MOVING消息实现的,当窗口移动时,窗口会收到这个消息,我们可以在这个消息中通过参数修改窗口位置。 这样实现的话问题就出现了,拖动窗口到右侧可以看到吸附效果,可是向左拽不动窗口了。 ...

weixin_30367543的博客 475

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Windows 消息大全

WM_ :窗口消息 窗口消息 // 自身 WM_ERASEBKGND // 当窗口背景必须被擦除时(例在窗口改变大小时) WM_GETFONT // 得到当前控件绘制文本的字体 WM_SETFONT // 设置当前控件绘制文本的字体 WM_GETTEXT // 得到与窗口对应的文本 WM_SETTEXT // 设置与窗口对应的文本 WM_GETTEXTLENGTH // 确定与窗口关联的文本的长度(以字符为单位)。 WM_SETICON // 将

LYSM 580

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

限制窗体的移动范围和缩放大小

作用: 可以控制MessageBox()确认窗口只能在父窗口的范围内移动,不能移出父窗口的范围。 注意:始终要保证子窗口坐标不越界以及维持窗口尺寸大小 方法:重载消息WM_MOVING //限制窗口的移动范围(不能在WM_MOVE中实现) void CDelTaskDlg::OnMoving(UINT fwSide, LPRECT pRect) { // TODO: 在此处

jiangqin115的专栏 3286

PC Camera开发日志(十二)------ 窗口的依附

我的项目中老大要求窗口能实现无缝链接,并完成吸附的效果。我用很笨的方法来实现的,原理是计算窗口的相对坐标,然后重载ON_WM_MOVE消息响应函数,使用MoveWindow来移动同样的相对尺寸,就实现了吸附的效果。我是使用在一组Dialog的吸附效果上,个人觉得只要移动同样的相对坐标,那么可以保持相对位置不变,看上去就像吸附。在这个过程当中我用到或者看到的小提示有: 一、屏幕坐标,

waterathena的专栏 764
上一篇: 旋转屏幕
下一篇: 浅谈API HOOK技术
ShenRui
博客等级 码龄20年 63粉丝 36原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值