// @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 PyCMenu>|win32ui|CreatePopupMenu|Creates a popup menu object. PyObject *PyCMenu::create_popup(PyObject *self, PyObject *args) { CHECK_NO_ARGS(args); HMENU hMenu = CreatePopupMenu(); if (!hMenu) RETURN_API_ERR("CreatePopupMenu"); return ui_assoc_object::make(PyCMenu::type, hMenu); }
// @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); }
// @pymethod string|PyCMenu|DeleteMenu|Deletes the specified menu item. PyObject *PyCMenu::DeleteMenu(PyObject *self, PyObject *args) { HMENU hMenu = GetMenu( self ); if (!hMenu) return NULL; int id,flags; if (!PyArg_ParseTuple(args,"ii", &id, // @pyparm int|id||The id of the item being deleted. &flags)) // @pyparm int|flags||Specifies how the id parameter is interpreted. It must be one of win32con.MF_BYCOMMAND or win32con.MF_BYPOSITION. return NULL; if (!::DeleteMenu(hMenu, id, flags)) RETURN_API_ERR("::DeleteMenu"); RETURN_NONE; }
// @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 |PyCMenu|TrackPopupMenu|Creates a popup menu anywhere on the screen. PyObject *PyCMenu::TrackPopupMenu(PyObject *self, PyObject *args) { // @comm The TrackPopupMenu function displays a floating pop-up menu at the // specified location and tracks the selection of items on the pop-up menu. // The floating pop-up menu can appear anywhere on the screen. HMENU hMenu = GetMenu( self ); if (!hMenu) return NULL; HWND hTarget; PyObject *wndObject = NULL; int flags=TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON; int x,y; if (!PyArg_ParseTuple(args,"(ii)|iO", &x, &y, // @pyparm (int, int)|(x,y)||The position for the menu.. &flags, // @pyparm int|flags|win32con.TPM_LEFTALIGN\|win32con.TPM_LEFTBUTTON\|win32con.TPM_RIGHTBUTTON|Flags for the menu. &wndObject)) // @pyparm <o PyCWnd>|owner|(main application frame)|The owner of the menu. return NULL; if (wndObject) { CWnd *wnd=GetWndPtr(wndObject); if (wnd==NULL) return NULL; hTarget = wnd->m_hWnd; } else { CWinApp *pApp = GetApp(); if (!pApp) return NULL; hTarget=pApp->m_pMainWnd->GetSafeHwnd(); } GUI_BGN_SAVE; BOOL rc = ::TrackPopupMenu(hMenu,flags,x,y,0,hTarget,NULL); GUI_END_SAVE; // @rdesc If the underlying MFC function fails, but TPM_RETURNCMD is set in the flags parameter, then None is returned instead of the normal exception. if (!rc) { if (flags & TPM_RETURNCMD) { RETURN_NONE; } else { RETURN_API_ERR("TrackPopupMenu"); } } return Py_BuildValue("i",rc); }
// @pymethod <o PyCMenu>|win32ui|LoadMenu|Creates and loads a menu resource from a DLL. PyObject *PyCMenu::load_menu(PyObject *self, PyObject *args) { int id; PyObject *dllObj = NULL; HMODULE hMod = NULL; // @pyparm int|id||The Id of the menu to load. // @pyparm <o PyDLL>|dll|None|The DLL to load from. if (!PyArg_ParseTuple(args, "i|O", &id, &dllObj)) return NULL; if (dllObj && dllObj!=Py_None) { // passed a DLL object. if (!is_uiobject(dllObj, &dll_object::type)) RETURN_TYPE_ERR("passed object must be a PyDLL object"); hMod = ((dll_object *)dllObj)->GetDll(); } else hMod = AfxFindResourceHandle( MAKEINTRESOURCE(id), RT_MENU ); HMENU hMenu = ::LoadMenu(hMod, MAKEINTRESOURCE(id)); if (!hMenu) RETURN_API_ERR("LoadMenu"); return ui_assoc_object::make(PyCMenu::type, hMenu); }
// @pymethod |PyCMenu|InsertMenu|Inserts an item into a menu. PyObject *PyCMenu::InsertMenu(PyObject *self, PyObject *args) { HMENU hMenu = GetMenu( self ); if (!hMenu) return NULL; TCHAR *value = NULL; int id=0; int flags; int pos; BOOL rc, bHaveInt = TRUE; PyObject *obsubMenu=NULL, *obvalue=Py_None; if (!PyArg_ParseTuple(args,"ii|OO:InsertMenu", &pos, // @pyparm int|pos||The position (zero-based) the item should be inserted. &flags, // @pyparm int|flags||Flags for the new item. &obsubMenu, // @pyparm int/<o PyCMenu>|id|0|The ID for a new menu item, or handle to a submenu &obvalue)) // @pyparm string/None|value|None|A string for the menu item. return NULL; if (obsubMenu){ id=PyInt_AsLong(obsubMenu); if (id==-1 && PyErr_Occurred()){ PyErr_Clear(); bHaveInt=FALSE; } } if (!PyWinObject_AsTCHAR(obvalue, &value, TRUE)) return NULL; if (bHaveInt) rc=::InsertMenu( hMenu, pos, flags, id, value); else { HMENU hsubMenu = GetMenu(obsubMenu); rc=::InsertMenu(hMenu, pos, flags, (UINT_PTR)hsubMenu, value); } PyWinObject_FreeTCHAR(value); if (!rc) RETURN_API_ERR("::InsertMenu"); 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; }