Bool WREHData2Mem( HDDEDATA hData, void **data, uint_32 *size ) { DWORD dde_size; if( data == NULL || size == NULL || hData == (HDDEDATA)NULL ) { return( FALSE ); } *size = dde_size = DdeGetData( hData, NULL, 0, 0 ); if( dde_size == 0 ) { return( FALSE ); } *data = WREMemAlloc( dde_size ); if( *data == NULL ) { return( FALSE ); } if( dde_size != DdeGetData( hData, *data, dde_size, 0 ) ) { WREMemFree( *data ); return( FALSE ); } return( TRUE ); }
void WREDisplayHint( int id ) { char *buf; char *mditext; WREHintItem *hint; if( id < WRE_MDI_FIRST ) { hint = WREGetHintItem ( id ); if( hint ) { WRESetStatusByID( -1, hint->hint ); } } else { mditext = WREAllocRCString( WRE_HINT_MDIMSG ); if( mditext ) { buf = WREMemAlloc( strlen(mditext) + 20 + 1 ); if( buf ) { sprintf( buf, mditext, WRE_MDI_FIRST + 1 - id ); WRESetStatusText( NULL, buf, TRUE ); WREMemFree( buf ); } WREFreeRCString( mditext ); } } return; }
Bool WREGetAndAddIconImage( BYTE *data, WResDir dir, ICONDIRENTRY *id, int ord ) { BYTE *icon; int dup; WResID *tname; WResID *rname; WResLangType lang; Bool ok; dup = FALSE; lang.lang = DEF_LANG; lang.sublang = DEF_SUBLANG; tname = NULL; rname = NULL; ok = ( data && dir && id && id->dwBytesInRes ); if ( ok ) { icon = (BYTE *)WREMemAlloc( id->dwBytesInRes ); ok = ( icon != NULL ); } if( ok ) { memcpy( icon, data + id->dwImageOffset, id->dwBytesInRes ); tname = WResIDFromNum( (uint_16)RT_ICON ); ok = ( tname != NULL ); } if( ok ) { rname = WResIDFromNum( ord ); ok = ( rname != NULL ); } if ( ok ) { ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0, id->dwBytesInRes, dir, &lang, &dup ); } if( ok ) { ok = WRFindAndSetData( dir, tname, rname, &lang, icon ); } if( !ok ) { if( icon != NULL ) { WREMemFree( icon ); } } if( tname != NULL ) { WREMemFree( tname ); } if( rname != NULL ) { WREMemFree( rname ); } return( ok ); }
WREToolBar *WREAllocToolBar( void ) { WREToolBar *tbar; tbar = (WREToolBar *)WREMemAlloc( sizeof( WREToolBar ) ); if( tbar != NULL ) { memset( tbar, 0, sizeof( WREToolBar ) ); } return( tbar ); }
WREToolBarInfo *WREAllocToolBarInfo( int num ) { WREToolBarInfo *info; info = (WREToolBarInfo *)WREMemAlloc( sizeof( WREToolBarInfo ) ); if( info != NULL ) { memset( info, 0, sizeof( WREToolBarInfo ) ); info->items = (TOOLITEMINFO *)WREMemAlloc( sizeof( TOOLITEMINFO ) * num ); if( info->items != NULL ) { memset( info->items, 0, sizeof( TOOLITEMINFO ) * num ); info->num_items = num; } else { WREMemFree( info ); info = NULL; } } return( info ); }
WREResInfo *WREAllocResInfo ( void ) { WREResInfo *info; info = (WREResInfo *) WREMemAlloc ( sizeof(WREResInfo) ); if ( info ) { memset ( info, 0, sizeof(WREResInfo) ); } return ( info ); }
Bool WRECreateIconResHeader( RESICONHEADER **rih, uint_32 *rihsize, BYTE *data, uint_32 data_size ) { ICONHEADER *pih; uint_32 pihsize; ICONHEADER *ih; uint_32 ihsize; int i; Bool ok; ih = NULL; ok = (rih != NULL && rihsize != NULL && data != NULL && data_size != 0); if( ok ) { pih = (ICONHEADER *)data; pihsize = sizeof( ICONHEADER ); pihsize += sizeof( ICONDIRENTRY ) * (pih->idCount - 1); ok = WRCreateIconHeader( data + pihsize, data_size - pihsize, 1, &ih, &ihsize ); } if( ok ) { *rihsize = sizeof( RESICONHEADER ); *rihsize += sizeof( RESICONDIRENTRY ) * (ih->idCount - 1); *rih = (RESICONHEADER *)WREMemAlloc( *rihsize ); ok = (*rih != NULL); } if( ok ) { memcpy( *rih, pih, sizeof( WORD ) * 3 ); for( i = 0; i < ih->idCount; i++ ) { (*rih)->idEntries[i].bWidth = ih->idEntries[i].bWidth; (*rih)->idEntries[i].bHeight = ih->idEntries[i].bHeight; (*rih)->idEntries[i].bColorCount = ih->idEntries[i].bColorCount; (*rih)->idEntries[i].bReserved = 0; (*rih)->idEntries[i].wPlanes = ih->idEntries[i].wPlanes; (*rih)->idEntries[i].wBitCount = ih->idEntries[i].wBitCount; (*rih)->idEntries[i].lBytesInRes = ih->idEntries[i].dwBytesInRes; (*rih)->idEntries[i].wNameOrdinal = i + 1; } } if( ih != NULL ) { WREMemFree( ih ); } return( ok ); }
Bool WRECreateCursorResHeader( RESCURSORHEADER **rch, uint_32 *rchsize, BYTE *data, uint_32 data_size ) { CURSORHEADER *ch; uint_32 chsize; ICONHEADER *ih; uint_32 ihsize; int i; Bool ok; ih = NULL; ok = (rch != NULL && rchsize != NULL && data != NULL && data_size != 0); if( ok ) { *rch = NULL; *rchsize = 0; ch = (CURSORHEADER *)data; chsize = sizeof( CURSORHEADER ); chsize += sizeof( CURSORDIRENTRY ) * (ch->cdCount - 1); ok = WRCreateIconHeader( data + chsize, data_size - chsize, 2, &ih, &ihsize ); } if( ok ) { *rchsize = sizeof( RESCURSORHEADER ); *rchsize += sizeof( RESCURSORDIRENTRY ) * (ih->idCount - 1); *rch = (RESCURSORHEADER *)WREMemAlloc( *rchsize ); ok = (*rch != NULL); } if( ok ) { memcpy( *rch, ch, sizeof( WORD ) * 3 ); for( i = 0; i < ih->idCount; i++ ) { (*rch)->cdEntries[i].bWidth = ih->idEntries[i].bWidth; (*rch)->cdEntries[i].bHeight = ih->idEntries[i].bHeight * 2; (*rch)->cdEntries[i].wPlanes = ih->idEntries[i].wPlanes; (*rch)->cdEntries[i].wBitCount = ih->idEntries[i].wBitCount; (*rch)->cdEntries[i].lBytesInRes = ih->idEntries[i].dwBytesInRes; (*rch)->cdEntries[i].wNameOrdinal = i + 1; } } if( ih != NULL ) { WREMemFree( ih ); } return( ok ); }
Bool WRECreateWREPopupListItem ( int num, HMENU menu, WREPopupHintItem *hint_items ) { WREPopupListItem *p; p = (WREPopupListItem *) WREMemAlloc ( sizeof(WREPopupListItem) ); if ( p ) { p->num = num; p->menu = menu; p->hint_items = hint_items; if ( WREInitHintItems ( num, menu, hint_items ) ) { ListAddElt ( &WREPopupList, p ); } else { WREMemFree ( p ); return ( FALSE ); } } else { return ( FALSE ); } return ( TRUE ); }
void WRESetTotalText( WREResInfo *info ) { HWND total; HWND lbox; LRESULT count; char *buf; if( info == NULL || WRETotalText == NULL || WRETotalTextOne == NULL || WRETotalTextNone == NULL ) { return; } lbox = GetDlgItem( info->info_win, IDM_RNRES ); total = GetDlgItem( info->info_win, IDM_RNTOTALTEXT ); if( lbox == (HWND)NULL || total == (HWND)NULL ) { return; } count = SendMessage( lbox, LB_GETCOUNT, 0, 0 ); if( count == LB_ERR ) { count = 0; } if( count == 0 ) { SendMessage( total, WM_SETTEXT, 0, (LPARAM)(LPSTR)WRETotalTextNone ); } else if( count == 1 ) { SendMessage( total, WM_SETTEXT, 0, (LPARAM)(LPSTR)WRETotalTextOne ); } else { buf = WREMemAlloc( strlen( WRETotalText ) + 20 + 1 ); if( buf != NULL ) { sprintf( buf, WRETotalText, count ); SendMessage( total, WM_SETTEXT, 0, (LPARAM)(LPSTR)buf ); WREMemFree( buf ); } } }
Bool WREGetAndAddCursorImage( BYTE *data, WResDir dir, CURSORDIRENTRY *cd, int ord ) { BYTE *cursor; int dup; uint_32 size; WResID *tname; WResID *rname; WResLangType lang; CURSORHOTSPOT hotspot; Bool ok; dup = FALSE; lang.lang = DEF_LANG; lang.sublang = DEF_SUBLANG; tname = NULL; rname = NULL; ok = (data != NULL && dir != NULL && cd != NULL && cd->dwBytesInRes != 0); if ( ok ) { cursor = (BYTE *)WREMemAlloc( cd->dwBytesInRes ); ok = (cursor != NULL); } if( ok ) { memcpy( cursor, data + cd->dwImageOffset, cd->dwBytesInRes ); hotspot.xHotspot = cd->wXHotspot; hotspot.yHotspot = cd->wYHotspot; size = cd->dwBytesInRes; ok = WREAddCursorHotspot( &cursor, &size, &hotspot ); } if( ok ) { tname = WResIDFromNum( (uint_16)RT_CURSOR ); ok = (tname != NULL); } if( ok ) { rname = WResIDFromNum( ord ); ok = (rname != NULL); } if( ok ) { ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0, size, dir, &lang, &dup ); } if( ok ) { ok = WRFindAndSetData( dir, tname, rname, &lang, cursor ); } if( !ok ) { if( cursor != NULL ) { WREMemFree( cursor ); } } if( tname != NULL ) { WREMemFree( tname ); } if( rname != NULL ) { WREMemFree( rname ); } return( ok ); }
Bool WRECreateIconDataFromGroup( WRECurrentResInfo *group, BYTE **data, uint_32 *size ) { WResLangType lt; WRECurrentResInfo image; RESICONHEADER *rih; ICONHEADER *ih; uint_16 ord; uint_32 osize; int i; Bool ok; ok = (group != NULL && group->info != NULL && group->info->info != NULL && group->lang != NULL && data != NULL && size != NULL); if( ok ) { if( group->lang->data == NULL ) { group->lang->data = WREGetCurrentResData( group ); ok = (group->lang->data != NULL); } } if( ok ) { image.info = group->info; rih = (RESICONHEADER *)group->lang->data; *size = sizeof( ICONHEADER ); *size += sizeof( ICONDIRENTRY ) * (rih->cwCount - 1); *data = (BYTE *)WREMemAlloc( *size ); ih = (ICONHEADER *)*data; ok = (*data != NULL); } if( ok ) { memcpy( ih, rih, sizeof( WORD ) * 3 ); } if( ok ) { for( i = 0; ok && i < rih->cwCount; i++ ) { ord = (uint_16)rih->idEntries[i].wNameOrdinal; lt = group->lang->Info.lang; ok = WREFindImageId( &image, (uint_16)RT_ICON, ord, < ); if( ok ) { osize = *size; ok = WREAddIconImageToData( &image, data, size ); if( ok ) { ih = (ICONHEADER *)*data; ih->idEntries[i].bWidth = rih->idEntries[i].bWidth; ih->idEntries[i].bHeight = rih->idEntries[i].bHeight; ih->idEntries[i].bColorCount = rih->idEntries[i].bColorCount; //ih->idEntries[i].wPlanes = rih->idEntries[i].wPlanes; //ih->idEntries[i].wBitCount = rih->idEntries[i].wBitCount; ih->idEntries[i].wPlanes = 0; ih->idEntries[i].wBitCount = 0; ih->idEntries[i].bReserved = 0; ih->idEntries[i].dwBytesInRes = *size - osize; ih->idEntries[i].dwImageOffset = osize; } } } } if( !ok ) { if( *data != NULL ) { WREMemFree( *data ); *data = NULL; } *size = 0; } return( ok ); }
Bool WRECreateCursorDataFromGroup( WRECurrentResInfo *group, BYTE **data, uint_32 *size ) { WRECurrentResInfo image; WResLangType lt; RESCURSORHEADER *rch; CURSORHEADER *ch; CURSORHOTSPOT hotspot; uint_16 ord; uint_32 osize; int i; Bool ok; ok = (group != NULL && group->info != NULL && group->info->info != NULL && group->lang != NULL && data != NULL && size != NULL); if( ok ) { if( group->lang->data == NULL ) { group->lang->data = WREGetCurrentResData( group ); ok = (group->lang->data != NULL); } } if( ok ) { image.info = group->info; rch = (RESCURSORHEADER *)group->lang->data; *size = sizeof( CURSORHEADER ); *size += sizeof( CURSORDIRENTRY ) * (rch->cwCount - 1); *data = (BYTE *)WREMemAlloc( *size ); ch = (CURSORHEADER *)*data; ok = (*data != NULL); } if( ok ) { memcpy( ch, rch, sizeof( WORD ) * 3 ); } if( ok ) { for( i = 0; ok && i < rch->cwCount; i++ ) { ord = (uint_16)rch->cdEntries[i].wNameOrdinal; lt = group->lang->Info.lang; ok = WREFindImageId( &image, (uint_16)RT_CURSOR, ord, < ); if( ok ) { osize = *size; ok = WREAddCursorImageToData( &image, data, size, &hotspot ); if( ok ) { ch = (CURSORHEADER *)*data; ch->cdEntries[i].bWidth = rch->cdEntries[i].bWidth; ch->cdEntries[i].bHeight = rch->cdEntries[i].bHeight / 2; ch->cdEntries[i].bColorCount = 0; ch->cdEntries[i].bReserved = 0; ch->cdEntries[i].wXHotspot = hotspot.xHotspot; ch->cdEntries[i].wYHotspot = hotspot.yHotspot; ch->cdEntries[i].dwBytesInRes = *size - osize; ch->cdEntries[i].dwImageOffset = osize; } } } } if( !ok ) { if( *data != NULL ) { WREMemFree( *data ); *data = NULL; } *size = 0; } return( ok ); }
Bool WRECreateResourceWindow( WREResInfo *res_info ) { MDICREATESTRUCT mdics; LRESULT ret; HWND win; Bool ok; DWORD style; int fn_offset; char *win_title; int win_title_len; _wre_touch( fn_offset ); win_title = NULL; ok = (res_info != NULL); if( ok ) { WREIncNumRes(); if( res_info->info->file_name != NULL ) { //perhaps I should make this an option //fn_offset = WRFindFnOffset( res_info->info->file_name ); //title = &res_info->info->file_name[fn_offset]; mdics.szTitle = res_info->info->file_name; } else if( res_info->info->save_name != NULL ) { mdics.szTitle = res_info->info->save_name; } else { WREResCounter++; win_title_len = strlen( WREResUntitled ) + 7; win_title = (char *)WREMemAlloc( win_title_len ); sprintf( win_title, "%s.%d", WREResUntitled, 0xffff & WREResCounter ); mdics.szTitle = win_title; } style = 0; if( WREGetNumRes() != 1 && WREIsCurrentMDIWindowZoomed() ) { style = WS_MAXIMIZE; } mdics.szClass = WREResClass; mdics.hOwner = WREAppInst; mdics.x = CW_USEDEFAULT; mdics.y = CW_USEDEFAULT; mdics.cx = CW_USEDEFAULT; mdics.cy = CW_USEDEFAULT; mdics.style = style; mdics.lParam = (LPARAM)(LPVOID)res_info; ret = SendMessage( WREGetMDIWindowHandle(), WM_MDICREATE, 0, (LPARAM)(LPVOID)&mdics ); ok = (ret != NULL); } if( ok ) { #ifdef __NT__ win = (HWND)ret; #else win = (HWND)LOWORD( ret ); #endif ok = (res_info->res_win != NULL && res_info->res_win == win); } if( ok ) { ok = WRECreateResInfoWindow( res_info ); } if( ok ) { WResizeInfoWindow( res_info ); ShowWindow( res_info->info_win, SW_SHOW ); SetFocus( res_info->info_win ); } if( win_title != NULL ) { WREMemFree( win_title ); } return( ok ); }