Hi,
Has anyone tried adding a bitmap to a static control?
MSDN says you can do it with SS_BITMAP, there are one or two listed, but nothing that helps me in IWB.
Thanks,
Andy.
			
			
			
				Funny you should ask this.. I was just peeking into MSDN and printed to paper the page about Tab Control styles.
About your problem: MSDN also say that the bitmap must be defined in a resource file.
( https://msdn.microsoft.com/en-us/library/ms933002.aspx (https://msdn.microsoft.com/en-us/library/ms933002.aspx) )
Hope you haven't missed out that one.
Good luck!
Egil
			
			
			
				Egil,
Thanks for that, but even with it in the resource file, how do I load it into a static?
And what's the hex value for SS_BITMAP?
Andy.
			
			
			
				CONST SS_BITMAP = 0xE
Specifies that a bitmap is to be displayed in the static control. The text is the name of a bitmap (not a filename) defined elsewhere in the resource file
Brian
			
			
			
				Good morning. Here's MSDN style. Just edit the file name and adjust the static dimension to match the image size.
$INCLUDE "windowssdk.inc"
CONST STATIC_1 = 1
INT myBMP
WINDOW w1
OPENWINDOW w1,0,0,600,400,@MINBOX|@MAXBOX|@SIZE,NULL,"Simple Window",&w1_handler
WAITUNTIL w1 = 0
END
 
SUB w1_handler
	SELECT @MESSAGE
		CASE @IDCREATE
			CENTERWINDOW w1
			
			' load the image - create the static - set the image
			myBMP = LOADIMAGE (GETSTARTPATH() + "myimage.bmp", @IMGBITMAP)		
			StaticBitmapCreate(w1.hwnd, 100, 40, 256, 256, STATIC_1)
			StaticBitmapSetImage(w1.hwnd, STATIC_1, myBMP)
			
		CASE @IDCLOSEWINDOW
			' delete the image
			DELETEIMAGE(myBMP, @IMGBITMAP)
		
			CLOSEWINDOW w1
	ENDSELECT
ENDSUB
SUB StaticBitmapCreate(HWND parent, int x, int y, int dimx, int dimy, int id), INT
	INT dwStyles = WS_CHILD | WS_VISIBLE | SS_LEFT | SS_BITMAP
    RETURN CreateWindowEx(0, "STATIC", "", dwStyles, x, y, dimx, dimy, parent, id, GetModuleHandle(0), 0)
ENDSUB
SUB StaticBitmapSetImage(HWND parent, INT id, HBITMAP imagen)
	HWND handle = GetDlgItem(parent, id)
	_SendMessage(handle, STM_SETIMAGE, IMAGE_BITMAP, imagen)
ENDSUB
			
			
				Brian and Fasecero
That's brilliant guys!!!!!!!!
So here we have a static, loaded with a bitmap, and acts like a button when you click on it!
$INCLUDE "windowssdk.inc"
CONST SS_NOTIFY=0x100
CONST STATIC_1 = 1
INT myBMP
WINDOW w1
OPENWINDOW w1,0,0,600,400,@MINBOX|@MAXBOX|@SIZE,NULL,"Simple Window",&w1_handler
WAITUNTIL w1 = 0
END
 
SUB w1_handler
	SELECT @MESSAGE
		CASE @IDCREATE
			CENTERWINDOW w1
			
			' load the image - create the static - set the image
			myBMP = LOADIMAGE (GETSTARTPATH() + "tabclose.bmp", @IMGBITMAP)		
			StaticBitmapCreate(w1.hwnd, 100, 40, 256, 256, STATIC_1)
			StaticBitmapSetImage(w1.hwnd, STATIC_1, myBMP)
      CASE @IDCONTROL
         SELECT @CONTROLID
						CASE STATIC_1
						IF @NOTIFYCODE=0
							openconsole
							closeconsole
						endif
         endselect
			
		CASE @IDCLOSEWINDOW
			' delete the image
			DELETEIMAGE(myBMP, @IMGBITMAP)
		
			CLOSEWINDOW w1
	ENDSELECT
ENDSUB
SUB StaticBitmapCreate(HWND parent, int x, int y, int dimx, int dimy, int id), INT
	INT dwStyles = WS_CHILD | WS_VISIBLE | SS_LEFT | SS_BITMAP | SS_NOTIFY
    RETURN CreateWindowEx(0, "STATIC", "", dwStyles, x, y, dimx, dimy, parent, id, GetModuleHandle(0), 0)
ENDSUB
SUB StaticBitmapSetImage(HWND parent, INT id, HBITMAP imagen)
	HWND handle = GetDlgItem(parent, id)
	_SendMessage(handle, STM_SETIMAGE, IMAGE_BITMAP, imagen)
ENDSUB
Fantastic!!!
 8)
			
			
			
				Well, you guys gave me something play with. I'm assuming that the image content is not rectangular and the image background color matches the window back color (white). The following code informs the user that something will happens when clicking by changing the cursor to a HAND, and only when the cursor is not over the image empty area.
