免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8418 | 回复: 7
打印 上一主题 下一主题

pythonwin获取快捷方式的地址及创建快捷方式(方法) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-29 19:08 |只看该作者 |倒序浏览
# -*- coding: cp936 -*-
#shortcut.py

import os

import pythoncom
from win32com.shell import shell
from win32com.shell import shellcon

def GetpathFromLink(lnkpath):
    shortcut = pythoncom.CoCreateInstance(
        shell.CLSID_ShellLink, None,
        pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
    shortcut.QueryInterface( pythoncom.IID_IPersistFile ).Load(lnkpath)
    path = shortcut.GetPath(shell.SLGP_SHORTPATH)[0]

    return path

def CreateLnkpath(filename,lnkname):
    shortcut = pythoncom.CoCreateInstance(
        shell.CLSID_ShellLink, None,
        pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
    shortcut.SetPath(filename)
    if os.path.splitext(lnkname)[-1] != '.lnk':
        lnkname += ".lnk"
    shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(lnkname,0)

def GetURLFromShortcut(url):
    shortcut = pythoncom.CoCreateInstance(
        shell.CLSID_InternetShortcut,None,
        pythoncom.CLSCTX_INPROC_SERVER,shell.IID_IUniformResourceLocator)
    shortcut.QueryInterface(pythoncom.IID_IPersistFile).Load(url)
    url = shortcut.GetURL()

    return url

def CreateURLShortcut(url,name):
    shortcut = pythoncom.CoCreateInstance(
        shell.CLSID_InternetShortcut,None,
        pythoncom.CLSCTX_INPROC_SERVER,shell.IID_IUniformResourceLocator)
    shortcut.SetURL(url)
    if os.path.splitext(name)[-1] != '.url':
        name += '.url'
    shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(name,0)

def GetDesktoppath():
    ilist = shell.SHGetSpecialFolderLocation(0,shellcon.CSIDL_DESKTOP)
    dtpath = shell.SHGetPathFromIDList(ilist)

    #dtpath = dtpath.decode('gbk')

    return dtpath

论坛徽章:
0
2 [报告]
发表于 2009-09-30 09:01 |只看该作者
感谢分享,霍霍。win32下面不少好东东

论坛徽章:
0
3 [报告]
发表于 2009-10-05 12:46 |只看该作者
这个好好学学
哪里能找到pythonwin的书呢?扫盲的最好,呵呵

论坛徽章:
0
4 [报告]
发表于 2009-10-05 16:46 |只看该作者
原帖由 ermu 于 2009-10-5 12:46 发表
这个好好学学
哪里能找到pythonwin的书呢?扫盲的最好,呵呵


python的书还分 pythonwin和pythonlinux吗?

论坛徽章:
0
5 [报告]
发表于 2009-10-05 18:10 |只看该作者
看下pythonwin应该不错

论坛徽章:
0
6 [报告]
发表于 2009-10-05 20:46 |只看该作者
学习了!

论坛徽章:
0
7 [报告]
发表于 2009-10-06 01:40 |只看该作者
pythonwin是python对win32的扩展库

论坛徽章:
0
8 [报告]
发表于 2009-10-07 13:04 |只看该作者
原帖由 ermu 于 2009-10-5 12:46 发表
这个好好学学
哪里能找到pythonwin的书呢?扫盲的最好,呵呵


pythonwin如果懂mfc使用起来不是很困难,如果不懂mfc,学习起来比mfc简单,看mfc的代码,就能学着使用pythonwin下的函数。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP