473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Creating a window from PyHandle? Possible?

Hi guys,

This is the first time I'm posting to the newsgroup, hope you can help out.

I'm writing a module to interface with the task scheduler in windows
using PyWin32. Everything has been great so far but I'm stuck on
displaying the propertys page of a task. Here's the code:

import pythoncom
import win32api
from win32com.taskscheduler import taskscheduler
import win32ui

task_scheduler = pythoncom.CoCreateInstance\
(taskscheduler.CLSID_CTaskScheduler,
None, pythoncom.CLSCTX_INPROC_SERVER,
taskscheduler.IID_ITaskScheduler)

def show_schedule_page(task_name):

TASKPAGE_TASK = 0,
TASKPAGE_SCHEDULE = 1,
TASKPAGE_SETTINGS = 2

try:
task = task_scheduler.Activate(task_name)
except pythoncom.com_error, e:
print 'Task name not found...'
return

# ** This returns a PyHandle
handle = task.QueryInterface(taskscheduler.IID_IProvideTask Page).\
GetPage(1, True)

# ** Can't create a window with it using win32ui, returns error
try:
win32ui.CreateWindowFromHandle(handle)
except win32ui.error, e:
print e

# ** Can't add it to a property sheet, return an error
property_sheet = win32ui.CreatePropertySheet('Task Schedule')
try:
property_sheet.AddPage(handle)
except (win32ui.error, TypeError), e:
print e

show_schedule_page('task1')

Any ideas on how to do it? The task schduler api reference is at
http://msdn.microsoft.com/library/de...start_page.asp

I'm pretty new at this, is there anything that I've missed out?

Cheers,
Fadly Tabrani
python loves me loves python
Jul 18 '05 #1
1 4199
The basic problem is that the handle returned from GetPage is not an MFC
object, and win32ui is expecting an MFC property sheet page, not a raw
handle.
I played around with this a while back, and managed to display the property
page
by sending the window message PSM_ADDPAGE to a PyCPropertySheet.
However, you can't use SendMessage until you've called CreateWindow for the
property sheet, and you can't call CreateWindow until you've added a
property
page. (catch-22!) I got around this by adding a dummy page to the property
sheet,
calling CreateWindow & SendMessage to add the task page, and then removing
the stand-in. But since the task page isn't MFC, after I did that any
attempt to call methods on the property sheet caused an access violation.

Roger

import win32api,win32con, win32ui, pythoncom
import traceback, os
from win32com.taskscheduler import taskscheduler
PSM_ADDPAGE = win32con.WM_USER + 103
PSM_REMOVEPAGE = win32con.WM_USER + 102
task_name='test_addtask_4.job'

ts=pythoncom.CoCreateInstance(taskscheduler.CLSID_ CTaskScheduler,None,

pythoncom.CLSCTX_INPROC_SERVER,taskscheduler.IID_I TaskScheduler)

t=ts.Activate(task_name)
iptp=t.QueryInterface(taskscheduler.IID_IProvideTa skPage)
tp=iptp.GetPage(taskscheduler.TASKPAGE_TASK,False)

fname=os.path.join(os.environ['SYSTEMROOT'],'system32','mstask.dll')
dll=win32ui.LoadLibrary(fname)
try:
dll.AttachToMFC()
except:
traceback.print_exc()

ps=win32ui.CreatePropertySheet('eh ?????')

## property sheet won't let you CreateWindow unless there's already a
property page attached,
## and you can't do a SendMessage until you've created a window !!!!
pptask=win32ui.CreatePropertyPage(401) ## 401 is the task page template from
mstask.dll, identified using EnumResources
ps.AddPage(pptask)
ps.CreateWindow()
ps.SendMessage(PSM_ADDPAGE,0,tp)
## get rid of the dummy
ps.RemovePage(0)

"Fadly Tabrani" <no@spam.net> wrote in message
news:ck**********@mawar.singnet.com.sg...
Hi guys,

This is the first time I'm posting to the newsgroup, hope you can help out.
I'm writing a module to interface with the task scheduler in windows
using PyWin32. Everything has been great so far but I'm stuck on
displaying the propertys page of a task. Here's the code:

import pythoncom
import win32api
from win32com.taskscheduler import taskscheduler
import win32ui

task_scheduler = pythoncom.CoCreateInstance\
(taskscheduler.CLSID_CTaskScheduler,
None, pythoncom.CLSCTX_INPROC_SERVER,
taskscheduler.IID_ITaskScheduler)

def show_schedule_page(task_name):

TASKPAGE_TASK = 0,
TASKPAGE_SCHEDULE = 1,
TASKPAGE_SETTINGS = 2

try:
task = task_scheduler.Activate(task_name)
except pythoncom.com_error, e:
print 'Task name not found...'
return

# ** This returns a PyHandle
handle = task.QueryInterface(taskscheduler.IID_IProvideTask Page).\ GetPage(1, True)

# ** Can't create a window with it using win32ui, returns error
try:
win32ui.CreateWindowFromHandle(handle)
except win32ui.error, e:
print e

# ** Can't add it to a property sheet, return an error
property_sheet = win32ui.CreatePropertySheet('Task Schedule')
try:
property_sheet.AddPage(handle)
except (win32ui.error, TypeError), e:
print e

show_schedule_page('task1')

Any ideas on how to do it? The task schduler api reference is at
http://msdn.microsoft.com/library/de...start_page.asp
I'm pretty new at this, is there anything that I've missed out?

Cheers,
Fadly Tabrani
python loves me loves python

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Tom Moroow | last post by:
Hi, I'm pretty new to javascript and was wondering how you would piece together a variable name and then assign it a value. I want to create a hidden field and assign it a value based on the value...
4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
2
by: Wayne Hornak via .NET 247 | last post by:
I want to, when a user presses a button, to provide them withanother screen. How do I do this? It seems that theResponse.Redirect will change pages in the same window, I wantanother window to...
9
by: kermit | last post by:
I keep seeing that you can use the FileSystemObject in either VB script, or Javascript on an aspx page. I added a refrence to the scrrun.dll I added importing namespaces for 'System.Object',...
2
by: JIM.H. | last post by:
Hello, I have an asp.net C# application and have many pages and each page has many buttons. So I would like to have an help button and if user click it should open another window and give help to...
3
by: Progalex | last post by:
Hi everybody! I'm creating a very simple VB .NET application that needs to launch the command line ml.exe compiler. At the moment I'm redirecting ML's output to a text file and then my app...
5
by: John Scott | last post by:
Ok..this a rather odd question/problem. I haven't really found a straight forward answer to how to handle this scenario, so I hope someone here can help. Here it is: I have an application...
1
by: Frijoles | last post by:
Hello, I have a function that accepts an Image as the input. Currently, I load a bitmap in the calling class and pass that in. I'd like to create an overlay with another image and then pass the...
0
by: =?Utf-8?B?c2Vy?= | last post by:
Hi, I am working on a windows application whose primary task is to apply all the properties of one control to another. Hence i am using the SetValue method of the PropertyDescriptor. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.