Help needed from José, again

Windows specific questions.
deltarho[1859]
Posts: 2698
Joined: Jan 02, 2017 0:34
Location: UK

Help needed from José, again

Postby deltarho[1859] » May 18, 2020 6:05

@Josep Roca

Hi, José - I am pulling my hair out again with WinFBX.

I have a BitMapButton and when I click on it WndProc completes a task.

I then want the bmp to be killed and replaced with another. On clicking on the 'new' bmp WndProc completes a task. The task is the opposite to clicking on the previous bmp. We basically have a toggle.

This is what I have in the rc file.

Code: Select all

101 bitmap top.bmp
102 bitmap nottop.bmp

In the code I have

Code: Select all

#Define ID_Top 1103
...
...
Function WndProc( .................
Static As Boolean Topmost = True
...
...
Case ID_Top
  IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
    If IsTrue(Topmost) then
      DestroyWindow(pWindow.ControlHandle(ID_Top))
      pWindow.AddControl("BITMAPBUTTON", , ID_Top, "#102", 94, 0, 16, 16)
      AfxRedrawWindow(pWindow.ControlHandle(ID_Top))
      SetWindowPos hDlg, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
      Topmost = False
      Messagebox hDlg, "NotTop", "Cpaths", MB_Topmost ' Testing purposes only
    Else
      DestroyWindow(pWindow.ControlHandle(ID_Top))
      pWindow.AddControl("BITMAPBUTTON", , ID_Top, "#101", 94, 0, 16, 16)
      AfxRedrawWindow(pWindow.ControlHandle(ID_Top))
      SetWindowPos hDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
      Topmost = True
      Messagebox hDlg, "Top", "Cpaths", MB_Topmost ' Testing purposes only
    End If
  End If

The two message boxes, for testing only, tell me that the callback is working and I get the topmost being toggled but the bitmap does not change from #101.

I have a feeling that DestroyWindow is not doing what I hoped it would.
deltarho[1859]
Posts: 2698
Joined: Jan 02, 2017 0:34
Location: UK

Re: Help needed from José, again

Postby deltarho[1859] » May 18, 2020 8:08

Most Windows APIs have return values, and for good reason. Muggins here should have tested DestroyWindow. I get zero so a failure. GetLatError was also zero which is most helpful - not.

With PowerBASIC's DDT I would use 'CONTROL KILL hDlg, id&'. "The control is destroyed and removed from the dialog". Well, I'm now in FreeBASIC so tough. Image

WinFBX is an extraordinary piece of work but finding stuff is time-consuming even with 'WinFBX Framework Help' in WinFBE. I also have WinFBX.chm.
SARG
Posts: 1163
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Help needed from José, again

Postby SARG » May 18, 2020 8:13

Why destroying the button ? Is it possible just to set the new bitmap ? I don't know WinFBX maybe a such function exists.

In fbdebugger it's what I do.

Creation of the button

Code: Select all

butnotes=fb_button("NOTES",windmain, IDNOTES,600,0, 30, 26)
fb_modstyle(butnotes,BS_BITMAP)
bmb(14)=Loadbitmap(fb_hinstance,Cast(LPSTR,MAKEINTRESOURCE(1014)))
SendMessage(butnotes, BM_SETIMAGE, IMAGE_BITMAP, Cast(LPARAM,bmb(14)))


Change of the bitmap.

Code: Select all

bmb(21)=Loadbitmap(fb_hinstance,Cast(LPSTR,MAKEINTRESOURCE(1021))) 'if notes changes
SendMessage(butnotes,BM_SETIMAGE,IMAGE_BITMAP,Cast(LPARAM,bmb(21)))
Josep Roca
Posts: 501
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Help needed from José, again

Postby Josep Roca » May 18, 2020 8:16

SDK guys have better techniques that killing everybody :)

This should work:

Code: Select all

DIM hBmp AS HBITMAP
IF Topmost THEN
   hBmp = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(102))
ELSE
   hBmp = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(101))
END IF
IF hBmp THEN
   DIM hButton AS HWND = GetDlgItem(hwnd, ID_Top)
   Button_DeleteBitmap(hButton)
   Button_SetBitmap(hButton, hBmp)
   Topmost = NOT Topmost
END IF
jj2007
Posts: 1728
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Help needed from José, again

Postby jj2007 » May 18, 2020 8:17

