Qbasicnews.com

Full Version: Odd (DIM aString AS STRING * aNumber)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I don't know if this has been reported before or not, or even worth mentioning.


When I have even numbers of ( DIM aString AS STRING * aNumber ), my programs won't stretch a bitmap on a button or static control and it won't resize a button to fit a bitmap.

The ones it effects are these:

This one resizes the button to the bitmap:
SendMessage GetDlgItem(hDlg, 107),BM_SETIMAGE,IMAGE_BITMAP, BYVAL hBmp4

A StretchBlt that puts a bitmap on a button.

And a StretchBlt that puts a bitmap on a static control.



What's odd is it doesn't have any effect on this one.

This one will work whether there is an odd or even numbers of (Dim Strings * numbers):

SendMessage GetDlgItem(hDlg, 106), STM_SETIMAGE, IMAGE_BITMAP, it resizes a button to fit a bitmap.


If I'm going to have 2 or 4 or 6 or 8 of them, I have to add an extra fake one for the bitmaps to work, which is no big thing. They all work on 1, 3, 5, 7, 9, 11, 13, I didn't check any futher.

These ( DIM aString AS STRING * aNumber ) didn't have anything to do with the bitmaps, they were all for 4 different Listviews in the same callback.

They didn't stop any of the other controls from working right. There was 20 controls plus one large circle with diagcross background lines and a rounded rectangle with background lines and a regular rectangle with no lines. Then there was those 2 bitmaps on two buttons and 2 bitmaps on 2 static controls, where only one worked every the time.


Later..........Jerry Fielden
You can be sure memory is being rewritten somehow and then those extra strings when declared are reserving more space, so the API calls won't rewrite other vars, so no errors happen -- are you calling any API function passing those fixed-len strings? Are they allocated locally inside a sub/function? Without seeing the code i can't help more, sorry..
Hello ,

I think I've located the problem, but I'm not really sure. So here's the code. I've stripped it down to the problem area, I think.

I believe it has to do with saving a file with PUT, when creating the buttons or static controls with bitmaps.

The file saving was just part of an example for loading a Listview from a file in the same window creating part.

Code:
OPTION EXPLICIT

' $INCLUDE: 'win\kernel32.bi'
' $INCLUDE: 'win\user32.bi'
' $INCLUDE: 'win\GDI32.bi'

DECLARE FUNCTION  WinMain (byval hInstance as long, _  
                       byval hPrevInstance as long, _  
                       szCmdLine as string, _          
                       byval iCmdShow as long) as long  

'entry point
  END WinMain(GetModuleHandle(null), null, Command$, SW_NORMAL)


