PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Wilko Verweij on November 13, 2016, 11:12:38 AM

Title: Image static control
Post by: Wilko Verweij on November 13, 2016, 11:12:38 AM
I have a weird problem. In a program, I create two types of static controls, using CreateWindow. First type is a text static control (normal label), the second type is an image static control. The second one is loaded with a png (using code coming from FireFly-PowerBasic, translated to FreeBasic). Now when I size the window, I can move the text static control using SetWindowPos or MoveWindow API calls, but that does not work for the image static. The image disappears. How to solve that? Do I need to manually redraw the image? But how? And where?
Below are some code fragments.
First to create control, set png file and set code pointer.
tmpStyles = WS_CHILD OR WS_VISIBLE OR SS_BITMAP OR SS_REALSIZEIMAGE
  PixBetween = (WClient - 608) \ 5
  FOR I = 1 TO 6
    hMenuPNG(I) = CreateLabel(hWndMainForm, "", tmpStyles, 16 + (I - 1) * (96 + PixBetween), 30, 96, 96, NULL)
  NEXT I
SendMessage(hMenuPNG(1), STM_SETIMAGE, IMAGE_BITMAP, CAST(LPARAM, GdiPlusCreateHBITMAPFromResource("IMG_INPUT96")))
  [..] 
  SendMessage(hMenuPNG(6), STM_SETIMAGE, IMAGE_BITMAP, CAST(LPARAM, GdiPlusCreateHBITMAPFromResource("IMG_HELP96")))
  FOR I = 1 TO 6
    SetWindowLongPtr(hMenuPNG(I), GWLP_WNDPROC, CAST(LONG_PTR, @Static_MenuPNGProc))
  NEXT I

This is CreateLabel:
FUNCTION CreateLabel(BYVAL hWndParent AS HWND, BYVAL strT AS STRING, BYVAL Styles AS DWORD, BYVAL LblLeft AS LONG, BYVAL LblTop AS LONG, BYVAL LblWidth AS LONG, BYVAL LblHeight AS LONG, byval ControlID as HMENU) AS HWND
 
  FUNCTION = CreateWindow("STATIC", strT, Styles, LblLeft, LblTop, LblWidth, LblHeight, hWndParent, ControlID, 0&, 0&)
 
END FUNCTION

And this is how I try to move the controls (works for text, but image disappears):
      GetClientRect(hWndMainForm, VARPTR(RC_Client))
      'center top label
      GetWindowRect(hMenuLabelTop, VARPTR(RC))
      MapWindowPoints HWND_DESKTOP, GetParent(hMenuLabelTop), CPTR(POINT PTR, @RC), 2
      'both SetWindowPos and MoveWindow work
      'SetWindowPos(hMenuLabelTop, 0, (RC_Client.Right - RC.Right + RC.Left) \ 2, RC.Top, 0, 0, SWP_NOZORDER OR SWP_NOSIZE)
      MoveWindow(hMenuLabelTop, (RC_Client.Right - RC.Right + RC.Left) \ 2, RC.Top, ScaleX * 250, ScaleY * 18, FALSE)
      'position static controls with png
      'Needed: 6* 96 + 2* 16 (left and right) = 608
      PixBetween = (RC_Client.Right - RC_Client.Left - 608) \ 5
      'neither SetWindowPos nor MoveWindow work (well, maybe the controls move but the images disappear)
      FOR I = 1 TO 6
        SetWindowPos(hMenuPNG(I), 0, 16 + (96 + PixBetween) * (I - 1), 30, 0, 0, SWP_NOZORDER OR SWP_NOSIZE)
        'MoveWindow(hMenuPNG(I), 16, 30,96,96, FALSE)
      NEXT I


Any help is appreciated...
Title: Re: Image static control
Post by: Wilko Verweij on November 16, 2016, 09:17:43 AM
Hi,
I discovered that when I delete this line:
SetWindowLongPtr(hMenuPNG(I), GWLP_WNDPROC, CAST(LONG_PTR, @Static_MenuPNGProc))
the image displays fine and can be moved without disappearing. But then the next question is: how I can receive messages from the static control? I must overlook something simple...
Title: Re: Image static control
Post by: Wilko Verweij on November 19, 2016, 10:01:25 AM
OK, I found out could to subclass to receive messages. If anyone is interested in the code to load a PNG-file just let me know, then I will post it. It is basically only a conversion of PowerBasic code generated by FireFly-Powerbasic.