Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Include binaries...
#11
nope... Cry
Reply
#12
The Win API is a ..., if i remember the bitmaps had to be converted to DC's and such, but i don't know GDI too much, sorry.
Reply
#13
As per the MSDN documentation (it's actually quite good Smile ), you need to send an icon handle - not a pointer to the data. See the CreateIcon function.
Reply
#14
Thank you both.

looked a little deeper and yes, the raw data can't be used, have to use win API.

CreateIcon is used when creating a new empty icon, but in this case we have already the icon data in memory.

Found out a DIB image needs to be created with CreateDIBitmap.
This command is used for bitmaps, icons etc. and takes a memory address with the raw data (well actually a little more...).

Hope to get it going...

...why needs every thing to be so complicated :???:
Reply
#15
Hallo fsw,

it's easy to show the application-icon:

Code:
~CreateWindow("STATIC", "#1", _
  WS_CHILD Or WS_VISIBLE Or SS_ICON, _
  26, 21, 32, 32, hWnd, 2, App.hInstance, 0)

To add the icon to the application just create a textfile with one line like this:

Code:
IDI_ICON1   ICON    DISCARDABLE     "MyIcon.ico"

Save it as with the Notepade as "*.rc", for example "MyIcon.rc". If you start "fbc.exe", then add the "MyIcon.rc" to the commandline like:

fbc test.bas -s gui MyIcon.rc

For Icon-Programming-Examples download the api-guide here:

http://www.mentalis.org/agnet/appdown.shtml

After installing let the programm search for all API-Function that included the word "Icon" and then click in "example" and you'll the how to use it (the examples are in Visual-Basic).

Kind regards from Germany

Peter
erman freeBASIC-mailinglist: de.groups.yahoo.com/group/free-basic.
For subscribing send an empty e-mail to free-basic-subscribe@yahoogroups.de.
Reply
#16
Thanks Peter,
but you missed the whole point here.

I know how to use resources, rc, res etc. files.
Done it 1000 times, this is not the problem.

The point here is to NOT USE RESOURCES, but store the images (or whatever) into the exe and access them.
(as I said in the first post...)

This way it's harder for others to manipulate the images used by the program.
Reply
#17
Well, you could:

1. compile your bas file
2. get the size of the exe
3. append the data to the exe
4. open your exe as a data file in the exe itself
5. seek exesize
6. read from there
Big Grin
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#18
Yes relsoft, that is working, just append it at the exe, I'm doing it with my Setup-Programm also, I just append the zip-file at the setup.exe.

Mostly an Icon is 766 byte, so just start at "FileLen()-766" to read the data.

Don't forget: today is mother's day (at least in Gemany)! ;-)

Kind regards

Peter
erman freeBASIC-mailinglist: de.groups.yahoo.com/group/free-basic.
For subscribing send an empty e-mail to free-basic-subscribe@yahoogroups.de.
Reply
#19
Vic, can I do it that way?
Code:
dim bmpaddress as ubyte ptr = @bitmap_data(0)

dim pbfilehptr as BITMAPFILEHEADER ptr
dim pbfileh as BITMAPFILEHEADER

  'ptr to BITMAPFILEHEADER
  pbfilehptr = bmpaddress
  pbfileh = *pbfilehptr

my problem is that the address of bitmap_data(0) and pbfileh are not the same.
And because of this, while using CreateDIBitmap, it's not working.

Here the code with CreateDIBitmap:
Code:
dim bmpaddress as ubyte ptr = @bitmap_data(0)

dim pbfilehptr as BITMAPFILEHEADER ptr
dim pbfileh as BITMAPFILEHEADER

  'ptr to BITMAPFILEHEADER
  pbfilehptr = bmpaddress
  pbfileh = *pbfilehptr

dim pbinfohptr as BITMAPINFO ptr 'HEADER ptr
dim pbinfoh as BITMAPINFO 'HEADER
  'ptr to BITMAPINFO 'HEADER
'  print SizeOf(BITMAPFILEHEADER)
'  print SizeOf(BITMAPINFO)
  pbinfohptr = bmpaddress + SizeOf(BITMAPFILEHEADER)
  pbinfoh = *pbinfohptr

print @scrabble_data(0)
print pbfilehptr
print @pbfileh

dim pbits as long
dim init as long
  'pointer to bitmap data
  pbits = pbfileh.bfOffBits 'offset
  init = bmpaddress + pbits  'bitmap data

