Author Topic: OxySliders - a work in progress  (Read 4755 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
OxySliders - a work in progress
« on: April 17, 2014, 03:08:16 AM »
Hello,

in order to learn about Oxygenbasic and explore a little bit the Win32 Api I started a little project which I call OxySliders1. Currently I use a modeless Dialogbox as a Main Window to see what I can do with it. When OyySliders1 is finished I will create Oxyslider2 with a Main Window to see the differrences.

Although small this project is certainly not trivial. No step for mankind but a giant leap for me. And I am surprised that I already came so far in relative short time. With help of Resed.exe (a visual resource file editor, most probably it is also part of Radasm) I created the resource dll and started coding.

This is already implemented:

Toolbar with tooltips
Menu with Hotkeys
Creating several grids
Limit Sizing the dialogbox
Correct Shuffling - using only RND might give combinations which can not be solved.
Playing the game

Only using a library would not have been of much help for me. And some problems can not be simply solved. E.g. I looked for a solution in Internet to use WM_KEYDOWN or accelerators in a dialog, yet I found the solution not in Internet but in the examples of OxygenBasic. A PreTranslateMessage in O2h?

The project is not yet finished. I would like to add:

Sound using minmidi.inc
Change the color and font of the buttons
Use and Split a picture for the buttons
Using a strategy for the assistant

Maybe somebody can help? Any suggestion, link, hint or code would be welcome. My approach in the moment is "trial and error".

Anyway, when the project will be finished I hopefully will know a little bit more about Windows.

Roland



.

Mike Lobanovsky

  • Guest
Re: OxySliders - a work in progress
« Reply #1 on: April 17, 2014, 11:34:11 AM »
Hello Roland,

Excellent results and a very clean coding style! :)

1. WM_KEYDOWN, WM_KEYUP, and WM_CHAR can't be intercepted in a DlgProc() because the Dialog window that this callback belongs to never gets keyboard focus itself. These messages are present only in a generic non-dialog frame window's WndProc() callback. So you strategy of preprocessing these messages in WinMain() is perfectly correct.

2. If you make your toolbar button strip a 256-color bitmap and use a system color COLOR_BTNFACE for the bitmap background, then you can get the toolbar button bitmap backgrounds recolored automatically to the current Windows theme on bmp load. Just use a LR_LOADMAP3DCOLORS flag in your LoadImage() call. I'm using custom themes on all my Windows platforms and your buttons don't look elegant enough to me on anything but the default theme background.

3. BS_PUSHBUTTON, BS_DEFPUSHBUTTON, or BS_PUSHLIKE styles are always drawn with the default system colors no matter what you do. WM_CTLCOLORBTN's return value (a brush handle) is ignored by these button styles.

4. The BS_OWNERDRAW style will use the brush returned by WM_CTLCOLORBTN for the custom-drawn button's background beneath the text. Everything else including borders that would reflect the button's current states and text itself will have to be drawn manually. Use WM_CTLCOLORBTN's wParam as the hDC to draw on. Use DrawFrameControl() to draw the button's borders. The context foreground and background colors refer to the button text. Use SetTextColor() and SetBkColor() calls for that. The text background color may be overridden with SetBkMode(hDC, TRANSPARENT). Use SelectObject() to select your own custom logfont (or system default GUI font from the GetStockObject() palette of objects) instead of the hDC's ugly default font. Store this default font's handle that SelectObject() returns! Use DrawText() or TextOut() to draw the button's text. Reselect the previously stored default font's handle back into hDC with another call to SelectObject() after the text is drawn! Failure to do so will lead to heavy GDI memory leaks.

In some themes, Windows might use the background brush returned by WM_CTLCOLORBTN incorrectly and cover your entire painting with that color on top of it. In this case, use FloodFill() to paint your hDC's background beneath the text manually and sumply return a system stock HOLLOW_BRUSH (a.k.a. NULL_BRUSH) instead. A hollow brush doesn't produce any visible effect on any painted device context.

5. Use SendMessage(hControl, WM_SETFONT, hLogFont, MakeLong(TRUE, 0)) to permanently select a stock font (or your own logfont) into any control that would exibit an ugly default font on creation. This however doesn't work for user-drawn controls similar to item 4 above.

6. Use SendDlgItemMessage(hDlg, ID_button, BM_SETIMAGE, IMAGE_BITMAP, hBmp) to set a bitmap to the button. Note well that the function uses button ID's rather than handles to identify specific buttons.

Hope this helps. :)

Aurel

  • Guest
Re: OxySliders - a work in progress
« Reply #2 on: April 17, 2014, 12:53:36 PM »
Well
Lot of information Mike but very good explanation as usual.  ;)

@mike
Quote
6. Use SendDlgItemMessage(hDlg, ID_button, BM_SETIMAGE, IMAGE_BITMAP, hBmp) to set a bitmap to the button. Note well that the function uses button ID's rather than handles to identify specific buttons.

One question...
I never used this api for seting bitmap on button .
Is that api function work with themed button?

Mike Lobanovsky

  • Guest
Re: OxySliders - a work in progress
« Reply #3 on: April 17, 2014, 04:56:46 PM »
Thanks for the appreciation, Aurel.