$INCLUDE "windowssdk.inc"
CONST STATIC_1 = 1
INT staticBackColor = RGB(255,255,255) ' image background color
INT myBMP
WINDOW w1
OPENWINDOW w1,0,0,600,400,@MINBOX|@MAXBOX|@SIZE,NULL,"Simple Window",&w1_handler
WAITUNTIL w1 = 0
END
 
SUB w1_handler
	SELECT @MESSAGE
		CASE @IDCREATE
			CENTERWINDOW w1
			
			' load the image - create the static - set the image
			myBMP = LOADIMAGE (GETSTARTPATH() + "myimage.bmp", @IMGBITMAP)		
			StaticBitmapCreate(w1.hwnd, 100, 40, 256, 256, STATIC_1)
			StaticBitmapSetImage(w1.hwnd, STATIC_1, myBMP)
      CASE @IDCONTROL
         SELECT @CONTROLID
			CASE STATIC_1
				IF @NOTIFYCODE=0
					openconsole
					closeconsole
				endif
         endselect
		 
	CASE WM_SETCURSOR
		INT hwndST = GetDlgItem(w1.hwnd, STATIC_1)
	
		IF @WPARAM = hwndST THEN		
			HDC hdc = GetDC(hwndST)
			
			POINT p
			GetCursorPos(p)
			ScreenToClient(hwndST, p)
			
			COLORREF colour = _GetPixel(hdc, p.x, p.y)
			
			IF colour <> staticBackColor THEN 
				SetMainCursor(LoadCursor(NULL, IDC_HAND))
				ReleaseDC(hwndST, hdc)
				RETURN TRUE
			ENDIF
					
			ReleaseDC(hwndST, hdc)
		ENDIF
			
		CASE @IDCLOSEWINDOW
			' delete the image
			DELETEIMAGE(myBMP, @IMGBITMAP)
		
			CLOSEWINDOW w1
	ENDSELECT
ENDSUB
SUB StaticBitmapCreate(HWND parent, int x, int y, int dimx, int dimy, int id), INT
	INT dwStyles = WS_CHILD | WS_VISIBLE | SS_LEFT | SS_BITMAP | SS_NOTIFY
    RETURN CreateWindowEx(0, "STATIC", "", dwStyles, x, y, dimx, dimy, parent, id, GetModuleHandle(0), 0)
ENDSUB
SUB StaticBitmapSetImage(HWND parent, INT id, HBITMAP imagen)
	HWND handle = GetDlgItem(parent, id)
	_SendMessage(handle, STM_SETIMAGE, IMAGE_BITMAP, imagen)
ENDSUB
DECLARE SetCursorTemplate(HCURSOR cursor), HCURSOR
SUB SetMainCursor(HCURSOR cursor)
	UINT hInst=LoadLibrary("user32.dll")
		
	IF hInst THEN
		UINT proc = GetProcAddress(hInst, "SetCursor")	
		IF proc THEN !<SetCursorTemplate>proc(cursor)
		FreeLibrary(hInst)
	ENDIF
ENDSUB
			
			
				If I just wanted a static control with a bitmap instead of text and I wanted it to respond to a button click then my code (based on reading the help file) would look like this:
$INCLUDE "windowssdk.inc"
CONST STATIC_1 = 1
WINDOW w1
OPENWINDOW w1,0,0,600,400,@MINBOX|@MAXBOX|@SIZE,0,"Simple Window",&w1_handler
CONTROL w1,@static,"",100, 40, 256, 256,@TABSTOP|@SS_NOTIFY|@CTLSTCBITMAP ,STATIC_1
SETCONTROLTEXT w1,STATIC_1, GETSTARTPATH + "tabclose.bmp"
WAITUNTIL w1 = 0
END
 
SUB w1_handler(),int
	SELECT @MESSAGE
		CASE @IDCREATE
			CENTERWINDOW w1
      CASE @IDCONTROL
         SELECT @CONTROLID
				CASE STATIC_1
					IF @NOTIFYCODE =0
						messagebox 0,"it works","",0
					endif
         endselect
			
		CASE @IDCLOSEWINDOW
			CLOSEWINDOW w1
	ENDSELECT
	return 0
ENDSUB
			
			
			
				Good stuff, Larry - that's the KISS method!
Brian
			
			
			
				QuoteGood stuff, Larry - that's the KISS method!
I second that!
There is one thing I don't understand though, the Static Control is defined to be 256 by 256 pixels. Therefore I expected the whole Static Control to be "active" when clicking on it. But when I tried  with a much smaller bitmap  (20x16 flag bitmap), only the program only responds when the cursor is placed inside the small bitmap. 
ther must be something I have missed.... ???
Egil
			
 
			
			
				Egil,
I have been playing around with this, and I have found that the control is automatically set to the size of the image.
So it looks like you have to set the image size, and that will make the control the same size - or at least that's how I see it at the moment.
Andy.
 
			
			
			
				Very good indeed, Larry! Sometimes I'm so deep into the winapi stuff that I tend to forget about the built-in functions a lot. Good call :)
			
			
			
				Andy, I have looked at msdn and found the following
https://docs.microsoft.com/en-us/windows/desktop/controls/static-control-styles
SS_BITMAP
The style ignores the nWidth and nHeight parameters; the control automatically sizes itself to accommodate the bitmap.