dim hdc as long
dim catchbitmap as long
  hdc=GetDC (hwnd)
'  print hdc
  catchbitmap = CreateDIBitmap (hdc, pbinfoh.bmiHeader, CBM_INIT, init, pbinfoh, DIB_RGB_COLORS)
  print catchbitmap ' should not be ZERO... but it is :(

If I can get the pointer stuff ironed out I should be able to Create a Bitmap from the data inside the exe.
Reply
#20
BYREF args fault again.. i hate those suckers. This test worked fine:

Code:
option explicit

#include once "win\kernel32.bi"
#include once "win\user32.bi"
#include once "win\gdi32.bi"
#include once "fblogo.bi"


declare function        WinMain     ( byval hInstance as long, _
                                      byval hPrevInstance as long, _
                                      szCmdLine as string, _
                                      byval iCmdShow as integer ) as integer
                                  
                                  
    end WinMain( GetModuleHandle( null ), null, Command$, SW_NORMAL )
    
function WndProc ( byval hWnd as long, _
                   byval message as long, _
                   byval wParam as long, _
                   byval lParam as long ) as integer
    dim rct as RECT
    dim pnt as PAINTSTRUCT
    dim hDC as long
      static logoinfo as BITMAPINFO ptr
    static logodib as long    
    
    WndProc = 0
    
    select case ( message )
      
        case WM_CREATE            

            '' pointer to bitmap file
            dim logo as BITMAPFILEHEADER ptr = @fblogo_data(0)

            '' ponter to bitmap header
              logoinfo = logo + SizeOf(BITMAPFILEHEADER)

              '' create a DIB
              logodib = CreateDIBitmap( GetDC( hWnd ), byval @logoinfo->bmiHeader, _
                                        CBM_INIT, byval logo + logo->bfOffBits, byval logoinfo, DIB_RGB_COLORS )
      
            exit function
        
        case WM_PAINT
          
            hDC = BeginPaint( hWnd, pnt )
            
            '' load DIB to a compatible DC
            dim memDC as long
            memDC = CreateCompatibleDC( hDC )
            
            dim oldobj as long
            oldobj = SelectObject( memDC, logodib )
            
            '' blit compatible DC to this window
            BitBlt( hDC, 0, 0, logoinfo->bmiHeader.biWidth, logoinfo->bmiHeader.biHeight, _
                    memDC, 0, 0, SRCCOPY )
            
            '' restore
            SelectObject( memDC, oldobj )
            DeleteDC( memDC )
            
            EndPaint( hWnd, pnt )
            
            exit function            
        
        case WM_KEYDOWN
            if( lobyte( wParam ) = 27 ) then
                PostMessage hWnd, WM_CLOSE, 0, 0
            end if
        
        case WM_DESTROY
            PostQuitMessage 0            
            exit function
    end select
    
    WndProc = DefWindowProc( hWnd, message, wParam, lParam )    
    
end function

function WinMain ( byval hInstance as long, _
                   byval hPrevInstance as long, _
                   szCmdLine as string, _
                   byval iCmdShow as integer ) as integer    
    
     dim wMsg as MSG
     dim wcls as WNDCLASS    
     dim szAppName as string
     dim hWnd as unsigned long

    
     WinMain = 0
    
     szAppName = "Test"
    
     with wcls
         .style         = CS_HREDRAW or CS_VREDRAW
         .lpfnWndProc   = @WndProc
         .cbClsExtra    = 0
         .cbWndExtra    = 0
         .hInstance     = hInstance
         .hIcon         = LoadIcon( null, byval IDI_APPLICATION )
         .hCursor       = LoadCursor( null, byval IDC_ARROW )
         .hbrBackground = GetStockObject( byval WHITE_BRUSH )
         .lpszMenuName  = null
         .lpszClassName = strptr( szAppName )
     end with
    
    
    if ( RegisterClass( wcls ) = false ) then
        exit function
    end if
    
    

    hWnd = CreateWindowEx( 0, szAppName, "Test", WS_OVERLAPPEDWINDOW, _
                          CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, _
                          null, null, hInstance, null )
                          

    ShowWindow   hWnd, iCmdShow
    UpdateWindow hWnd
    

    while ( GetMessage( wMsg, null, 0, 0 ) <> false )    
        TranslateMessage wMsg
        DispatchMessage  wMsg
    wend
    
    
    WinMain = wMsg.wParam

end function
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)