zoukankan      html  css  js  c++  java
  • 如何获得窗口句柄(HWND )和改变窗口属性

    1、 对于一个窗口如何进行操作呢,首先要得到其使用句柄,我们可以用FindWindow()函数来获取当前窗口句柄,具体使用如下:

      HWND hFig = ::FindWindow(NULL,HWND);

      如果得到找到,则返回窗口的句柄,否则返回NULL。 当然我们可以使用 SetWindowPos(HWND hWnd, HWND hWndIsertAfter, int X, int Y, int cx, int cy , UINT Uflags) 改变窗口的大小和位置,Uflags是标志窗口的显示属性,具体值可以是SWP_NOMOVE 、SWP_NOZORDER 、SWP_NOACTIVATE 、SWP_FRAMECHANGED等。 具体的调用实例如下:

      HWND hFig = ::FindWindow(NULL,"Fig No. 1"); //找到窗口,并返回窗口句柄

      if(hFig == NULL) {

        AfxMessageBox("未能产生Figure窗口,图形绘制失败!");

        return;

      } // 获取绘图区域的位置和大小

      RECT PlotRec;

      CWnd *PlotArea = GetDlgItem(IDC_PLOTAREA); // 获取绘图区域指针

      PlotArea->GetWindowRect(&PlotRec); // 将绘图区域矩形赋给 定义矩形

      long Width = PlotRec.right - PlotRec.left; long Height = PlotRec.bottom - PlotRec.top; // 获得绘图区域的宽和高

      // 设置Figure窗口为绘图区域窗口的子窗口并调整其位置

      ::SetParent(hFig,PlotArea->GetSafeHwnd()); // 设置绘图区域窗口为 Figure窗口的父窗口

      ::SetWindowPos(hFig,NULL,1,1,Width,Height,SWP_NOZORDER | SWP_NOACTIVATE); // 设置绘图窗口的大小和位置

      // 设置窗口可见

      SetVisible(h_a,mwArray("ON"));

      // 进入窗口等待状态

      bWait = 1; mlfHGWaitForFiguresToDie();

    2、当然你想改变窗口属性的话,还可以增加以下函数来改变窗口的属性

      long lStyle. = ::GetWindowLong(hFig,GWL_STYLE);

      ::SetWindowLong(hFig,GWL_STYLE,lStyle. & (~WS_CAPTION) & (~WS_THICKFRAME));

      ::SetWindowPos(hFig,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);

    就写到这吧,其他的学会了再统一以一个实例的形式给出。

  • 相关阅读:
    SAP OPEN UI5 Step 8: Translatable Texts
    SAP OPEN UI5 Step7 JSON Model
    SAP OPEN UI5 Step6 Modules
    SAP OPEN UI5 Step5 Controllers
    SAP OPEN UI5 Step4 Xml View
    SAP OPEN UI5 Step3 Controls
    SAP OPEN UI5 Step2 Bootstrap
    SAP OPEN UI5 Step1 环境安装和hello world
    2021php最新composer的使用攻略
    Php使用gzdeflate和ZLIB_ENCODING_DEFLATE结果gzinflate报data error
  • 原文地址:https://www.cnblogs.com/buffer/p/1407352.html
Copyright © 2011-2022 走看看