Yes, SendDlgItemMessage(hDlg, ID_button, BM_SETIMAGE, IMAGE_BITMAP, hBmp) should work for any button control, whether themed or not, on any Windows platform. It's a very basic Win32 function that's been around in the SDK since Windows 95 IIRC.

As mentioned in item 2 of my earlier message, if you use a LoadImage() call to load the bitmap that you're going to use on a button, you may also use MS Paint to fill its background with COLOR_3DFACE (see the MSDN link for the RGB() values) and re-save it as a 256-color .BMP file (that's a must!). Then LoadImage() with a LR_LOADMAP3DCOLORS flag in its proper place will re-color the bitmap automagically on load to match its background to whatever your current theme colors your buttons with. The effect we be as if you've just loaded a transparent icon rather than a bitmap; looks very professional.

My only advice however is not to abuse your GUI's with such bitmapped buttons. They are not common practice under Windows except for toolbars where they look only natural. The best-looking classical native Windows GUI's are austere enough. Whenever you see a program whose menus and buttons all have bitmaps on them like a Christmas tree, you may be 100% sure the program is a cheap Linux port. ;)

Arnold

  • Guest
Re: OxySliders - a work in progress
« Reply #4 on: April 18, 2014, 01:14:09 AM »
Hello Mike,

thank you for providing support. These hints are really very helpful for me. They also point to the direction which I will have to use and look for further information.

First of all I will change the bitmap for the toolbar. I did not realize the different appearance until I changed the background style of my Windows and compared with some other applications. This subject must not be neglected.

Roland

Mike Lobanovsky

  • Guest
Re: OxySliders - a work in progress
« Reply #5 on: April 18, 2014, 08:18:52 AM »
Glad to be of help, Roland.

@Aurel:

There's a special button style called BS_BITMAP. If you add it to your button on creation then you'll be able to add bitmaps to it on the fly with a simple call to SendMessage(hButton, BM_SETIMAGE, IMAGE_BITMAP, hBmp) where hButton is the button's handle and not a dialog control ID.

Moreover, there's also a BS_ICON button style. LoadImage() can load Windows icons too so if you have loaded a genuine icon, you can set it to a BS_ICON button with a SendMessage(hButton, BM_SETIMAGE, IMAGE_ICON, hIcon) call.


Make your GUI's prettier, gentlemen! :)  But don't overdo... ;)

Arnold

  • Guest
Re: OxySliders - a work in progress
« Reply #6 on: April 26, 2014, 04:41:54 AM »
Hello,

this is the current state of the project. And as we have to do some renovation of our flat, I must pause for a while.

Nevertheless I proudly present: Midisound for Oxysliders. Oxygenbasic is a little bit tempting: I never tried to do something with midi, but seeing MinMidi.inc I started some own experiments. Maybe the routine for the sound could be done better - I tried to use a UDT - but it does what I want.

If anything is wrong or could be improved, constructive criticism is always welcome. Although the implementation might be a little bit delayed.

Roland

.

Mike Lobanovsky

  • Guest
Re: OxySliders - a work in progress
« Reply #7 on: April 26, 2014, 12:51:46 PM »
Nice job, Roland! :)

Arnold

  • Guest
Re: OxySliders - apologies
« Reply #8 on: January 28, 2015, 08:10:43 AM »
Hello,

due to the sudden death of my brother at the end of June last year I was not able to concentrate neither on programming nor on Oxygenbasic. As he lived alone a lot of things had to be done. I must admit to be the last one now of my parents family still makes me feel sad.

As OxygenBasic has changed a little bit the last months and as I noticed some bugs in my projects I have to reinvestigate the source code.

Roland

Charles Pegge

  • Guest
Re: OxySliders - a work in progress
« Reply #9 on: January 28, 2015, 01:03:43 PM »

Hi Roland,

My deepest sympathy for the loss of your brother.

I have worked through your emailed document relating to /example/basics breakages, and replied to you, albeit rather briefly. I don't think any of them affected Oxygen's main syntax.

There can be problems with  auto-conversion - mixing strings and numbers and nesting at the same time. Its main use is to assemble strings containing labels and values, removing the need for str(...) expressions.

Arnold

  • Guest
Re: OxySliders - a work in progress
« Reply #10 on: January 28, 2015, 03:09:12 PM »
Hi Charles,

thank you for your reply. I know that everybody will experience sad situations over the years, but sometimes it is really painful.

I have posted two other messages, but by mistake I posted them in the Development section. Can I move them somehow into the Open Forum?


Roland

JRS

  • Guest
Re: OxySliders - a work in progress
« Reply #11 on: January 28, 2015, 03:25:37 PM »
Quote from: Roland
I know that everybody will experience sad situations over the years, but sometimes it is really painful.

There is no substitute for personal loss. Your strength and determination to go on is what keeps the void from consuming you.

Mike Lobanovsky

  • Guest
Re: OxySliders - a work in progress
« Reply #12 on: January 28, 2015, 04:16:36 PM »
Hi Roland,

My deepest condolences on that sorrowful occasion.

Yet we must carry on, and we must keep ourselves in good shape for what's there for us at present and in the future. Getting some distraction from our daily worries can bring a sense of satisfaction and completeness that we tend to lack at dramatic moments in our life. Leisure coding is one such pastime to help us get through; been there, seen that.