If that doesn't work, another cheap trick is to create two buttons at the same location, and to toggle their visibility with ShowWindow
deltarho[1859]
Posts: 2698
Joined: Jan 02, 2017 0:34
Location: UK

Re: Help needed from José, again

Postby deltarho[1859] » May 18, 2020 9:25

@SARG

You were on the right track.

@jj2007

Didn't need to try that

@Josep Roca

José, you are, how can I put it, on the button. Image

The only thing that you missed out was the respective 'SetWindowPos hDlg, .........'. The bitmaps changed, what I failed to do, but the topmost status did not change, what I managed to do.

Anyway, adding in the 'SetWindowPos hDlg, .........' I now have exactly what I wanted to achieve.

The problem I have with WinFBX is finding what I want. With PowerBASIC's DDT we have 54 'Control <Something or other' in PBWin Help. With 'WinFBX Framework Help' I couldn't find anything. With WinFBX.chm we have, for example, Button_SetBitmap at 'Windows Control Procedures>Button Control>Wrappers>Button_SetBitmap'. I actually went sailing past that when searching for something to ring a bell. I have been thinking for sometime to write macros for your wrappers like 'Control <Something or other'. Not only would this benefit me but anyone else coming from PowerBASIC. In fact, it would benefit those here who do not know what PB's DDT is. The macro syntax for Button_SetBitmap could be 'Control Add Image, hDlg, .........'. Perhaps I should do just that as a project 'on the side'.

Anyway, thank you, José. I will be adding this code to SetCompilerPathsII and SetCompilerSwichesII which will make UEZ happy as they are both TopMost whether we like it or not. UEZ did not. Image

With regard Cpaths, for the moment, I now have
Image

At the top tight of the client area is our bitmap. The left snapshot is TopMost and the right snapshot is not Topmost - we just click on the bitmap.

If only my programming skills were as good as my imagination. Come to think of it, it hardly ever is, oh dear!
Josep Roca
Posts: 501
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Help needed from José, again

Postby Josep Roca » May 18, 2020 9:55

@David

You should be grateful for having the "Button_xxx" wrappers. Otherwise, you will have to use

Code: Select all

DeleteObject(cast(HGDIOBJ, SendMessage(GetDlgItem(hwnd, ID_Top), BM_SETIMAGE, cast(WPARAM, IMAGE_BITMAP), cast(LPARAM, hbmp))))


I was afraid to post it :)

Frankly, CONTROL ADD IMGBUTTON is so outdated... I have a button control, implemented as a class, that is much more advanced, and also allows to use alphablended .png icons instead of these outdated bitmaps. It is the default button control used by the WinFBE visual designer. Paul adopted it because his users wanted coloured buttons.

CXpButton: https://github.com/JoseRoca/WinFBX/blob ... 20Class.md
Josep Roca
Posts: 501
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Help needed from José, again

Postby Josep Roca » May 18, 2020 10:53

My wrappers for Windows common controls follow the naming style of the ones provided in windowsx.bi and commctrl.bi. I have provided additional ones in AfxCtl.inc.

Documentation of the macros provided by the Windows headers:
windowsx: https://docs.microsoft.com/en-us/window ... /windowsx/
commctrl: https://docs.microsoft.com/en-us/window ... /commctrl/

I don't think that adding macros that follow the DDT naming style would be worthwile because if a PBer comes to FB most probably will use Paul's WinFBE visual editor and WinFormsX, that uses an OOP style similar to VB6. WinFBX is more low-level, and users that aren't skilled in the use of the Windows API prefer to fill properties and message cracking. As I never have used VB6, I prefer a lower-level approach.
deltarho[1859]
Posts: 2698
Joined: Jan 02, 2017 0:34
Location: UK

Re: Help needed from José, again

Postby deltarho[1859] » May 18, 2020 11:19

My biggest regret is staying with PB's DDT for as long as I did. Had I joined the PB forums before DDT was introduced I may have become skilled in the use of the Windows API. Having said that I have knocked out some pretty tasty GUIs with DDT but that left me in poor stead when I chose to not only use PowerBASIC. A lot of PBers are like me and there are not many now who are SDKers. It could be argued that DDT was the worse thing that Bob Zale did but PBWin 'took' off' when he did. Not that it did him much good because he was such a poor businessman he died 'up to his neck' in debt.

Jose wrote:My wrappers for Windows common controls follow the naming style of the ones provided in windowsx.bi and commctrl.bi.

OK, point taken.

Return to “Windows”

Who is online

Users browsing this forum: No registered users and 3 guests