❶ 知道一个窗体的句柄,如何获取这个窗体
var frm = (Control)Form.FromHandle(h);
h为句柄,我这里强转成control了,你可以自己看情况改动
我原来写过一个例子,调用cmd.exe窗口,并嵌入到自己的窗体内,你可以参考一下
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form2 : Form
{
[DllImport("user32", EntryPoint = "SetParent", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32", EntryPoint = "FindWindowA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessageA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam);
[DllImport("shell32.dll", EntryPoint = "ShellExecuteA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int ShellExecute(int hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
private const int WM_SYSCOMMAND = 0x112;
private const int SC_MAXIMIZE = 0xF030;
private const int SC_MINIMIZE = 0xF020;
private const int SC_RESTORE = 0xF120;
public const int SW_HIDE = 0;
public const int SW_SHOW = 5;
[DllImport("user32.dll ", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int ShowWindow(int hwnd, int nCmdShow);
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
//Process p = null;
// p = System.Diagnostics.Process.Start("c:\\windows\\system32\\cmd.exe");
ShellExecute(this.panel1.Handle.ToInt32(), "open", @"c:\\windows\\system32\\cmd.exe", null, ".", SW_HIDE); // 让CtrlDemo.exe运行在PANEL里
IntPtr h = FindWindow(null, "c:\\windows\\system32\\cmd.exe");
//关键在这里
var frm = (Control)Form.FromHandle(h);
//使你的Form可以嵌入别的容器
//frm.Visible = true;
SetParent(h, this.panel1.Handle); //嵌套到panel1内
SendMessage(h.ToInt32(), WM_SYSCOMMAND, SC_MAXIMIZE, 0);
ShowWindow(h.ToInt32(), SW_SHOW);
}
}
}
❷ fromhandle()是干嘛函数是做什么用的
pMap是什么玩意儿? FromHandle(HWMD hWnd)是静态方法啊,用类名直接调用,返回的就是CWnd*,不需要强制转换。谁写的代码?在什么场合里写的代码?
❸ CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));是什么意思,求翻译
楼主你好!
整个的这一句代码,是这样的,下面我一个地方一个地方给你解释:
首先,定义了一个CBrush类的指针pBrush,然后,将这个CBrush类的成员函数FromHandle()的返回值赋给它,因为CBrush是封装类,所以,用::符,指明在这里调用的是CBrush类的FromHandle(),而不是CWnd、CDialog等类的,因为FromHandle()在很多封装类中都有,作为方法成员(即成员函数)。FromHandle()见名思义,即“从句柄获得什么什么”。
GetStockObject()用在这里,指明你要创建一个什么样的画刷,是空画刷?还是实心画刷?还是其他的?NULL_BRUSH是一个宏,表示空画刷,在这里等同于HOLLOW_BRUSH,两个可以通用。HOLLOW,中文意思即为“空”。所以,这句代码,是创建了一个画刷类(CBrush)的指针变量,并在定义之时,为其创建了一个空画刷。
通常,可以在为静态文本控件、编辑框控件、按钮控件等控件设置透明时,使用这句代码。
希望能为你带来帮助,谢谢!
❹ 怎么理解CWnd::FromHandle(HWMD hWnd)里的一句
pMap是什么玩意儿?
FromHandle(HWMD hWnd)是静态方法啊,用类名直接调用,返回的就是CWnd*,不需要强制转换。
谁写的代码?在什么场合里写的代码?
❺ 同一个线程 FromHandlePermanent不能得到窗口对象
说半天也没说明白。这个函数只会获取CWnd指针,不会创建CWnd对象。换句话说,你进行操作的窗口句柄必须关联了CWnd或其派生类的对象这个函数才能起作用。
❻ FromHandlePermanent到底返回什么东西
FromHandle 当给定一个窗口的句柄时,返回CWnd对象的指针。如果没有CWnd对象与这个句柄相连接,则创建一个临时的CWnd对象并与之相连接 FromHandlePermanent 当给定一个...
❼ CBitmap::FromHandle(hBitmap) 将hbitmap变成CBitmap类 怎么成全局变量,使hbitmap也能在别的函数中调用
可以参照 theApp的作法
❽ 我想给CIMAGE 添加 绘画的对象 CDC::FromHandle 怎么用啊
首先说FromHandle用法,这样不对,正确的是这样的:
HDC hDC;....
CDC mDC;
mDC.FromHandle(hDC);
其次说思路,你的需求,正确思路是这样的:在画图之前,CreateCompatibleDC创建内存DC,SelectObject将一个位图句柄加载到内存DC,画图直接使用内存DC,然后BitBlt到设备dc(在OnDraw或者Onpaint中),这样在画完成之后,这个位图句柄就可以保存你画的图了。
❾ FromHandle函数的作用和用法
使用一个句柄初始化对象
因为MFC的类很多都是封装SDK中相对应句柄的
先SDK去看看
看完SDK再去理解MFC不然要弄晕的
❿ 电脑老是弹出个英文窗口,怎么解决
360修复一下试试