给定Win32窗口的句柄,我需要找到它相对于其父窗口的位置.
我知道几个函数(例如; GetWindowRect()
和GetClientRect()
),但它们都没有显式返回所需的坐标.
我该怎么做呢?
我正在为Windows开发一个c ++应用程序.我正在使用win32 API.我有一个非常简单的问题,我无法找到答案.如何打开没有标题栏的窗口(没有控件,图标和标题),并且无法调整大小.
我用于创建窗口的应用程序的一段代码:
hWnd = CreateWindow(szWindowClass, 0, (WS_BORDER ),
0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);
Run Code Online (Sandbox Code Playgroud)
更新:
要在c#中执行此操作,您只需定义以下代码:
FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
ControlBox = false;
Run Code Online (Sandbox Code Playgroud) 我正在使用python为windows编写简单的托盘.
我成功创建了一个托盘图标,菜单,子菜单.我坚持为特定的托盘项目添加图像.
这是我用过的代码.(链接)即使这段代码也行不通.Windows文档不清楚.
def addMenuItem(self, wID, title, menu):
path = os.path.dirname(os.path.abspath(__file__))
path += "\print_pref.ico"
option_icon = self.prep_menu_icon(path)
item, extras = win32gui_struct.PackMENUITEMINFO(text=title,
hbmpItem=option_icon,
wID=wID)
win32gui.InsertMenuItem(menu, 0, 1, item)
def prep_menu_icon(self, icon):
# First load the icon.
ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON)
ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON)
hicon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE)
hdcBitmap = win32gui.CreateCompatibleDC(0)
hdcScreen = win32gui.GetDC(0)
hbm = win32gui.CreateCompatibleBitmap(hdcScreen, ico_x, ico_y)
hbmOld = win32gui.SelectObject(hdcBitmap, hbm)
# Fill the background.
brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU)
win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush)
# …
Run Code Online (Sandbox Code Playgroud) 我在pyqt QApplication的选项卡中嵌入了一个应用程序.当我关闭选项卡时,此应用程序嵌入在如何允许它显示"保存更改"对话框中?
我在tab_close上使用它:
win32gui.PostMessage(int(wdg.process._handle),win32con.WM_CLOSE,0,0)
Run Code Online (Sandbox Code Playgroud)
当我这样做时,如果应用程序通常会抛出一个,我会丢失此对话框.
代码看起来类似于:
class MainWindow(QTabWidget):
def __init__(self, parent=None):
QTabWidget.__init__(self, parent)
self.setTabsClosable(1)
self.tabCloseRequested.connect(self.close_tab)
...
def close_tab(self,ind):
wdg = self.widget(ind)
win32gui.PostMessage(int(wdg.process._handle),win32con.WM_CLOSE,0,0)
self.removeTab(ind)
del wdg
...
Run Code Online (Sandbox Code Playgroud)
这会产生这样的UI(嵌入了Window的notepad.exe).单击选项卡上的"X"将关闭记事本,而不会提示用户保存任何输入.
如何关闭选项卡并允许嵌入式应用程序提示用户保存其更改?
我的Python文件,我已经导入了win32gui
这样的模块:
import win32gui
Run Code Online (Sandbox Code Playgroud)
我也下载win32gui
但不知道如何让我的脚本运行.如何运行导入的Python脚本win32gui
?当我运行它时,我得到:
ImportError: No module named win32gui
Run Code Online (Sandbox Code Playgroud)
抱歉新手问题,但我正在尝试学习Python,所以不太了解它.
如何获取所有打开的窗口的名称/文本列表?
我试过pywinauto:
pywinauto.findwindows.find_windows(title_re="*")
但*
用作正则表达式会引发错误
我试过 win32gui:它有
win32gui.GetWindowText(win32gui.GetForegroundWindow())
但在它的文档中,我找不到 getAllWindows 或返回打开 hwnd 句柄的所有名称/文本的内容:http ://timgolden.me.uk/pywin32-docs/contents.html
我正在尝试通过搜索其标题来编写一个找到窗口的程序.一旦找到窗口,它将尝试将其带到前面.我正在使用win32gui
API来实现这一目标.我能够让它在大多数情况下工作,但由于某种原因,如果任务管理器在前面,它就不起作用.我有以下示例代码.
import win32gui, win32con
import re, traceback
from time import sleep
class cWindow:
def __init__(self):
self._hwnd = None
def BringToTop(self):
win32gui.BringWindowToTop(self._hwnd)
def SetAsForegroundWindow(self):
win32gui.SetForegroundWindow(self._hwnd)
def Maximize(self):
win32gui.ShowWindow(self._hwnd, win32con.SW_MAXIMIZE)
def setActWin(self):
win32gui.SetActiveWindow(self._hwnd)
def _window_enum_callback(self, hwnd, wildcard):
'''Pass to win32gui.EnumWindows() to check all the opened windows'''
if re.match(wildcard, str(win32gui.GetWindowText(hwnd))) != None:
self._hwnd = hwnd
def find_window_wildcard(self, wildcard):
self._hwnd = None
win32gui.EnumWindows(self._window_enum_callback, wildcard)
def main():
sleep(5)
try:
wildcard = ".*Building Operation WorkStation.*"
cW = cWindow()
cW.find_window_wildcard(wildcard)
cW.Maximize()
cW.BringToTop()
cW.SetAsForegroundWindow()
except:
f …
Run Code Online (Sandbox Code Playgroud) 我在主窗口中创建了几个按钮(窗口),但是Tab键和箭头键不起作用.我的研究表明,对于C++,在消息泵中使用IsDialogMessage创建了TranslateMessage/DispatchMessage的旁路,如下所示,以允许此功能:
while(GetMessage(&Msg, NULL, 0, 0))
{
if(!IsDialogMessage(g_hToolbar, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我正在使用python和win32gui模块来创建CreateWindows,我无法弄清楚如何绕过正常的消息捕获以允许自然处理键盘.我的代码与此类似:
from win32gui import *
from win32con import *
window_class = WNDCLASS()
hinst = window_class.hInstance = GetModuleHandle(None)
window_class.lpszClassName = 'ClassName'
window_class.style = CS_VREDRAW | CS_HREDRAW
window_class.hCursor = LoadCursor(0, IDC_ARROW)
window_class.hbrBackground = COLOR_WINDOW
window_class.lpfnWndProc = {}
classAtom = RegisterClass(window_class)
hwnd = CreateWindow(classAtom, "", WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION
| WS_SYSMENU | WS_MINIMIZEBOX | WS_EX_TOPMOST | WS_CLIPSIBLINGS,
0, 0, 140, 100, 0, 0, GetModuleHandle(None), None)
btn1_hwnd = CreateWindow("Button", "btn …
Run Code Online (Sandbox Code Playgroud) 在开发检查软件时,我有一个要求防止通过TeamViewer,AnyDesk,Ammyy Admin等应用程序共享桌面,或者至少阻止对其进行检测。我们的考试软件是用C#开发的,它是一种winform逐一呈现问题。
我不认为检测如此简单,因为它们有多种捕获屏幕桌面复制API,BitBlt,Direct3D,DirectX,DirectShow等方法。
因此,我开始探索如何防止在启动桌面共享时显示我的c#winform。为此,到目前为止,我已经尝试了以下操作:
SetWindowDisplayAffinity
为WDA_MONITOR
对Winform 启用保护的桌面组合来利用DWM(停止窗口管理器)。通过在我开始桌面共享时执行此操作,远程控制的计算机可以看到表单上的黑色层。但是,并非所有桌面共享应用程序都具有相同的行为。就像TeamViewer的行为一样,但Ammyy Admin的行为却像AnyDesk。某些应用程序如何显示黑层而有些则不显示?我还能做些什么吗? if (winForm != null)
{
if (Protect)
result = SetWindowDisplayAffinity(winForm.Handle, WDA_MONITOR);
else
result = SetWindowDisplayAffinity(winForm.Handle, WDA_NONE);
}
Run Code Online (Sandbox Code Playgroud)
我编码的这种方法并不完全适用于所有桌面共享应用程序,因此,是否有100%的解决方案可以防止/检测桌面共享?
如果您尝试了VLC播放器的“ DirectX(DirectDraw)视频输出”,那么此输出方法也将执行相同的操作SetWindowDisplayAffinity
,当启动任何桌面共享应用程序时,它将在视频上显示黑色图层,而我测试了该功能是否可与将近9种桌面共享应用程序一起使用知道怎么做?可以用c#winform完成吗?
更新29-05-2019
检查VLC代码后,我知道它们正在使用DirectDraw进行硬件覆盖。因此,我创建了vc ++项目并使用d3d9并创建了具有红色表面的覆盖,现在,如果我将机器移开,则红色的表单将显示黑色。答对了!!解决了一半问题。
现在,我正在尝试为该窗口设置透明度,以便覆盖将在我的C#应用程序的顶部,并且考生可以进行考试,如果进行远程考试,则覆盖将以黑色显示。为了使窗口透明,我使用了DwmExtendFrameIntoClientArea
winapi,但是现在在远程也可以将其显示为透明。有什么办法吗?