任何人都可以指出(或提供?)一些很好的,明确的如何在Win32中实现滚动的例子?显然,谷歌提出了很多东西,但大多数例子对我来说似乎太简单或太复杂,无法确保他们能够证明正确的做事方式.我在当前项目中使用LispWorks CAPI(跨平台Common Lisp GUI库),在Windows上我有一个难以弄清楚的与滚动相关的错误; 基本上我想通过Win32 API直接做一些测试,看看我是否可以对这种情况有所了解.
非常感谢,克里斯托弗
我用C语言开发了蒸汽表方程求解器......但是在黑屏控制台中输入值很无聊.
所以我非常想在C中创建简单的GUI.
我搜索了你好的世界代码,都很长.但这是我理解的唯一一个.
#include <windows.h>
int main()
{
MessageBoxA( NULL, "Hello World!", "Hello", MB_OK );
}
Run Code Online (Sandbox Code Playgroud)
通过使用GUI构建器C,我得到这个代码,现在我在想如何扫描从textBox1的1和TextBox值在CommandButton1的点撃,并显示在TEXTBOX3输出?
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include "hello.auto.h"
HWND hwnd_Label1, hwnd_Label2, hwnd_TextBox1, hwnd_TextBox2, hwnd_CommandButton1,
hwnd_TextBox3;
HFONT MSSansSerif_8pt;
void CreateChildWindows(HWND hwndMainWindow, HINSTANCE hInstance)
{
InitCommonControls();
MSSansSerif_8pt = CreateFont(-11,0,0,0,FW_NORMAL,0,0,0,0,0,0,0,0,"MS Sans Serif");
hwnd_Label1 = CreateWindowEx(0, "Static", "Pressure",
WS_CHILD | WS_VISIBLE,
11, 55, 95, 38, hwndMainWindow,
(HMENU)Label1, hInstance, NULL);
SetWindowFont(hwnd_Label1, MSSansSerif_8pt, TRUE);
hwnd_Label2 = CreateWindowEx(0, "Static", "Temperature",
WS_CHILD | …
Run Code Online (Sandbox Code Playgroud) 我像这样得到活动窗口:
window = win32gui.GetForegroundWindow()
Run Code Online (Sandbox Code Playgroud)
这是一个Int,比如1053634.然后我尝试将前景窗口设置回指定的窗口:
win32gui.SetForegroundWindow(window)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:win32gui.SetForegroundWindow(window)错误:(127,'SetForegroundWindow','无法找到指定的过程.')
有时当我在解释器中执行此操作时,我收到此错误:
win32gui.SetForegroundWindow(1053634)
error: (0, 'SetForegroundWindow', 'No error message is available')
Run Code Online (Sandbox Code Playgroud)
您认为这个问题是什么?
谢谢!
我只是在学习python,而我是相对论的新手。我创建了以下脚本,该脚本将获取当前活动的Windows标题并将其打印到窗口中。
import win32gui
windowTile = "";
while ( True ) :
newWindowTile = win32gui.GetWindowText (win32gui.GetForegroundWindow());
if( newWindowTile != windowTile ) :
windowTile = newWindowTile ;
print( windowTile );
Run Code Online (Sandbox Code Playgroud)
上面的代码段有效。我没有尝试获取活动窗口(Foreground Window
)的应用程序名称
我的问题是:
编辑
例如:如果用户从计算器(calc.exe)切换到Google Chrome(chrome.exe),我想查看他们切换到的应用程序被调用了。标题的问题在于,并非所有的应用程序都以应用程序名称作为标题的前缀。例如,谷歌浏览器将页面标题作为窗口标题。我想知道用户切换到哪个应用程序。
calc.exe
chrome.exe
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用python 2.7中的win32gui获取桌面上的项目数.
以下代码:win32gui.SendMessage(win32gui.GetDesktopWindow(), LVM_GETITEMCOUNT)
返回零,我不知道为什么.
我win32api.GetLastError()
后来写了,它也返回零.
提前致谢.
编辑:我需要使用这种方法,因为最终目标是获取图标的位置,并通过类似的方法完成.所以我只是想确保我知道如何使用这种方法.另外,我认为它可以提供与列出桌面内容不同的输出(可以吗?).第三,我如何获得这些职位的来源建议采用这种方式 - 例如http://www.codeproject.com/Articles/639486/Save-and-restore-icon-positions-on-desktop.
EDIT2:
获取计数的完整代码(对我不起作用):
import win32gui
from commctrl import LVM_GETITEMCOUNT
print win32gui.SendMessage(win32gui.GetDesktopWindow(), LVM_GETITEMCOUNT)
Run Code Online (Sandbox Code Playgroud)
再次感谢!
解:
import ctypes
from commctrl import LVM_GETITEMCOUNT
import pywintypes
import win32gui
GetShellWindow = ctypes.windll.user32.GetShellWindow
def get_desktop():
"""Get the window of the icons, the desktop window contains this window"""
shell_window = GetShellWindow()
shell_dll_defview = win32gui.FindWindowEx(shell_window, 0, "SHELLDLL_DefView", "")
if shell_dll_defview == 0:
sys_listview_container = []
try:
win32gui.EnumWindows(_callback, sys_listview_container)
except pywintypes.error as e:
if e.winerror …
Run Code Online (Sandbox Code Playgroud) 我想写一个简单的系统托盘应用程序,它检查一些Web服务的状态,并根据给出的响应更改其图标.我正在以非阻塞方式进行分散,以便程序仍然响应,因为它每10秒触发一次http请求.你能帮忙吗 - 我对winapi来说是一个彻头彻尾的菜鸟???
#!/usr/bin/env python
# Module : SysTrayIcon.py
# Synopsis : Windows System tray icon.
# Programmer : Simon Brunning - simon@brunningonline.net
# Date : 11 April 2005
# Notes : Based on (i.e. ripped off from) Mark Hammond's
# win32gui_taskbar.py and win32gui_menu.py demos from PyWin32
'''TODO
For now, the demo at the bottom shows how to use it...'''
import json
import time
import urllib2
import os
import sys
import win32api
import win32con
import win32gui_struct
try:
import winxpgui as …
Run Code Online (Sandbox Code Playgroud) 我发现了以下三种在Windows中获取鼠标坐标的方法:
from ctypes import windll, Structure, c_long, byref
class POINT(Structure):
_fields_ = [("x", c_long), ("y", c_long)]
def MousePosition_ctypes():
pos = POINT()
windll.user32.GetCursorPos(byref(pos))
return {"x":pos.x,"y":pos.y}
import win32api
def MousePosition_win32api():
pos = win32api.GetCursorPos()
return {"x":pos[0],"y":pos[1]}
import win32gui
def MousePosition_win32gui():
flags, hcursor, (x,y) = win32gui.GetCursorInfo()
return {"x":x,"y":y}
Run Code Online (Sandbox Code Playgroud)
它们之间有什么区别?使用ctypes有优势吗?pywin32在这里和ctypes一样吗?
我进行了10 ^ 6次运行的计时测试。
import timeit
print("MousePosition_ctypes ",timeit.repeat("MousePosition_ctypes()", "from __main__ import MousePosition_windll",number=10**6))
print("MousePosition_win32api",timeit.repeat("MousePosition_win32api()", "from __main__ import MousePosition_win32api",number=10**6))
print("MousePosition_win32gui",timeit.repeat("MousePosition_win32gui()", "from __main__ import MousePosition_win32gui",number=10**6))
Run Code Online (Sandbox Code Playgroud)
结果:
MousePosition_ctypes [3.171214059203684, 3.0459668639906723, 3.0454502913267243]
MousePosition_win32api [1.9730332863218454, 1.9517156492346004, 2.072004962338813]
MousePosition_win32gui [1.787176519159173, 1.8011713842243182, 1.8127041221688245]
Run Code Online (Sandbox Code Playgroud)
因此,win32gui版本将是最快的。 …
Program.cs代码-
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Run Code Online (Sandbox Code Playgroud)
对于Form1
public Form1()
{
InitializeComponent();
var displayIcon = new NotifyIcon();
displayIcon.Icon = SystemIcons.Information;
displayIcon.BalloonTipText = "test";
displayIcon.Visible = true;
displayIcon.ShowBalloonTip(3000);
displayIcon.Click += DisplayIcon_Click;
displayIcon.BalloonTipClicked += DisplayIcon_BalloonTipClicked;
}
private void DisplayIcon_BalloonTipClicked(object sender, EventArgs e)
{
// throw new NotImplementedException();
}
private void DisplayIcon_Click(object sender, EventArgs e)
{
// throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)
当气球通知在桌面上显示3秒钟时,将引发事件DisplayIcon_BalloonTipClicked。但是,即使通知转到操作中心,即使应用程序正在运行,也不会引发该事件。请在这里提出问题。
我使用win32gui
将记事本窗口移动到屏幕的原点 (0, 0),宽度和高度等于 500。结果是窗口没有移动到真正的左边框,而是 ~10 px。向右。宽度和高度也不等于 500 像素。(~620 像素。相反)。
我正在使用以下代码来生成我的结果。
import win32gui
from PIL import ImageGrab
# Open notepad.exe manually.
hwnd = win32gui.FindWindow(None, "Untitled - Notepad")
win32gui.MoveWindow(hwnd, 0, 0, 500, 500, True)
bbox = win32gui.GetWindowRect(hwnd)
img = ImageGrab.grab(bbox)
Run Code Online (Sandbox Code Playgroud)
我一直在 Python3 中使用 win32api 创建一个支持 toast 通知的 Windows 10 应用程序。
我的应用程序已经有一个系统托盘图标,我正在使用以下代码添加 toast 通知
def show_toast(self,msg,title):
flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, self.hicon,
"SpotiFind")
win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, (self.hwnd, 0,
win32gui.NIF_INFO,
win32con.WM_USER + 20,
self.hicon, "Balloon Tooltip", msg, 200, title))
Run Code Online (Sandbox Code Playgroud)
一切正常,但通知保留在通知区域,我想自动删除它......根据 MSDN ( https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/ns-shellapi -_notifyicondataa )
要移除气球通知,请指定 NIF_INFO 并通过 szInfo 提供一个空字符串。
所以我尝试了以下
def _destroy_toast(self):
win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, (self.hwnd, 0,
win32gui.NIF_INFO,
win32con.WM_USER + 20,
self.hicon, "Balloon Tooltip", "", 200, ""))
Run Code Online (Sandbox Code Playgroud)
这没什么...
提前致谢..