我手边有一个名为“MDI demo”的MDI应用程序。我想用win32 API拍摄一个子窗口的快照,比如“subwindow1”。我可以使用GetApplicationHwnd
获取应用程序的父主窗口。但我找不到任何API来获取直接子MDI客户端窗口。
目前,我尝试使用父级句柄作为参数的EnumChildWindow。但是,似乎在MDI应用程序中找不到子窗口。
这是一个例子,MDI应用程序是Python,PyQt5
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class MainWindow(QMainWindow):
count = 0
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.mdi = QMdiArea()
self.setCentralWidget(self.mdi)
bar = self.menuBar()
file = bar.addMenu("File")
file.addAction("New")
file.addAction("cascade")
file.addAction("Tiled")
file.triggered[QAction].connect(self.windowaction)
self.setWindowTitle("MDI demo")
def windowaction(self, q):
print "triggered"
if q.text() == "New":
MainWindow.count = MainWindow.count+1
sub = QMdiSubWindow()
sub.setWidget(QTextEdit())
sub.setWindowTitle("subwindow"+str(MainWindow.count))
self.mdi.addSubWindow(sub)
sub.show()
if q.text() == "cascade":
self.mdi.cascadeSubWindows()
if q.text() == "Tiled":
self.mdi.tileSubWindows()
def main():
app = QApplication(sys.argv)
ex = MainWindow()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
我在C ++中的win32快照程序的骨架如下
#include <iostream>
#include <vector>
#include <Windows.h>
#include <gdiplus.h>
using namespace std;
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) {
cout << "I find a child" << endl;
}
char APPNAME[] = "MDI demo";
int main(int argc, char *argv[]) {
vector<HWND> hwnds = GetApplicationHwnd(APPNAME);
int succeed = 0;
cout << "Found " << hwnds.size() << " windows called " << APPNAME << endl;
for (int i = 0; i < hwnds.size(); ++i) {
EnumChildWindows(hwnds[i], EnumChildProc, (LPARAM)NULL);
}
int a;
cin >> a;
}
你介意任何暗示如何收益吗?谢谢。