FUNCTION ProcessWindow (BYVAL hDlg AS Uinteger, BYVAL wMsg AS Uinteger, BYVAL wParam _
                  AS Uinteger, BYVAL lParam AS LONG, BYVAL hInstance AS LONG) AS LONG
  
  
   dim buff1 as string * 10
   DIM Fake1 AS STRING * 10     ' try commenting some of these out
   DIM Fake2 AS STRING * 10
   DIM Fake3 AS STRING * 10
   DIM Fake4 AS STRING * 10
   DIM Fake5 AS STRING * 10
   DIM Fake6 AS STRING * 10
   DIM Fake7 AS STRING * 10
   DIM Fake8 AS STRING * 10
   DIM Fake9 AS STRING * 10
  
    
   DIM wmID AS Long, wmEvent AS LONG
      
   STATIC hBmp2 AS LONG
   DIM MemDC2 AS LONG, rc2 AS RECT, bm2 AS BITMAP
  
   STATIC hBmp5 AS LONG
   DIM MemDC5 AS LONG, rc5 AS RECT, bm5 AS BITMAP
  
   DIM hCtrl AS LONG
   dim xx as long, yl as long, xl as long, ff as long

   IF wMsg = WM_CREATE THEN        'Messages that Initializes Controls and  
                                       'tasks that affects the Appearance of Dialogs

     hBmp2 = LoadImage(0, "\bmp\smallBMP.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
     GetObject hBmp2, LEN(bm2), bm2       'get bitmap's size
     hBmp5 = LoadImage(0, "\bmp\smallBMP.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
     GetObject hBmp5, LEN(bm5), bm5       'get bitmap's size
      
     hCtrl = CreateWindowEx(0, "static", "", _
            SS_BITMAP   OR  WS_CHILD OR WS_VISIBLE, _
                  1,  1,  190,  217, _  
                  hdlg,  104, hInstance, BYVAL NULL)    

     hCtrl = CreateWindowEx(WS_EX_CLIENTEDGE, "Button", "", _
           WS_CHILD OR WS_VISIBLE OR  BS_BITMAP     , _
                 320,  22, bm2.bmWidth, bm2.bmHeight, _  
                 hdlg,  102, hInstance, BYVAL NULL)    


     SendMessage GetDlgItem(hDlg, 102),BM_SETIMAGE,IMAGE_BITMAP, BYVAL hBmp2
     SendMessage GetDlgItem(hDlg, 104), STM_SETIMAGE, IMAGE_BITMAP, BYVAL hBmp5

'--------------------------------------------------------------
'---------------------------------------------------------------
'\\\\\\\\\\\\\\\\ Futher investigation reveals \\\\\\\\\\\\\\\\\
'---------------------------------------------------------------
        
' Without this file saving code, the problem don't exist. If I were
' to delete this, it wouldn't matter how many (DIM aString AS STRING * aNumber)
' I had, odd number or even number, the bitmaps would load correctly.

   xl = 1 : ff = FREEFILE                ' filenumber for creating & saving filler Data to file
   OPEN "\FREEBASIC\LLLVVVX1.ZZZ" FOR BINARY AS #ff  
     FOR yl=1 TO  20
       buff1="Item Nr" + STR$(xl)        ' Create Item filler Data for buffer
       PUT #ff,seek(ff), buff1                    ' Write column 1 filler DATA to file
       FOR xx = 1 TO  4
         buff1="Item Nr"+STR$(xx*100+xl)
         PUT #ff, SEEK(ff), buff1                  ' Write the rest to file
       NEXT xx    
       xl=xl+1    
     NEXT yl    
   CLOSE ff  
'
'------------------------------------------------------------------
'------------------------------------------------------------------

SetWindowPos hDlg, HWND_TOP, 0, 0, 0, 0, SWP_NoSize OR SWP_NoMove


  ELSEIF wMsg = WM_DESTROY THEN
     DeleteObject hBmp2
     DeleteObject hBmp5
   ELSEIF wMsg = WM_CLOSE  THEN   ' Message from Clicking on system close Icon
    PostQuitMessage 0
  END IF
  ProcessWindow = DefWindowProc(hdlg, wMsg, wParam, lParam)  
END FUNCTION


  FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _
                    BYVAL hPrevInstance AS LONG, _          
                    szCmdLine           AS STRING, _    
                    BYVAL iCmdShow      AS LONG) AS LONG    

    DIM wMsg       AS Msg      
    DIM wcls AS wndclass  
    DIM hWnd      AS unsigned LONG        
    DIM szpgmname AS STRING, style as long

                
     szpgmname = "FreeBasic GUI Samples"
     WITH wcls
         .style         = CS_HREDRAW OR CS_VREDRAW OR CS_DBLCLKS
         .lpfnWndProc   = @ProcessWindow  'point to callback code  
         .cbClsExtra    = 0  
         .cbWndExtra    = 0  
         .hInstance     = hInstance  
         .hIcon         = LoadIcon( hInstance, "MAINICON" )
         .hCursor       = LoadCursor( NULL, BYVAL IDC_ARROW )
         .hbrBackground = COLOR_MENU +1
         .lpszMenuName  = NULL
         .lpszClassName = STRPTR(szpgmname)
     END WITH
     RegisterClass wcls
          style =   WS_VISIBLE OR WS_OVERLAPPEDWINDOW OR  DS_MODALFRAME

          hWnd = CreateWindowEx(0, szpgmname, "Regular SDK Example", _
                                Style,  70,  45,  650,  485, _
                                HWND_DESKTOP, NULL, hInstance, BYVAL NULL)

     WHILE (GetMessage(wMsg, NULL, 0, 0) <> false )    
         TranslateMessage wMsg
         DispatchMessage  wMsg
     WEND
     WinMain = wMsg.wParam
END FUNCTION


Remember, it doesn't have any effect on the resize bitmap to fit static control, no matter what the conditions are. The static control one will always work. The button one won't work and the stretch bitmap for both button and static has the same problems.

I hope this is not to confusing, I get confused thinking about it.

Later........Jerry Fielden
Found out what is going on.. seems like GetObject only copies the bitmap struct if it's aligned to a dword boundary, as that buff string is 10+1 (all FB strings have a char more for the null-terminator), the variables following it will be "disaligned" on stack, making GetObject fail for some weird reason.

I changed the allocation so all local vars will be aligned on dword boundary now, it worked fine that way, no fake strings were needed..

While the new release is not out, you can fix it using dim buff1 as string * 11, but then the file saved will have a byte more on each item..
Making Buff1 *11, didn't fix it. I can already fix it by adding a fake one to make the total number of DIM AS * Number an uneven total.

I wasn't talking about how much the string was dimmed at, I was talking about the total number of them in the program. When there is an Odd/uneven number of them all bitmaps work correctly. When there is an Even number of them, only one works and thats the one for the STATIC controls resize label to fit bitmap.

I'll give you another example in case you didn't quite understand.

When I have this many Dims in the program:

dim buff1 as string * 11 ............ only 1 of them

All bitmaps work.

---------------------------------------------------

When I have this many:

dim buff1 as string * 11 ............ only 2
DIM Fake1 AS STRING * 1 ............ an even number of them

All quit working except the one for STATIC

-------------------------------------------------------------

When I have this many

dim buff1 as string * 11 ............ 3 of them
DIM Fake2 AS STRING * 1 ............ an uneven number
DIM Fake3 AS STRING * 10

They all start working again

--------------------------------------------------------------
this many

dim buff1 as string * 11
DIM Fake4 AS STRING * 10
DIM Fake5 AS STRING * 10 ............ 4 of them, even number
DIM Fake6 AS STRING * 10

quit working
---------------------------------------------------------------

dim buff1 as string * 11
DIM Fake4 AS STRING * 10
DIM Fake5 AS STRING * 10 ............ 5 of them
DIM Fake6 AS STRING * 10
DIM Fake7 AS STRING * 10

working again
-----------------------------------------------------------------

I tried all the way up to 14 of them in my program and all uneven numbers of them worked and all the even numbers of them didn't.


Now thats Odd, :???:

Well I hope you got it fixed. Smile
Hello V3c

I'm sure you know already, that ver13 did fix this Image problem.


Thank you kind sir.....Later.........Jerry Fielden