comparison 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
comparison
equal deleted inserted replaced
1370:e705051d841c 1371:896347a9be19
4048 * Parameters: 4048 * Parameters:
4049 * handle: The window handle to destroy. 4049 * handle: The window handle to destroy.
4050 */ 4050 */
4051 int API dw_window_destroy(HWND handle) 4051 int API dw_window_destroy(HWND handle)
4052 { 4052 {
4053 HWND parent = GetParent(handle); 4053 HWND parent;
4054 Box *thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA); 4054 Box *thisbox;
4055 HMENU menu = GetMenu(handle); 4055 HMENU menu;
4056 4056
4057 /* Handle special case for menu handle */
4058 if(handle < (HWND)65536)
4059 {
4060 char buffer[31] = {0};
4061 ULONG id = (ULONG)handle;
4062
4063 _snprintf(buffer, 30, "_dw_id%ld", id);
4064 menu = (HMENU)dw_window_get_data(DW_HWND_OBJECT, buffer);
4065
4066 if(menu && IsMenu(menu))
4067 return dw_menu_delete_item((HMENUI)menu, id);
4068 return DW_ERROR_UNKNOWN;
4069 }
4070
4071 parent = GetParent(handle);
4072 thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA);
4073 menu = GetMenu(handle);
4074
4057 if(menu) 4075 if(menu)
4058 _free_menu_data(menu); 4076 _free_menu_data(menu);
4059 4077
4060 /* If it is a desktop window let WM_DESTROY handle it */ 4078 /* If it is a desktop window let WM_DESTROY handle it */
4061 if(parent != HWND_DESKTOP) 4079 if(parent != HWND_DESKTOP)
5181 dw_window_set_data( DW_HWND_OBJECT, buffer1, (void *)check ); 5199 dw_window_set_data( DW_HWND_OBJECT, buffer1, (void *)check );
5182 dw_window_set_data( DW_HWND_OBJECT, buffer2, (void *)disabled ); 5200 dw_window_set_data( DW_HWND_OBJECT, buffer2, (void *)disabled );
5183 } 5201 }
5184 5202
5185 /* 5203 /*
5186 * INCOMPLETE
5187 * Deletes the menu item specified 5204 * Deletes the menu item specified
5188 * Parameters: 5205 * Parameters:
5189 * menu: The handle to the menu in which the item was appended. 5206 * menu: The handle to the menu in which the item was appended.
5190 * id: Menuitem id. 5207 * id: Menuitem id.
5191 */ 5208 * Returns:
5192 void API dw_menu_delete_item(HMENUI menux, unsigned long id) 5209 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure.
5210 */
5211 int API dw_menu_delete_item(HMENUI menux, unsigned long id)
5193 { 5212 {
5194 HMENU mymenu = (HMENU)menux; 5213 HMENU mymenu = (HMENU)menux;
5195 5214
5196 if ( IsWindow(menux) && !IsMenu(mymenu) ) 5215 if ( IsWindow(menux) && !IsMenu(mymenu) )
5197 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); 5216 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu");
5198 5217
5199 if ( DeleteMenu(mymenu, id, MF_BYCOMMAND) == 0 ) 5218 if ( DeleteMenu(mymenu, id, MF_BYCOMMAND) == 0 )
5200 { 5219 return DW_ERROR_UNKNOWN;
5201 char lasterror[257]; 5220
5202 FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT), lasterror, 256, NULL); 5221 if( (HMENU)menux != mymenu )
5203 fprintf(stderr, "Error deleting menu: %s", lasterror); 5222 DrawMenuBar(menux);
5204 } 5223 return DW_ERROR_NONE;
5205 DrawMenuBar(menux);
5206 } 5224 }
5207 5225
5208 /* 5226 /*
5209 * Pops up a context menu at given x and y coordinates. 5227 * Pops up a context menu at given x and y coordinates.
5210 * Parameters: 5228 * Parameters: