PyNETRESOURCE::~PyNETRESOURCE(void) { PyWinObject_FreeTCHAR(m_nr.lpProvider); PyWinObject_FreeTCHAR(m_nr.lpRemoteName); PyWinObject_FreeTCHAR(m_nr.lpLocalName); PyWinObject_FreeTCHAR(m_nr.lpComment); }
// @pymethod |PyCToolTipCtrl|UpdateTipText|Update the tool tip text for a control's tools static PyObject * PyCToolTipCtrl_update_tip_text(PyObject *self, PyObject *args) { PyObject *obWnd; TCHAR *pszText; PyObject *obText; UINT nIDTool; if (!PyArg_ParseTuple(args, "OOi:UpdateTipText", &obText,// @pyparm string|text||The text for the tool. &obWnd, // @pyparm <o PyCWnd>|wnd||The window of the tool. &nIDTool// @pyparm int|id||The id of the tool )) return NULL; CWnd *pWndToolOwner = NULL; if (obWnd != Py_None) { if (!ui_base_class::is_uiobject(obWnd,&PyCWnd::type)) RETURN_TYPE_ERR("wnd argument must be a window object"); pWndToolOwner = GetWndPtr(obWnd); if (pWndToolOwner==NULL) RETURN_TYPE_ERR("The window is not a valid PyCWnd"); } CToolTipCtrl *pTTC = GetToolTipCtrl(self); if (!pTTC)return NULL; if (!PyWinObject_AsTCHAR(obText, &pszText, FALSE)) return NULL; GUI_BGN_SAVE; pTTC->UpdateTipText(pszText,pWndToolOwner,nIDTool); GUI_END_SAVE; PyWinObject_FreeTCHAR(pszText); RETURN_NONE; }
// @pymethod |PyCMenu|ModifyMenu|Modify an item in a menu. PyObject *PyCMenu::ModifyMenu(PyObject *self, PyObject *args) { HMENU hMenu = GetMenu( self ); if (!hMenu) return NULL; TCHAR *value = NULL; PyObject *obvalue=Py_None; int id=0; int flags; int pos; if (!PyArg_ParseTuple(args,"ii|iO", &pos, // @pyparm int|pos||The position (zero-based) the item to be changed. &flags, // @pyparm int|flags||Flags for the item. &id, // @pyparm int|id|0|The ID for the item. &obvalue)) // @pyparm string/None|value|None|A string for the menu item. { return NULL; } if (!PyWinObject_AsTCHAR(obvalue, &value, TRUE)) return NULL; BOOL rc=::ModifyMenu( hMenu, pos, flags, id, value); PyWinObject_FreeTCHAR(value); if (!rc) RETURN_API_ERR("::ModifyMenu"); RETURN_NONE; }
// @pymethod <o PyDEVMODE>|win32api|EnumDisplaySettingsEx|Lists available modes for a display device, with optional flags // @comm Accepts keyword arguments PyObject *PyEnumDisplaySettingsEx(PyObject *self, PyObject *args, PyObject *kwargs) { CHECK_PFN(EnumDisplaySettingsEx); static char *keywords[]={"DeviceName","ModeNum","Flags", NULL}; TCHAR *DeviceName=NULL; PyObject *obDeviceName=Py_None, *ret=NULL; DWORD ModeNum=0; DEVMODE devmode; DWORD Flags=0; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Okk:EnumDisplaySettingsEx", keywords, &obDeviceName, // @pyparm string|DeviceName|None|Name of device as returned by <om win32api.EnumDisplayDevices>. Can be None for default display &ModeNum, // @pyparm int|ModeNum||Index of setting to return, or one of ENUM_CURRENT_SETTINGS, ENUM_REGISTRY_SETTINGS &Flags)) // @pyparm int|Flags|0|EDS_RAWMODE (2) is only defined flag return NULL; if (!PyWinObject_AsTCHAR(obDeviceName, &DeviceName, TRUE)) return NULL; ZeroMemory(&devmode,sizeof(DEVMODE)); devmode.dmSize=sizeof(DEVMODE); if (!(*pfnEnumDisplaySettingsEx)(DeviceName, ModeNum, &devmode, Flags)) PyWin_SetAPIError("EnumDisplaySettingsEx"); else ret = PyWinObject_FromDEVMODE(&devmode); PyWinObject_FreeTCHAR(DeviceName); return ret; }
// @pymethod |PyIShellLink|SetIconLocation|Sets the location (path and index) of the icon for a shell link object. PyObject *PyIShellLink::SetIconLocation(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); if ( pISL == NULL ) return NULL; PyObject *obIconPath; // @pyparm string|iconPath||Path to the file with the icon. // @pyparm int|iIcon||Index of the icon. int iIcon; if ( !PyArg_ParseTuple(args, "Oi:SetIconLocation", &obIconPath, &iIcon) ) return NULL; TCHAR *pszIconPath; if (!PyWinObject_AsTCHAR(obIconPath, &pszIconPath)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISL->SetIconLocation( pszIconPath, iIcon ); PY_INTERFACE_POSTCALL; PyWinObject_FreeTCHAR(pszIconPath); if ( FAILED(hr) ) return OleSetOleError(hr); Py_INCREF(Py_None); return Py_None; }
// @pymethod |win32wnet|WNetCancelConnection2|Closes network connections made by WNetAddConnection2 or 3 static PyObject * PyWNetCancelConnection2 (PyObject *self, PyObject *args) { LPTSTR lpName; // @pyparm string|name||Name of existing connection to be closed DWORD dwFlags; // @pyparm int|flags||Currently determines if the persisent connection information will be updated as a result of this call. DWORD bForce; // @pyparm int|force||indicates if the close operation should be forced. (i.e. ignore open files and connections) DWORD ErrorNo; PyObject *obName; if(!PyArg_ParseTuple(args, "Okk", &obName, &dwFlags, &bForce)) return NULL; if (!PyWinObject_AsTCHAR(obName, &lpName, FALSE)) return NULL; Py_BEGIN_ALLOW_THREADS ErrorNo = WNetCancelConnection2(lpName, dwFlags, (BOOL)bForce); Py_END_ALLOW_THREADS PyWinObject_FreeTCHAR(lpName); if (ErrorNo != NO_ERROR) { return ReturnNetError("WNetCancelConnection2", ErrorNo); } Py_INCREF(Py_None); return Py_None; };
static PyObject * py_register_clipboard_format(PyObject* self, PyObject* args) { TCHAR *name; PyObject *obname; if (!PyArg_ParseTuple(args, "O:RegisterClipboardFormat", &obname)) // @pyparm string|name||String that names the new format. return NULL; if (!PyWinObject_AsTCHAR(obname, &name, FALSE)) return NULL; UINT rc; Py_BEGIN_ALLOW_THREADS; rc = RegisterClipboardFormat(name); Py_END_ALLOW_THREADS; PyWinObject_FreeTCHAR(name); if (!rc) return ReturnAPIError("RegisterClipboardFormat"); return PyInt_FromLong(rc); // @comm If a registered format with the specified name already exists, a // new format is not registered and the return value identifies the existing // format. This enables more than one application to copy and paste data // using the same registered clipboard format. Note that the format name // comparison is case-insensitive.<nl> // Registered clipboard formats are identified by values in the range 0xC000 // through 0xFFFF. // @pyseeapi RegisterClipboardFormat // @rdesc If the function succeeds, the return value identifies the // registered clipboard format. // If the function fails, win32api.error is raised with the GetLastError // info. }
// @pymethod |PyIShellLink|SetRelativePath|Sets the relative path for a shell link object. PyObject *PyIShellLink::SetRelativePath(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); if ( pISL == NULL ) return NULL; PyObject *obPathRel; // @pyparm string|relPath||The relative path. // @pyparm int|reserved|0|Reserved - must be zero. DWORD dwReserved = 0; if ( !PyArg_ParseTuple(args, "O|l:SetRelativePath", &obPathRel, &dwReserved) ) return NULL; TCHAR *pszPathRel; if (!PyWinObject_AsTCHAR(obPathRel, &pszPathRel)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISL->SetRelativePath( pszPathRel, dwReserved ); PY_INTERFACE_POSTCALL; PyWinObject_FreeTCHAR(pszPathRel); if ( FAILED(hr) ) return OleSetOleError(hr); Py_INCREF(Py_None); return Py_None; // @comm This mechanism allows for moved link files // to reestablish connection with relative files through // similar-prefix comparisons }
// @pymethod |PyCWinApp|OpenDocumentFile|Opens a document file by name. static PyObject * ui_open_document_file(PyObject *self, PyObject *args) { TCHAR *fileName; PyObject *obfileName; if (!PyArg_ParseTuple(args, "O:OpenDocumentFile", &obfileName )) // @pyparm string|fileName||The name of the document to open. return NULL; if (!PyWinObject_AsTCHAR(obfileName, &fileName)) return NULL; CWinApp *pApp = GetApp(); if (!pApp) return NULL; if (((CProtectedWinApp *)pApp)->GetMainFrame()->GetSafeHwnd()==0) RETURN_ERR("There is no main frame in which to create the document"); GUI_BGN_SAVE; CDocument *pDoc = pApp->OpenDocumentFile(fileName); GUI_END_SAVE; PyWinObject_FreeTCHAR(fileName); if (PyErr_Occurred()) return NULL; if (pDoc==NULL) RETURN_NONE; return ui_assoc_object::make(PyCDocument::type, pDoc)->GetGoodRet(); }
// @pymethod <o PyDISPLAY_DEVICE>|win32api|EnumDisplayDevices|Obtain information about the display devices in a system // @comm Accepts keyword arguments PyObject *PyEnumDisplayDevices(PyObject *self, PyObject *args, PyObject *kwargs) { CHECK_PFN(EnumDisplayDevices); static char *keywords[]={"Device", "DevNum", "Flags", NULL}; TCHAR *Device=NULL; PyObject *obDevice = Py_None, *ret=NULL; DWORD DevNum=0; DWORD Flags=0; DISPLAY_DEVICE display_device; // @pyparm string|Device|None|Name of device, use None to obtain information for the display adapter(s) on the machine, based on DevNum // @pyparm int|DevNum|0|Index of device of interest, starting with zero // @pyparm int|Flags|0|Reserved, use 0 if passed in if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Okk:EnumDisplayDevices", keywords, &obDevice, &DevNum, &Flags)) return NULL; if (!PyWinObject_AsTCHAR(obDevice, &Device, TRUE)) return NULL; ZeroMemory(&display_device,sizeof(DISPLAY_DEVICE)); display_device.cb=sizeof(DISPLAY_DEVICE); if (!(*pfnEnumDisplayDevices)(Device, DevNum, &display_device, Flags)) PyWin_SetAPIError("EnumDisplayDevices"); else ret = PyWinObject_FromDISPLAY_DEVICE(&display_device); PyWinObject_FreeTCHAR(Device); return ret; }
// @pymethod int|win32api|ChangeDisplaySettingsEx|Changes video mode for specified display // @rdesc Returns DISP_CHANGE_SUCCESSFUL on success, or one of the DISP_CHANGE_* error constants on failure // @comm Accepts keyword arguments PyObject *PyChangeDisplaySettingsEx(PyObject *self, PyObject *args, PyObject *kwargs) { // for now there's no hwnd param parsing (required to be NULL anyway), and no lParam CHECK_PFN(ChangeDisplaySettingsEx); static char *keywords[]={"DeviceName","DevMode","Flags", NULL}; DWORD Flags=0; TCHAR *DeviceName=NULL; PDEVMODE pdevmode; PyObject *obDeviceName=Py_None, *obdevmode=Py_None; long ret; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOk:ChangeDisplaySettingsEx", keywords, &obDeviceName, // @pyparm str|DeviceName|None|Name of device as returned by <om win32api.EnumDisplayDevices>, use None for default display device &obdevmode, // @pyparm <o PyDEVMODE>|DevMode|None|A PyDEVMODE object as returned from <om win32api.EnumDisplaySettings>, or None to reset to default settings from registry &Flags)) // @pyparm int|Flags|0|One of the win32con.CDS_* constants, or 0 return NULL; if (!PyWinObject_AsDEVMODE(obdevmode, &pdevmode, TRUE)) return NULL; if (!PyWinObject_AsTCHAR(obDeviceName, &DeviceName, TRUE)) return NULL; // DISP_CHANGE_* errors don't translate as win32 error codes, just return it ret=(*pfnChangeDisplaySettingsEx)(DeviceName, pdevmode, (HWND) NULL, Flags, (LPVOID) NULL); PyWinObject_FreeTCHAR(DeviceName); return PyLong_FromLong(ret); }
// @pymethod |PyCDocument|DoSave|Calls the underlying MFC DoSave method. PyObject * ui_doc_do_save(PyObject *self, PyObject *args) { // @comm If invalid or no filename, will prompt for a name, else // will perform the actual saving of the document. TCHAR *fileName; PyObject *obfileName; int bReplace = TRUE; if (!PyArg_ParseTuple(args,"O|i", &obfileName, // @pyparm string|fileName||The name of the file to save to. &bReplace)) // @pyparm int|bReplace|1|Should an existing file be silently replaced?. return NULL; CDocument *pDoc; if (!(pDoc=PyCDocument::GetDoc(self))) return NULL; if (!PyWinObject_AsTCHAR(obfileName, &fileName, FALSE)) return NULL; // @xref <vm PyCDocument.DoSave> GUI_BGN_SAVE; BOOL rc = pDoc->CDocument::DoSave(fileName, bReplace); // @pyundocmfc CDocument|DoSave GUI_END_SAVE; PyWinObject_FreeTCHAR(fileName); if (rc==FALSE) RETURN_ERR("DoSave failed"); RETURN_NONE; }
// @pymethod int|PyCTreeCtrl|SetItemText|Changes the text of a list view item or subitem. PyObject *PyCTreeCtrl_SetItemText( PyObject *self, PyObject *args ) { CTreeCtrl *pList = GetTreeCtrl(self); if (!pList) return NULL; PyObject *obItem; TCHAR *text; PyObject *obtext; if (!PyArg_ParseTuple( args, "OO:SetItemText", &obItem, // @pyparm HTREEITEM|item||The item whose text is to be retrieved. &obtext)) // @pyparm string|text||String that contains the new item text. return NULL; HTREEITEM item; if (!PyWinObject_AsHANDLE(obItem, (HANDLE *)&item)) return NULL; if (!PyWinObject_AsTCHAR(obtext, &text, FALSE)) return NULL; GUI_BGN_SAVE; BOOL ok = pList->SetItemText(item, text); GUI_END_SAVE; PyWinObject_FreeTCHAR(text); if (!ok) RETURN_ERR("SetItemText failed"); RETURN_NONE; }
// @pymethod |win32wnet|WNetAddConnection3|Creates a connection to a network resource. // @comm Accepts keyword arguments. // @pyseeapi WNetAddConnection3 static PyObject *PyWNetAddConnection3 (PyObject *self, PyObject *args, PyObject *kwargs) { LPTSTR Username = NULL; LPTSTR Password = NULL; DWORD ErrorNo; // holds the returned error number, if any DWORD flags = 0; NETRESOURCE *pNetResource; PyObject *obPassword=Py_None, *obUsername=Py_None, *ret=NULL; PyObject *obhwnd, *obnr; static char *keywords[] = {"HwndOwner", "NetResource","Password","UserName","Flags", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|OOk", keywords, &obhwnd, // @pyparm int|hwnd||Handle to a parent window. &obnr, // @pyparm <o PyNETRESOURCE>|NetResource||Describes the network resource for the connection. &obPassword, // @pyparm str|Password|None|The password to use. Use None for default credentials. &obUsername, // @pyparm str|UserName|None|The user name to connect as. Use None for default credentials. &flags)) // @pyparm int|Flags|0|Combination win32netcon.CONNECT_* flags return NULL; HWND hwnd; if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd)) return NULL; if (!PyWinObject_AsNETRESOURCE(obnr, &pNetResource, FALSE)) return NULL; if (!PyWinObject_AsTCHAR(obPassword, &Password, TRUE) || !PyWinObject_AsTCHAR(obUsername, &Username, TRUE)) goto done; Py_BEGIN_ALLOW_THREADS ErrorNo = WNetAddConnection3(hwnd, pNetResource, Password, Username, flags); Py_END_ALLOW_THREADS if (ErrorNo != NO_ERROR) ReturnNetError("WNetAddConnection3", ErrorNo); else{ Py_INCREF(Py_None); ret = Py_None; } done: PyWinObject_FreeTCHAR(Password); PyWinObject_FreeTCHAR(Username); return ret; };
int PyNETRESOURCE::setattro(PyObject *self, PyObject *obname, PyObject *v) { if (v == NULL) { PyErr_SetString(PyExc_AttributeError, "can't delete NETRESOURCE attributes"); return -1; } char *name=PYWIN_ATTR_CONVERT(obname); if (name==NULL) return NULL; PyNETRESOURCE *This = (PyNETRESOURCE *)self; TCHAR *value; if (strcmp(name, "lpProvider")==0){ if (!PyWinObject_AsTCHAR(v, &value, TRUE)) return -1; PyWinObject_FreeTCHAR(This->m_nr.lpProvider); This->m_nr.lpProvider=value; return 0; } if (strcmp(name, "lpRemoteName")==0){ if (!PyWinObject_AsTCHAR(v, &value, TRUE)) return -1; PyWinObject_FreeTCHAR(This->m_nr.lpRemoteName); This->m_nr.lpRemoteName=value; return 0; } if (strcmp(name, "lpLocalName")==0){ if (!PyWinObject_AsTCHAR(v, &value, TRUE)) return -1; PyWinObject_FreeTCHAR(This->m_nr.lpLocalName); This->m_nr.lpLocalName=value; return 0; } if (strcmp(name, "lpComment")==0){ if (!PyWinObject_AsTCHAR(v, &value, TRUE)) return -1; PyWinObject_FreeTCHAR(This->m_nr.lpComment); This->m_nr.lpComment=value; return 0; } return PyObject_GenericSetAttr(self, obname, v); }
static void mmapfile_object_dealloc(mmapfile_object * m_obj) { if (m_obj->data != NULL) UnmapViewOfFile (m_obj->data); if (m_obj->map_handle != NULL) CloseHandle (m_obj->map_handle); if (m_obj->file_handle!=INVALID_HANDLE_VALUE) CloseHandle (m_obj->file_handle); PyWinObject_FreeTCHAR(m_obj->tagname); PyObject_Del(m_obj); }
// @pymethod int|PyCListCtrl|InsertItem|Inserts an item into the list. PyObject *PyCListCtrl_InsertItem( PyObject *self, PyObject *args ) { CListCtrl *pList; int ret; int item; TCHAR *text=NULL; int image; PyObject *obLVItem, *obtext; if (!(pList=GetListCtrl(self))) return NULL; if (PyArg_ParseTuple(args, "iOi:InsertItem", &item, // @pyparmalt1 int|item||The index of the item. &obtext, // @pyparmalt1 string|text||The text of the item. &image) // @pyparmalt1 int|image||The index of the image to use. && PyWinObject_AsTCHAR(obtext, &text, FALSE)){ GUI_BGN_SAVE; ret = pList->InsertItem(item, text, image ); GUI_END_SAVE; } else { PyErr_Clear(); if (PyArg_ParseTuple(args, "iO:InsertItem", &item, // @pyparmalt2 int|item||The index of the item. &obtext) // @pyparmalt2 string|text||The text of the item. && PyWinObject_AsTCHAR(obtext, &text, FALSE)){ GUI_BGN_SAVE; ret = pList->InsertItem(item, text ); GUI_END_SAVE; } else { PyErr_Clear(); if (PyArg_ParseTuple(args, "O:InsertItem", &obLVItem)) { // @pyparm <o LV_ITEM>|item||A tuple describing the new item. LV_ITEM lvItem; if (!PyWinObject_AsLV_ITEM(obLVItem, &lvItem)) return NULL; GUI_BGN_SAVE; ret = pList->InsertItem(&lvItem); GUI_END_SAVE; PyWinObject_FreeLV_ITEM(&lvItem); } else { PyErr_Clear(); RETURN_ERR("InsertItem requires (item, text, image), (item, text), or (itemObject)"); } } } PyWinObject_FreeTCHAR(text); if (ret==-1) RETURN_ERR("InsertItem failed"); return PyInt_FromLong(ret); }
PyObject *PyDDE_CreateTopic(PyObject *s, PyObject *args) { TCHAR *name; PyObject *obname; if (!PyArg_ParseTuple(args,"O:CreateTopic", &obname)) return NULL; if (!PyWinObject_AsTCHAR(obname, &name, FALSE)) return NULL; GUI_BGN_SAVE; PythonDDETopic *pNew = new PythonDDETopic; pNew->Create(name); GUI_END_SAVE; PyWinObject_FreeTCHAR(name); return ui_assoc_object::make(PyDDETopic::type, pNew); }
// @pymethod |PyCToolTipCtrl|AddTool|Adds a tool to tooltip control. static PyObject * PyCToolTipCtrl_add_tool(PyObject *self, PyObject *args) { PyObject *obWnd,*obRect; TCHAR *pszText; PyObject *obText; UINT nIDTool; if (!PyArg_ParseTuple(args, "OOOi:CreateWindow", &obWnd, // @pyparm <o PyCWnd>|wnd||The window of the tool. &obText,// @pyparm string|text||The text for the tool. &obRect, // @pyparm int, int, int, int|rect|None|The default rectangle &nIDTool// @pyparm int|id||The id of the tool )) return NULL; CWnd *pWnd = NULL; if (obWnd != Py_None) { if (!ui_base_class::is_uiobject(obWnd,&PyCWnd::type)) RETURN_TYPE_ERR("wnd argument must be a window object"); pWnd = GetWndPtr(obWnd); if (pWnd==NULL) RETURN_TYPE_ERR("The window is not a valid PyCWnd"); } RECT rect; RECT *pRectTool=NULL; if (obRect != Py_None) { if (!PyArg_ParseTuple(obRect, "iiii", &rect.left, &rect.top, &rect.right,&rect.bottom)) { PyErr_Clear(); RETURN_TYPE_ERR("Rect must be None or a tuple of (iiii)"); } pRectTool=▭ } CToolTipCtrl *pTTC = GetToolTipCtrl(self); if (!pTTC)return NULL; if (!PyWinObject_AsTCHAR(obText, &pszText, FALSE)) return NULL; GUI_BGN_SAVE; BOOL ok=pTTC->AddTool(pWnd,pszText,pRectTool,nIDTool); GUI_END_SAVE; PyWinObject_FreeTCHAR(pszText); if (!ok) RETURN_ERR("CToolTipCtrl::AddTool"); RETURN_NONE; }
// Menu Methods // @pymethod |PyCMenu|AppendMenu|Appends a new item to the end of a menu. Python can specify the state of the menu item by setting values in nFlags. PyObject *PyCMenu::AppendMenu(PyObject *self, PyObject *args) { HMENU hMenu = GetMenu( self ); if (!hMenu) return NULL; TCHAR *value = NULL; PyObject *obvalue=Py_None; int id=0; int flags; if (!PyArg_ParseTuple(args,"i|iO", &flags, // @pyparm int|flags||Specifies information about the state of the new menu item when it is added to the menu. May be a combination of the win32con.MF_* values. &id, // @pyparm int|id|0|Specifies either the command ID of the new menu item. &obvalue)) // @pyparm string/None|value|None|Specifies the content of the new menu item. If used, flags must contain win32con.MF_STRING. return NULL; if (!PyWinObject_AsTCHAR(obvalue, &value, TRUE)) return NULL; if (!::AppendMenu( hMenu, flags, id, value)){ PyWinObject_FreeTCHAR(value); RETURN_API_ERR("::AppendMenu"); } PyWinObject_FreeTCHAR(value); RETURN_NONE; }
// @pymethod |PyCEdit|ReplaceSel|Replaces the selection with the specified text. static PyObject *PyCEdit_replace_sel(PyObject *self, PyObject *args) { CEdit *pEdit = GetEditCtrl(self); TCHAR *msg; PyObject *obmsg; // @pyparm string|text||The text to replace the selection with. if (!pEdit || !PyArg_ParseTuple(args, "O:ReplaceSel", &obmsg) || !PyWinObject_AsTCHAR(obmsg, &msg, FALSE)) return NULL; GUI_BGN_SAVE; pEdit->ReplaceSel(msg); // @pyseemfc CEdit|ReplaceSel GUI_END_SAVE; PyWinObject_FreeTCHAR(msg); RETURN_NONE; }
// @pymethod |PyCPropertySheet|SetTitle|Sets the caption for the property sheet. PyObject *ui_propsheet_set_title( PyObject *self, PyObject *args ) { TCHAR *caption; PyObject *obcaption; // @pyparm string|title||The new caption if (!PyArg_ParseTuple(args, "O:SetTitle", &obcaption)) return NULL; CPythonPropertySheet *pPS = GetPythonPropSheet(self); if (!pPS) return NULL; if (!PyWinObject_AsTCHAR(obcaption, &caption, FALSE)) return NULL; GUI_BGN_SAVE; pPS->SetTitle(caption); GUI_END_SAVE; PyWinObject_FreeTCHAR(caption); RETURN_NONE; }
// @pymethod string|win32lz|GetExpandedName|Retrieves the original name of an expanded file, static PyObject * PyGetExpandedName(PyObject *self, PyObject *args) { TCHAR outName[_MAX_PATH+1]; TCHAR *nameIn; PyObject *obnameIn; if (!PyArg_ParseTuple(args, "O:GetExpandedName", &obnameIn )) // @pyparm str|Source||Name of a compressed file return NULL; if (!PyWinObject_AsTCHAR(obnameIn, &nameIn, FALSE)) return NULL; // @pyseeapi GetExpandedName int ret = GetExpandedName(nameIn, outName); PyWinObject_FreeTCHAR(nameIn); if (ret!=1) return ReturnLZError("GetExpandedName", ret); return PyWinObject_FromTCHAR(outName); }
// @pymethod |PyDDEStringItem|SetData|Sets an items data, and causes any underlying notification. PyObject *PyDDEStringItem_SetData(PyObject *self, PyObject *args) { TCHAR *val; PyObject *obval; PythonDDEStringItem *pItem = PyDDEStringItem::GetItem(self); if (!pItem) return NULL; // @pyparm string|data||The data to set. if (!PyArg_ParseTuple(args, "O:SetData", &obval)) return NULL; if (!PyWinObject_AsTCHAR(obval, &val, FALSE)) return NULL; GUI_BGN_SAVE; pItem->SetData(val); GUI_END_SAVE; PyWinObject_FreeTCHAR(val); RETURN_NONE; }
// @pymethod |PyCPropertySheet|SetFinishText|Sets the text for the Finish button PyObject *ui_propsheet_set_finish_text( PyObject *self, PyObject *args ) { CPropertySheet *pPS = pPS=GetPropSheet(self); if (!pPS) return NULL; TCHAR *text; PyObject *obtext; // @pyparm string|text||The next for the button if (!PyArg_ParseTuple( args, "O", &obtext)) return NULL; if (!PyWinObject_AsTCHAR(obtext, &text, FALSE)) return NULL; GUI_BGN_SAVE; pPS->SetFinishText(text); GUI_END_SAVE; PyWinObject_FreeTCHAR(text); RETURN_NONE; }
// @pymethod string|win32wnet|WNetGetUser|Retrieves the current default user name, or the user name used to establish a network connection. static PyObject * PyWNetGetUser(PyObject *self, PyObject *args) { PyObject *ret = NULL; PyObject *obConnection = Py_None; DWORD length = 0; DWORD errcode; TCHAR *szConnection = NULL; TCHAR *buf = NULL; // @pyparm string|connection|None|A string that specifies either the name of a local device that has been redirected to a network resource, or the remote name of a network resource to which a connection has been made without redirecting a local device. // If this parameter is None, the system returns the name of the current user for the process. if (!PyArg_ParseTuple(args, "|O", &obConnection)) return NULL; if (!PyWinObject_AsTCHAR(obConnection, &szConnection, TRUE)) goto done; // get the buffer size { Py_BEGIN_ALLOW_THREADS errcode=WNetGetUser(szConnection, NULL, &length); Py_END_ALLOW_THREADS } if (length==0) { ReturnNetError("WNetGetUser", errcode); goto done; } buf = (TCHAR *)malloc( sizeof( TCHAR) * length); if (buf == NULL){ PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", sizeof(TCHAR)*length); goto done; } Py_BEGIN_ALLOW_THREADS errcode = WNetGetUser(szConnection, buf, &length); Py_END_ALLOW_THREADS if (0 != errcode) { ReturnNetError("WNetGetUser", errcode); goto done; } // length includes the NULL - drop it (safely!) ret = PyWinObject_FromTCHAR(buf, (length > 0) ? length-1 : 0); done: PyWinObject_FreeTCHAR(szConnection); if (buf) free(buf); return ret; }
// @pymethod string|win32wnet|WNetGetConnection|Retrieves the name of the network resource associated with a local device. static PyObject * PyWNetGetConnection(PyObject *self, PyObject *args) { PyObject *ret = NULL; PyObject *obConnection = Py_None; DWORD length = 0; DWORD errcode; TCHAR *szConnection = NULL; TCHAR *buf = NULL; // @pyparm string|connection|None|A string that is a drive-based path for a network resource. // For example, if drive H has been mapped to a network drive share, and the network resource of interest is a file named Sample.doc in the directory \Win32\Examples on that share, the drive-based path is H:\Win32\Examples\Sample.doc. if (!PyArg_ParseTuple(args, "|O", &obConnection)) return NULL; if (!PyWinObject_AsTCHAR(obConnection, &szConnection, TRUE)) goto done; // get the buffer size { Py_BEGIN_ALLOW_THREADS errcode=WNetGetConnection(szConnection, NULL, &length); Py_END_ALLOW_THREADS } if (length==0) { ReturnNetError("WNetGetConnection", errcode); goto done; } buf = (TCHAR *)malloc( sizeof( TCHAR) * length); if (buf == NULL){ PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", sizeof(TCHAR)*length); goto done; } Py_BEGIN_ALLOW_THREADS errcode = WNetGetConnection(szConnection, buf, &length); Py_END_ALLOW_THREADS if (0 != errcode) { ReturnNetError("WNetGetConnection", errcode); goto done; } // length includes the NULL - drop it (safely!) ret = PyWinObject_FromTCHAR(buf, (length > 0) ? length-1 : 0); done: PyWinObject_FreeTCHAR(szConnection); if (buf) free(buf); return ret; }
// @pymethod |PyCDocument|SetTitle|Set the title of the document (ie, the name // to appear in the window caption for the document. static PyObject * ui_doc_set_title(PyObject *self, PyObject *args) { TCHAR *title; PyObject *obtitle; if (!PyArg_ParseTuple(args, "O", &obtitle)) // @pyparm string|title||The new title. return NULL; if (!PyWinObject_AsTCHAR(obtitle, &title, FALSE)) return NULL; CDocument *pDoc; if (!(pDoc=PyCDocument::GetDoc(self))) return NULL; GUI_BGN_SAVE; pDoc->SetTitle(title); // @pyseemfc CDocument|SetTitle GUI_END_SAVE; PyWinObject_FreeTCHAR(title); RETURN_NONE; }
// @pymethod int|PyCListCtrl|GetStringWidth|Gets the necessary column width to fully display this text in a column. PyObject *PyCListCtrl_GetStringWidth( PyObject *self, PyObject *args ) { TCHAR *text; PyObject *obtext; if (!PyArg_ParseTuple( args, "O:GetStringWidth", &obtext)) // @pyparm int|first||String that contains the text whose width is to be determined. return NULL; CListCtrl *pList = GetListCtrl(self); if (!pList) return NULL; if (!PyWinObject_AsTCHAR(obtext, &text, FALSE)) return NULL; GUI_BGN_SAVE; int width = pList->GetStringWidth(text); GUI_END_SAVE; PyWinObject_FreeTCHAR(text); return Py_BuildValue("i", width); // @comm Doesn't take the size of an included Image in account, only the size of the text is determined. }
BOOL CVirtualHelper::retval( CString &ret ) { ASSERT(retVal); if (!retVal) return FALSE; // failed - assume didnt work in non debug if (retVal==Py_None) { ret.Empty(); return TRUE; } CEnterLeavePython _celp; TCHAR *tchar_val; if (!PyWinObject_AsTCHAR(retVal, &tchar_val, FALSE)){ gui_print_error(); return FALSE; } ret = tchar_val; PyWinObject_FreeTCHAR(tchar_val); return TRUE; }