// @pymethod |PyIExtractIcon|Extract|Description of Extract. PyObject *PyIExtractIcon::Extract(PyObject *self, PyObject *args) { IExtractIconA *pIEI = GetI(self); if ( pIEI == NULL ) return NULL; // @pyparm <o unicode>|pszFile||Description for pszFile // @pyparm int|nIconIndex||Description for nIconIndex // @pyparm int|nIconSize||Description for nIconIndex HICON hiconLarge; HICON hiconSmall; PyObject *obpszFile; char *pszFile; UINT nIconIndex; UINT nIconSize; if ( !PyArg_ParseTuple(args, "Oii:Extract", &obpszFile, &nIconIndex, &nIconSize) ) return NULL; BOOL bPythonIsHappy = TRUE; if (!PyWinObject_AsString(obpszFile, &pszFile)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIEI->Extract( pszFile, nIconIndex, &hiconLarge, &hiconSmall, nIconSize ); PyWinObject_FreeString(pszFile); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIEI, IID_IExtractIcon ); if (hr==S_FALSE) return Py_BuildValue("OO", Py_None, Py_None); return Py_BuildValue("NN", PyWinLong_FromHANDLE(hiconLarge), PyWinLong_FromHANDLE(hiconSmall)); // @rdesc The result is (hicon_large, hicon_small), or // (None,None) if the underlying function returns S_FALSE, indicating // the calling application should extract it. }
STDMETHODIMP PyGShellBrowser::SetMenuSB( /* [in] */ HMENU hmenuShared, /* [in] */ HOLEMENU holemenuRes, /* [in] */ HWND hwndActiveObject) { PY_GATEWAY_METHOD; HRESULT hr=InvokeViaPolicy("SetMenuSB", NULL, "NNN", PyWinLong_FromHANDLE(hmenuShared), PyWinLong_FromHANDLE(holemenuRes), PyWinLong_FromHANDLE(hwndActiveObject)); return hr; }
// --------------------------------------------------- // // Gateway Implementation STDMETHODIMP_(UINT) PyGCopyHookW::CopyCallback( /* [unique][in] */ HWND hwnd, /* [unique][in] */ UINT wFunc, /* [unique][in] */ UINT wFlags, /* [unique][in] */ LPCWSTR srcFile, /* [unique][in] */ DWORD srcAttribs, /* [unique][in] */ LPCWSTR destFile, /* [unique][in] */ DWORD destAttribs) { PY_GATEWAY_METHOD; PyObject *result; HRESULT hr=InvokeViaPolicy("CopyCallback", &result, "NiiNlNl", PyWinLong_FromHANDLE(hwnd), wFunc, wFlags, PyWinObject_FromWCHAR(srcFile), srcAttribs, PyWinObject_FromWCHAR(destFile), destAttribs); if (FAILED(hr)) return hr; hr = PyInt_AsLong(result); if ((hr==-1) && PyErr_Occurred()) hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("CopyCallBack"); Py_DECREF(result); return hr; }
static PyObject * py_get_open_clipboard_window(PyObject* self, PyObject* args) { CHECK_NO_ARGS2(args, "GetOpenClipboardWindow"); HWND rc; Py_BEGIN_ALLOW_THREADS; rc = GetOpenClipboardWindow(); Py_END_ALLOW_THREADS; if (!rc) return ReturnAPIError("GetOpenClipboardWindow"); return PyWinLong_FromHANDLE(rc); // @comm If an application or dynamic-link library (DLL) specifies a NULL // window handle when calling the OpenClipboard function, the clipboard is // opened but is not associated with a window. In such a case, // GetOpenClipboardWindow returns NULL. // @pyseeapi GetOpenClipboardWindow // @rdesc If the function succeeds, the return value is the handle of the // window that has the clipboard open. // If the function fails, win32api.error is raised with the GetLastError // info. }
static PyObject * py_get_clipboard_owner(PyObject* self, PyObject* args) { CHECK_NO_ARGS2(args, "GetClipboardOwner"); HWND rc; Py_BEGIN_ALLOW_THREADS; rc = GetClipboardOwner(); Py_END_ALLOW_THREADS; if (!rc) return ReturnAPIError("GetClipboardOwner"); return PyWinLong_FromHANDLE(rc); // @comm The clipboard can still contain data even if the clipboard is not // currently owned.<nl> // In general, the clipboard owner is the window that last placed data in // clipboard. The EmptyClipboard function assigns clipboard ownership. // @pyseeapi GetClipboardOwner // @rdesc If the function succeeds, the return value is the handle of the // window that owns the clipboard. // If the function fails, win32api.error is raised with the GetLastError // info. }
STDMETHODIMP PyGShellBrowser::RemoveMenusSB( /* [in] */ HMENU hmenuShared) { PY_GATEWAY_METHOD; HRESULT hr=InvokeViaPolicy("RemoveMenusSB", NULL, "N", PyWinLong_FromHANDLE(hmenuShared)); return hr; }
// @pymethod (int, int)|PyCTreeCtrl|HitTest|Determines which tree view item, if any, is at a specified position. PyObject *PyCTreeCtrl_HitTest( PyObject *self, PyObject *args ) { CTreeCtrl *pList = GetTreeCtrl(self); if (!pList) return NULL; TVHITTESTINFO i; memset(&i, 0, sizeof(i)); // @pyparm point|x,y||The point to test. if (!PyArg_ParseTuple( args, "(ii):HitTest", &i.pt.x, &i.pt.y)) return NULL; GUI_BGN_SAVE; pList->HitTest( &i ); GUI_END_SAVE; return Py_BuildValue("iN", i.flags, PyWinLong_FromHANDLE(i.hItem)); // @rdesc The result is a tuple of (flags, hItem). // flags may be a combination of the following values: // @flagh Value|Description // @flag commctrl.TVHT_ABOVE|Above the client area. // @flag commctrl.TVHT_BELOW|Below the client area. // @flag commctrl.TVHT_NOWHERE|In the client area, but below the last item. // @flag commctrl.TVHT_ONITEM|On the bitmap or label associated with an item. // @flag commctrl.TVHT_ONITEMBUTTON|On the button associated with an item. // @flag commctrl.TVHT_ONITEMICON|On the bitmap associated with an item. // @flag commctrl.TVHT_ONITEMINDENT|In the indentation associated with an item. // @flag commctrl.TVHT_ONITEMLABEL|On the label (string) associated with an item. // @flag commctrl.TVHT_ONITEMRIGHT|In the area to the right of an item. // @flag commctrl.TVHT_ONITEMSTATEICON|On the state icon for a tree view item that is in a user-defined state. // @flag commctrl.TVHT_TOLEFT|To the left of the client area. // @flag commctrl.TVHT_TORIGHT|To the right of the client area. }
// @pymethod |PyCPrintInfo|GetHDC|Identifies a device context or an information context, depending on whether the Flags member specifies the PD_RETURNDC or PC_RETURNIC flag. If neither flag is specified, the value of this member is undefined. If both flags are specified, PD_RETURNDC has priority. // @pyseemfc PRINTDLG|hDC static PyObject *ui_get_hdc(PyObject * self, PyObject * args) { CHECK_NO_ARGS2(args, GetHDC); CPrintInfo *pInfo = ui_prinfo_object::GetPrintInfo(self); if (!pInfo) return NULL; HDC hDC = pInfo->m_pPD->m_pd.hDC; return PyWinLong_FromHANDLE(hDC); }
PyObject *PyWinObject_FromMSG(const MSG *pMsg) { return Py_BuildValue("NiNNi(ii)", PyWinLong_FromHANDLE(pMsg->hwnd), pMsg->message, PyWinObject_FromPARAM(pMsg->wParam), PyWinObject_FromPARAM(pMsg->lParam), pMsg->time, pMsg->pt.x, pMsg->pt.y); }
// @pymethod int|PyCWinApp|LoadIcon|Loads an icon resource. static PyObject * ui_load_icon(PyObject *self, PyObject *args) { int idResource; // @pyparm int|idResource||The ID of the icon to load. if (!PyArg_ParseTuple(args,"i:LoadIcon", &idResource)) return NULL; CWinApp *pApp = GetApp(); if (!pApp) return NULL; return PyWinLong_FromHANDLE(pApp->LoadIcon(idResource)); }
// @pymethod |PyCPrintInfo|GetPrinterDC|A handle to the printer device context if successful; otherwise NULL. If the bPrintSetupOnly parameter of the CPrintDialog constructor was FALSE (indicating that the Print dialog box is displayed), then GetPrinterDC returns a handle to the printer device context. You must call the WindowsDeleteDC function to delete the device context when you are done using it. // @pyseemfc CPrintDialog|GetPrinterDC static PyObject *ui_get_printer_dc(PyObject * self, PyObject * args) { CHECK_NO_ARGS2(args, GetPrinterDC); CPrintInfo *pInfo = ui_prinfo_object::GetPrintInfo(self); if (!pInfo) return NULL; GUI_BGN_SAVE; HDC hDC = pInfo->m_pPD->GetPrinterDC(); GUI_END_SAVE; return PyWinLong_FromHANDLE(hDC); }
// @pymethod int|PyCWinApp|LoadOEMCursor|Loads an OEM cursor. static PyObject *ui_load_oem_cursor(PyObject *self, PyObject *args) { UINT cid; HCURSOR hc; if ( !PyArg_ParseTuple(args, "i:LoadOEMCursor", &cid)) // @pyparm int|cursorId||The ID of the cursor to load. return NULL; hc = GetApp()->LoadOEMCursor(cid); if (hc==0) RETURN_API_ERR("LoadOEMCursor"); return PyWinLong_FromHANDLE(hc); }
STDMETHODIMP PyGShellBrowser::InsertMenusSB( /* [in] */ HMENU hmenuShared, /* [out][in] */ LPOLEMENUGROUPWIDTHS lpMenuWidths) { static const char *method_name = "InsertMenusSB"; PY_GATEWAY_METHOD; PyObject *oblpMenuWidths = PyObject_FromOLEMENUGROUPWIDTHS(lpMenuWidths); if (oblpMenuWidths==NULL) return MAKE_PYCOM_GATEWAY_FAILURE_CODE(method_name); PyObject *result; HRESULT hr=InvokeViaPolicy(method_name, &result, "NO", PyWinLong_FromHANDLE(hmenuShared), oblpMenuWidths); Py_DECREF(oblpMenuWidths); if (FAILED(hr)) return hr; PyObject_AsOLEMENUGROUPWIDTHS(result, lpMenuWidths); Py_DECREF(result); return PyCom_SetCOMErrorFromPyException(GetIID()); }
// @pymethod int|PyCWinApp|LoadStandardCursor|Loads a standard cursor. static PyObject *ui_load_standard_cursor(PyObject *self, PyObject *args) { PyObject *obid; TCHAR *csid; HCURSOR hc; if (!PyArg_ParseTuple(args, "O:LoadStandardCursor", &obid)) // @pyparm <o PyResourceId>|cursorId||The resource ID or name of the cursor to load. return NULL; if (!PyWinObject_AsResourceId(obid, &csid, TRUE)) return NULL; hc = GetApp()->LoadStandardCursor(csid); PyWinObject_FreeResourceId(csid); if (hc==0) RETURN_API_ERR("LoadStandardCursor"); return PyWinLong_FromHANDLE(hc); }
// @pymethod int|PyCWinApp|LoadStandardIcon|Loads an icon resource. static PyObject * ui_load_standard_icon(PyObject *self, PyObject *args) { TCHAR *resName; PyObject *obName; // @pyparm <o PyResourceId>|resourceName||The resource name or id of the standard icon to load. if (!PyArg_ParseTuple(args,"O:LoadStandardIcon", &obName)) return NULL; CWinApp *pApp = GetApp(); if (!pApp) return NULL; if (!PyWinObject_AsResourceId(obName, &resName, FALSE)) return NULL; HICON hicon = pApp->LoadStandardIcon(resName); PyWinObject_FreeResourceId(resName); if (hicon==0) RETURN_API_ERR("LoadStandardIcon"); return PyWinLong_FromHANDLE(hicon); }
// @pymethod |PyIShellBrowser|GetControlWindow|Returns a handle to one of the browser's control elements PyObject *PyIShellBrowser::GetControlWindow(PyObject *self, PyObject *args) { IShellBrowser *pISB = GetI(self); if ( pISB == NULL ) return NULL; // @pyparm int|id||One of shellcon.FCW_* values UINT id; if ( !PyArg_ParseTuple(args, "I:GetControlWindow", &id) ) return NULL; HWND hwnd; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISB->GetControlWindow( id, &hwnd ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISB, IID_IShellBrowser ); return PyWinLong_FromHANDLE(hwnd); }
//***************************************************************************** // // @pymethod <o PyHANDLE>|win32clipboard|SetClipboardViewer|The SetClipboardViewer function // adds the specified window to the chain of clipboard viewers. Clipboard // viewer windows receive a WM_DRAWCLIPBOARD message whenever the content of // the clipboard changes. // @rdesc Returns a handle to the next window in chain, or None if no other viewer exists. static PyObject * py_set_clipboard_viewer(PyObject* self, PyObject* args) { // @pyparm <o PyHANDLE>|hWndNewViewer||Integer handle to the window to be added to // the clipboard chain. HWND hWndNewViewer; PyObject *obhwnd; if (!PyArg_ParseTuple(args, "O:SetClipboardViewer", &obhwnd)) return NULL; if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hWndNewViewer)) return NULL; HWND rc; Py_BEGIN_ALLOW_THREADS; rc = SetClipboardViewer(hWndNewViewer); Py_END_ALLOW_THREADS; // Function can return NULL on success if there is no other viewer if (rc!=NULL) return PyWinLong_FromHANDLE(rc); DWORD e=GetLastError(); if (e) return PyWin_SetAPIError("SetClipboardViewer",e); Py_INCREF(Py_None); return Py_None; // @comm The windows that are part of the clipboard viewer chain, called // clipboard viewer windows, must process the clipboard messages // WM_CHANGECBCHAIN and WM_DRAWCLIPBOARD. Each clipboard viewer window calls // the SendMessage function to pass these messages to the next window in the // clipboard viewer chain.<nl> // A clipboard viewer window must eventually remove itself from the clipboard // viewer chain by calling the ChangeClipboardChain function -- for example, // in response to theWM_DESTROY message. // @pyseeapi SetClipboardViewer // @rdesc If the function succeeds, the return value identifies the next // window in the clipboard viewer chain.<nl> // If an error occurs or there are no other windows in the clipboard viewer // chain, win32api.error is raised with the GetLastError info. }
//***************************************************************************** // // @pymethod int|win32clipboard|GetClipboardDataHandle|Retrieves data from the // clipboard in a specified format, and returns an integer handle to the data. // To get the data bytes, use the <om win32clipboard.GetClipboardData> function. static PyObject * py_get_clipboard_data_handle(PyObject* self, PyObject* args) { // @pyparm int|format|CF_TEXT|Specifies a clipboard format. For a description of // the standard clipboard formats, see Standard Clipboard Formats. int format = CF_TEXT; if (!PyArg_ParseTuple(args, "|i:GetClipboardDataHandle:", &format)) return NULL; if (!IsClipboardFormatAvailable(format)) return PyErr_Format(PyExc_TypeError, "The clipboard format %d is not available", format); HANDLE handle; Py_BEGIN_ALLOW_THREADS; handle = GetClipboardData((UINT)format); Py_END_ALLOW_THREADS; if (!handle) return ReturnAPIError("GetClipboardData"); return PyWinLong_FromHANDLE(handle); }
// @pymethod |PyIProvideTaskPage|GetPage|Return a property sheet page handle for the spedified type (TASKPAGE_TASK,TASKPAGE_SCHEDULE,TASKPAGE_SETTINGS) // @comm There's not yet anything useful that can be done with this handle - return type subject to change PyObject *PyIProvideTaskPage::GetPage(PyObject *self, PyObject *args) { IProvideTaskPage *pIPTP = GetI(self); if ( pIPTP == NULL ) return NULL; TASKPAGE tpType; // @pyparm int|tpType||Type of page to retreive (TASKPAGE_TASK,TASKPAGE_SCHEDULE,TASKPAGE_SETTINGS) // @pyparm bool|PersistChanges||Indicates if changes should be saved automatically HPROPSHEETPAGE phPage; BOOL bPersistChanges; if ( !PyArg_ParseTuple(args, "ii:GetPage", &tpType, &bPersistChanges)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIPTP->GetPage(tpType, bPersistChanges, &phPage); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIPTP, IID_IProvideTaskPage ); return PyWinLong_FromHANDLE(phPage); }
// @pymethod int|PyIShellView|CreateViewWindow|Description of CreateViewWindow. PyObject *PyIShellView::CreateViewWindow(PyObject *self, PyObject *args) { IShellView *pISV = GetI(self); if ( pISV == NULL ) return NULL; // @pyparm <o PyIShellView>|psvPrevious||Description for psvPrevious FOLDERSETTINGS fs; PyObject *obpfs; // @pyparm (int, int)|pfs||Description for pfs // @pyparm <o PyIShellBrowser>|psb||Description for psb RECT rcView; PyObject *obprcView; // @pyparm (int, int, int, int)|prcView||Description for prcView PyObject *obpsvPrevious; PyObject *obpsb; IShellView *psvPrevious; IShellBrowser *psb; if ( !PyArg_ParseTuple(args, "OOOO:CreateViewWindow", &obpsvPrevious, &obpfs, &obpsb, &obprcView) ) return NULL; BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpsvPrevious, IID_IShellView, (void **)&psvPrevious, TRUE /* bNoneOK */)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyObject_AsFOLDERSETTINGS( obpfs, &fs )) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpsb, IID_IShellBrowser, (void **)&psb, TRUE /* bNoneOK */)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyObject_AsRECT( obprcView, &rcView )) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HWND hWnd; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISV->CreateViewWindow( psvPrevious, &fs, psb, &rcView, &hWnd ); if (psvPrevious) psvPrevious->Release(); if (psb) psb->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISV, IID_IShellView ); // @rdesc The result is an integer handle to the new window. return PyWinLong_FromHANDLE(hWnd); }
static PyObject * py_get_clipboard_viewer(PyObject* self, PyObject* args) { CHECK_NO_ARGS2(args, "GetClipboardViewer"); HWND rc; Py_BEGIN_ALLOW_THREADS; rc = GetClipboardViewer(); Py_END_ALLOW_THREADS; if (!rc) return ReturnAPIError("GetClipboardViewer"); return PyWinLong_FromHANDLE(rc); // @pyseeapi GetClipboardViewer // @rdesc If the function succeeds, the return value is the handle of the // first window in the clipboard viewer chain. // If the function fails, win32api.error is raised with the GetLastError // info. }
static PyObject * py_get_clipboard_data(PyObject* self, PyObject* args) { PyObject *ret; // @pyparm int|format|CF_TEXT|Specifies a clipboard format. For a description of // the standard clipboard formats, see Standard Clipboard Formats. // In Unicode builds (ie, python 3k), the default is CF_UNICODETEXT. #ifdef UNICODE int format = CF_UNICODETEXT; #else int format = CF_TEXT; #endif if (!PyArg_ParseTuple(args, "|i:GetClipboardData:", &format)) { return NULL; } if (!IsClipboardFormatAvailable(format)){ PyErr_SetString(PyExc_TypeError, "Specified clipboard format is not available"); return NULL; } HANDLE handle; WCHAR *filename=NULL; PyObject* obfilename = NULL; UINT filecnt=0, fileind=0, filenamesize=0; HDROP hdrop; Py_BEGIN_ALLOW_THREADS; handle = GetClipboardData((UINT)format); Py_END_ALLOW_THREADS; if (!handle) { return ReturnAPIError("GetClipboardData"); } void * cData = NULL; size_t size; DWORD dwordsize; switch (format) { case CF_BITMAP: break; case CF_HDROP: hdrop = (HDROP)GlobalLock(handle); break; case CF_ENHMETAFILE: dwordsize = GetEnhMetaFileBits((HENHMETAFILE)handle, 0, NULL); if (!dwordsize) return ReturnAPIError("GetClipboardData:GetEnhMetafileBits(NULL)"); // allocate a temporary buffer for enhanced metafile cData = malloc(dwordsize); if (cData == NULL) return ReturnAPIError("GetClipboardData:malloc"); // copy enhanced metafile into the temporary buffer if (0 == GetEnhMetaFileBits((HENHMETAFILE)handle, dwordsize, (LPBYTE)cData)) { free(cData); return ReturnAPIError("GetClipboardData:GetEnhMetafileBits"); } size=dwordsize; break; case CF_METAFILEPICT: // @todo CF_METAFILEPICT format returns a pointer to a METAFILEPICT struct which contains the metafile handle, // rather than returning the handle directly. This code currently fails with // error: (6, 'GetClipboardData:GetMetafileBitsEx(NULL)', 'The handle is invalid.') dwordsize = GetMetaFileBitsEx((HMETAFILE)handle, 0, NULL); if (!dwordsize) return ReturnAPIError("GetClipboardData:GetMetafileBitsEx(NULL)"); // allocate a temporary buffer for metafile cData = malloc(dwordsize); if (cData == NULL) return ReturnAPIError("GetClipboardData:malloc"); // copy metafile into the temporary buffer if (0 == GetMetaFileBitsEx((HMETAFILE)handle, dwordsize, cData)) { free(cData); return ReturnAPIError("GetClipboardData:GetMetafileBitsEx"); } size=dwordsize; break; // All other formats simply return the data as a blob. default: cData = GlobalLock(handle); if (!cData) { GlobalUnlock(handle); return ReturnAPIError("GetClipboardData:GlobalLock"); } size = GlobalSize(cData); if (!size) { GlobalUnlock(handle); return ReturnAPIError("GetClipboardData:GlobalSize"); } break; } switch (format) { case CF_BITMAP: ret = PyWinLong_FromHANDLE(handle); break; case CF_HDROP: filecnt = DragQueryFileW(hdrop, 0xFFFFFFFF, NULL, NULL); ret = PyTuple_New(filecnt); if (!ret) return PyErr_NoMemory(); for (fileind=0;fileind<filecnt;fileind++){ filenamesize = DragQueryFileW(hdrop, fileind, NULL, NULL); filename = (WCHAR *)malloc((filenamesize+1)*sizeof(WCHAR)); if (!filename) { Py_DECREF(ret); return PyErr_NoMemory(); } filenamesize = DragQueryFileW(hdrop, fileind, filename, filenamesize+1); obfilename=PyWinObject_FromWCHAR(filename); PyTuple_SetItem(ret,fileind,obfilename); free (filename); } GlobalUnlock(handle); break; case CF_UNICODETEXT: ret = PyUnicode_FromWideChar((wchar_t *)cData, (size / sizeof(wchar_t))-1); GlobalUnlock(handle); break; // For the text formats, strip the null! case CF_TEXT: case CF_OEMTEXT: ret = PyString_FromStringAndSize((char *)cData, size-1); GlobalUnlock(handle); break; default: assert(cData); if (!cData) { ret = Py_None; Py_INCREF(ret); } else ret = PyString_FromStringAndSize((char *)cData, size); GlobalUnlock(handle); break; } return ret; // @comm An application can enumerate the available formats in advance by // using the EnumClipboardFormats function.<nl> // The clipboard controls the handle that the GetClipboardData function // returns, not the application. The application should copy the data // immediately. The application cannot rely on being able to make long-term // use of the handle. The application must not free the handle nor leave it // locked.<nl> // The system performs implicit data format conversions between certain // clipboard formats when an application calls the GetClipboardData function. // For example, if the CF_OEMTEXT format is on the clipboard, a window can // retrieve data in the CF_TEXT format. The format on the clipboard is // converted to the requested format on demand. For more information, see // Synthesized Clipboard Formats. // @pyseeapi GetClipboardData // @pyseeapi Standard Clipboard Formats // @rdesc If the function fails, the standard win32api.error exception // is raised. If the function succeeds, the return value is as // described in the following table: // @flagh Format|Result type // @flag CF_HDROP|A tuple of Unicode filenames. // @flag CF_UNICODETEXT|A unicode object. // @flag CF_OEMTEXT|A string object. // @flag CF_TEXT|A string object. // @flag CF_ENHMETAFILE|A string with binary data obtained from GetEnhMetaFileBits // @flag CF_METAFILEPICT|A string with binary data obtained from GetMetaFileBitsEx (currently broken) // @flag CF_BITMAP|An integer handle to the bitmap. // @flag All other formats|A string with binary data obtained directly from the // global memory referenced by the handle. }
// @pymethod |PyIEmptyVolumeCache|ShowProperties| STDMETHODIMP PyGEmptyVolumeCache::ShowProperties( /* [in] */ HWND hwnd) { PY_GATEWAY_METHOD; return InvokeViaPolicy("ShowProperties", NULL, "N", PyWinLong_FromHANDLE(hwnd)); }
static PyObject * py_set_clipboard_data(PyObject* self, PyObject* args) { // @pyparm int|format||Specifies a clipboard format. For a description of // the standard clipboard formats, see Standard Clipboard Formats. // @pyparm int/buffer|hMem||Integer handle to the data in the specified // format, or string, unicode, or any object that supports the buffer interface. // A global memory object is allocated, and the object's buffer is copied to the new memory. // This parameter can be 0, indicating that the window provides data in // the specified clipboard format (renders the format) upon request. If a // window delays rendering, it must process the WM_RENDERFORMAT and // WM_RENDERALLFORMATS messages.<nl> // After SetClipboardData is called, the system owns the object identified // by the hMem parameter. The application can read the data, but must not // free the handle or leave it locked. If the hMem parameter identifies a // memory object, the object must have been allocated using the GlobalAlloc // function with the GMEM_MOVEABLE and GMEM_DDESHARE flags. int format; HANDLE handle; PyObject *obhandle; if (!PyArg_ParseTuple(args, "iO:SetClipboardData", &format, &obhandle)) return NULL; if (!PyWinObject_AsHANDLE(obhandle , &handle)){ PyErr_Clear(); const void * buf = NULL; Py_ssize_t bufSize = 0; // In py3k, unicode no longer supports buffer interface if (PyUnicode_Check(obhandle)){ bufSize = PyUnicode_GET_DATA_SIZE(obhandle) + sizeof(Py_UNICODE); buf=(void *)PyUnicode_AS_UNICODE(obhandle); } else { if (PyObject_AsReadBuffer(obhandle,&buf,&bufSize)==-1) return NULL; if (PyString_Check(obhandle)) bufSize++; // size doesnt include nulls! // else assume buffer needs no terminator... } handle = GlobalAlloc(GHND, bufSize); if (handle == NULL) { return ReturnAPIError("GlobalAlloc"); } void *dest = GlobalLock(handle); memcpy(dest, buf, bufSize); GlobalUnlock(handle); } HANDLE data; Py_BEGIN_ALLOW_THREADS; data = SetClipboardData((UINT)format, handle); Py_END_ALLOW_THREADS; if (!data) // XXX - should we GlobalFree the mem? return ReturnAPIError("SetClipboardData"); return PyWinLong_FromHANDLE(data); // @comm The uFormat parameter can identify a registered clipboard format, // or it can be one of the standard clipboard formats. For more information, // see Registered Clipboard Formats and Standard Clipboard Formats.<nl> // The system performs implicit data format conversions between certain // clipboard formats when an application calls the GetClipboardData function. // For example, if the CF_OEMTEXT format is on the clipboard, a window can // retrieve data in the CF_TEXT format. The format on the clipboard is // converted to the requested format on demand. For more information, see // Synthesized Clipboard Formats. // @pyseeapi SetClipboardData // @rdesc If the function succeeds, the return value is integer handle // of the data.<nl> // If the function fails, win32api.error is raised with the GetLastError // info. }
//***************************************************************************** // // @pymethod int|win32clipboard|SetClipboardText|Convienience function to // call SetClipboardData with text. // @comm You may pass a Unicode or string/bytes object to this function, // but depending on the value of the 'format' param, it may be converted // to the appropriate type for that param. // @comm Many applications will want to call this function twice, with the // same string specified but CF_UNICODETEXT specified the second. static PyObject * py_set_clipboard_text(PyObject* self, PyObject* args) { int format = CF_TEXT; PyObject *obtext, *ret=NULL; if (!PyArg_ParseTuple(args, "O|i:SetClipboardText", &obtext, // @pyparm str/unicode|text||The text to place on the clipboard. &format)) // @pyparm int|format|CF_TEXT|The clipboard format to use - must be CF_TEXT or CF_UNICODETEXT return NULL; const void *src = 0; DWORD cb = 0; // number of bytes *excluding* NULL size_t size_null = 0; if (format == CF_TEXT) { if (!PyWinObject_AsString(obtext, (char **)&src, FALSE, &cb)) return NULL; size_null = sizeof(char); } else if (format == CF_UNICODETEXT) { DWORD cchars; if (!PyWinObject_AsWCHAR(obtext, (WCHAR **)&src, FALSE, &cchars)) return NULL; cb = cchars * sizeof(WCHAR); size_null = sizeof(WCHAR); } else { return PyErr_Format(PyExc_ValueError, "Format arg must be one of CF_TEXT (%d) or CF_UNICODETEXT (%d) - got %d", CF_TEXT, CF_UNICODETEXT, format); } HGLOBAL hMem; BYTE *dest=NULL; hMem = GlobalAlloc(GHND, cb + size_null); if (hMem == NULL) PyWin_SetAPIError("GlobalAlloc"); else{ dest = (BYTE *)GlobalLock(hMem); memcpy(dest, src, cb); // whack the terminator on. memset(dest+cb, 0, size_null); GlobalUnlock(hMem); HANDLE data; Py_BEGIN_ALLOW_THREADS; data = SetClipboardData((UINT)format, hMem); Py_END_ALLOW_THREADS; if (!data) PyWin_SetAPIError("SetClipboardText"); else ret = PyWinLong_FromHANDLE(data); } if (format == CF_TEXT) PyWinObject_FreeString((char *)src); else PyWinObject_FreeWCHAR((WCHAR *)src); return ret; // @pyseeapi SetClipboardData // @rdesc If the function succeeds, the return value is integer handle // of the data.<nl> // If the function fails, win32api.error is raised with the GetLastError // info. }
// @pymethod int|PyCTreeCtrl|InsertItem|Inserts an item into the list. PyObject *PyCTreeCtrl_InsertItem( PyObject *self, PyObject *args ) { CTreeCtrl *pList; HTREEITEM ret = NULL; UINT mask; int image, selImage, state, stateMask; PyObject *obParent, *obInsertAfter; LPARAM lParam; HTREEITEM hParent, hInsertAfter; TCHAR *text=NULL; PyObject *obtext=Py_None; if (!(pList=GetTreeCtrl(self))) return NULL; if (PyArg_ParseTuple(args, "iOiiiiOOO:InsertItem", &mask, // @pyparmalt1 int|mask||Integer specifying which attributes to set &obtext, // @pyparmalt1 string|text||The text of the item. &image, // @pyparmalt1 int|image||The index of the image to use. &selImage, // @pyparmalt1 int|selectedImage||The index of the items selected image. &state, // @pyparmalt1 int|state||The initial state of the item. &stateMask, // @pyparmalt1 int|stateMask||Specifies which bits of the state are valid. &lParam, // @pyparmalt1 object|lParam||A user defined object for the item. &obParent, // @pyparmalt1 HTREEITEM|parent||The parent of the item. &obInsertAfter)) { // @pyparmalt1 HTREEITEM|parent||The parent of the item. if (!PyWinObject_AsHANDLE(obParent, (HANDLE *)&hParent)) return NULL; if (!PyWinObject_AsHANDLE(obInsertAfter, (HANDLE *)&hInsertAfter)) return NULL; if (!PyWinObject_AsTCHAR(obtext, &text, TRUE)) return NULL; GUI_BGN_SAVE; ret = pList->InsertItem(mask, text, image, selImage, state, stateMask, lParam, hParent, hInsertAfter); GUI_END_SAVE; goto done; } PyErr_Clear(); hParent = TVI_ROOT; hInsertAfter = TVI_LAST; if (PyArg_ParseTuple(args, "Oii|O&O&:InsertItem", &obtext, // @pyparmalt2 string|text||The text for the item. &image, // @pyparmalt2 int|image||The index of the image to use. &selImage, // @pyparmalt2 int|selectedImage||The index of the items selected image. PyWinObject_AsHANDLE, &hParent, // @pyparmalt2 HTREEITEM|parent|commctrl.TVI_ROOT|The parent of the item. PyWinObject_AsHANDLE, &hInsertAfter) // @pyparmalt2 HTREEITEM|insertAfter|commctrl.TVI_LAST|The item to insert the new item after, or TVI_FIRST, TVI_LAST or TVI_SORT && PyWinObject_AsTCHAR(obtext, &text, FALSE)){ GUI_BGN_SAVE; ret = pList->InsertItem(text, image, selImage, hParent, hInsertAfter); GUI_END_SAVE; goto done; } // This arg format conflicts with the above. Handle's can be parsed as ints, so if both optional items are // passed, they will be caught by the above and never get here ! PyErr_Clear(); hParent = TVI_ROOT; hInsertAfter = TVI_LAST; if (PyArg_ParseTuple(args, "O|O&O&:InsertItem", &obtext, // @pyparmalt3 string|text||The text for the item. PyWinObject_AsHANDLE, &hParent, // @pyparmalt3 HTREEITEM|parent|commctrl.TVI_ROOT|The parent of the item. PyWinObject_AsHANDLE, &hInsertAfter) // @pyparmalt3 HTREEITEM|parent|commctrl.TVI_LAST|The parent of the item. && PyWinObject_AsTCHAR(obtext, &text, FALSE)){ GUI_BGN_SAVE; ret = pList->InsertItem(text, hParent, hInsertAfter); GUI_END_SAVE; goto done; } PyErr_Clear(); PyObject *obTVItem; TV_INSERTSTRUCT tvItem; if (PyArg_ParseTuple(args, "O&O&O:InsertItem", PyWinObject_AsHANDLE, &tvItem.hParent, // @pyparm HTREEITEM|hParent||The parent item. If commctrl.TVI_ROOT or 0, it is added to the root. PyWinObject_AsHANDLE, &tvItem.hInsertAfter, // @pyparm HTREEITEM|hInsertAfter||The item to insert after. Can be an item or TVI_FIRST, TVI_LAST or TVI_SORT &obTVItem)) { // @pyparm <o TV_ITEM>|item||A tuple describing the new item. if (!PyWinObject_AsTV_ITEM(obTVItem, &tvItem.item)) return NULL; GUI_BGN_SAVE; ret = pList->InsertItem(&tvItem); GUI_END_SAVE; PyWinObject_FreeTV_ITEM(&tvItem.item); goto done; } PyErr_Clear(); RETURN_ERR("InsertItem could not parse the params."); // And you will beat your brains out determining why ... done: PyWinObject_FreeTCHAR(text); if (ret==NULL) RETURN_ERR("InsertItem failed"); return PyWinLong_FromHANDLE(ret); }