diff win/dw.c @ 1371:896347a9be19

Initial versions of dw_menu_delete_item() on OS/2 and Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 22 Nov 2011 20:46:37 +0000
parents e705051d841c
children b6249d66404c
line wrap: on
line diff
--- a/win/dw.c	Sun Nov 20 16:34:44 2011 +0000
+++ b/win/dw.c	Tue Nov 22 20:46:37 2011 +0000
@@ -4050,10 +4050,28 @@
  */
 int API dw_window_destroy(HWND handle)
 {
-   HWND parent = GetParent(handle);
-   Box *thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA);
-   HMENU menu = GetMenu(handle);
-
+   HWND parent;
+   Box *thisbox;
+   HMENU menu;
+
+   /* Handle special case for menu handle */
+   if(handle < (HWND)65536)
+   {
+      char buffer[31] = {0};
+      ULONG id = (ULONG)handle;
+      
+      _snprintf(buffer, 30, "_dw_id%ld", id);
+      menu = (HMENU)dw_window_get_data(DW_HWND_OBJECT, buffer);
+      
+      if(menu && IsMenu(menu))
+         return dw_menu_delete_item((HMENUI)menu, id);
+      return DW_ERROR_UNKNOWN;
+   }
+   
+   parent = GetParent(handle);
+   thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA);
+   menu = GetMenu(handle);
+   
    if(menu)
       _free_menu_data(menu);
 
@@ -5183,13 +5201,14 @@
 }
 
 /*
- * INCOMPLETE
  * Deletes the menu item specified
  * Parameters:
  *       menu: The handle to the  menu in which the item was appended.
  *       id: Menuitem id.
- */
-void API dw_menu_delete_item(HMENUI menux, unsigned long id)
+ * Returns: 
+ *       DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure.
+ */
+int API dw_menu_delete_item(HMENUI menux, unsigned long id)
 {
    HMENU mymenu = (HMENU)menux;
 
@@ -5197,12 +5216,11 @@
       mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu");
 
    if ( DeleteMenu(mymenu, id, MF_BYCOMMAND) == 0 )
-   {
-      char lasterror[257];
-      FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT), lasterror, 256, NULL);
-      fprintf(stderr, "Error deleting menu: %s", lasterror);
-   }
-   DrawMenuBar(menux);
+      return DW_ERROR_UNKNOWN;
+   
+   if( (HMENU)menux != mymenu )
+      DrawMenuBar(menux);
+   return DW_ERROR_NONE;
 }
 
 /*