PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

changing class members / background color

Hi All,

some weeks ago I (new in API programming) was beginning to try out PPL. It's very nice, because it's possible to write programs, which are running on the desktop AND the pocket PC.

In the meantime I progressed a little relating API programming. But till today I didn't succeed to change the background color or style of a window or control. (FillRect works, but is not that what I want.)

Therefore I have any questions:
How can I change the members of classes before I register this class?
I found out, that in C (I'm new in C too) I define the class as:

WNDCLASS myClass;

and allocate the needed memory as:
memset(&myClass;,0,sizeof(WNDCLASS));

Then I can already access the class members as:
myClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);

and can register the class as:
RegisterClass(&myClass;);

How I do the same in PPL?

Thank you very much for any help or suggestions.

Regards Joerg
Joerg · 19 May 2006, 13:19 UTC — PPL only for games?
Hi Kornalius,

I am programming a little "database" program, to store personal data as accounts, insurance numbers etc., using the standard Windows controls as forms, tab and text controls, labels (statics), control bar and menus, list boxes, but also the integrated encryption functionality (that's a nice thing!). I'm doing that using PPL, because I wanted to try out it. All is working fine. It needed some time more as usually, because I was new in PPL and API programming.

Therefore I'm sure, that PPL is usefull not only for games, but even to create Windows "standard" programs w/o the game API.

But because I have only little experiences relating API programming, I have still one problem, which about I already asked in this forum (three weeks ago), but unfortunately didn't get an answer till now:

ALL ELEMENTS OF THE WINDOWS ARE ONLY WHITE.
How can I change the background color of a form and of a control?

In the internet I found out, how it works in C, and I think, I understand the principle. But I didn't understand till now, how I access class members in PPL, resp. how I create at first a window class with the needed members; is there any template, predefined structure etc.? Or is this the wrong way?

I think, I understand right, that the intention of PPL is programming games at first.
But I think, that other programms, as the example above, are important too, or not?

So it would be very nice, and I would be very, very glad, if you could help me with any suggestion or example, which shows me the right way to a colored background...
Please help!

Best regards from Berlin (Germany)
Joerg.
Jeorg,

We are very close to the launch time for 1.0 of PPL, so I suspect that Kornalius is busy getting ready for that event.

In answer to your question. Your are correct in that the WinClass structure is not exposed, so you can't change the background that way. The magic of the WinClass structure is that you can define a bruch that will be used to erase the background by the default WinProc, so it just happens for you.

The default WinProc does this in response to a WM_ERASEBKGND message. This message gets sent a rectangle to draw because it has been invalidated. You could service the message yourself and return a non zero value after painting the background.

I may try this myself this weekend and post an example.

bmanske
Hi,

Yes I am very busy preparing, debugging and optimizing v1.0. Hopefully the help file will be finished soon so I can start selling PPL.

I have also worked on a project (called DataMite) I started a little while ago that will be the second product to be sold by ArianeSoft. I had a problem to solve at work and this tool proved to be the best to use with the new modifications I made. Its a data extraction tool with scripting and SQL support. I will open a web site for it soon. Comparable tools are worth 1000$, I plan on selling it for around 100$. This should help finance PPL development a little more.

Brad, you have just showed me something new. I didnt even know how to change the background color of a window myself. It would be very nice to have a little example to show how its done in PPL. Thanks in advance.
Joerg · 22 May 2006, 08:27 UTC — What I tried till now...
Hi bmanske, hi Kornalius,

thank you very much for your answers at first. Off course I understand, that there are many things to do, to finish the PPL project, and - at the same time - to start a new project.

What I tried till know relating the background color, is that:

I used the WM_PAINT and the WM_ACTIVATE messages, because this worked best in my attempts:

Code:
WM_PAINT:
SetBackground(FORM100$,RGB(0, 200, 200));
SetBackground(GROUP130$,RGB(0, 200, 200));
WM_ACTIVATE:
InvalidateRect(FORM100$, NULL, false);


During program start it is necessary to send once the WM_PAINT message to the form:

Code:
SendMessage(FORM100$, WM_PAINT, 0, 0);


The in the WM_PAINT message used subroutine "SetBackground" looks so:

Code:
Proc SetBackground(hWnd$,Farbe$)
struct (ps$, PAINTSTRUCT);
struct (rt$, RECT);
myBrush$=CreateSolidBrush(Farbe$);
hDC$=GetDC(hWnd$);
GetClientRect(hWnd$, &rt;$);
BeginPaint(hWnd$, &ps;$);
FillRect(hDC$, &rt;$, myBrush$);
EndPaint(hWnd$, &ps;$);
ReleaseDC(hWnd$, hDC$);
DeleteObject(myBrush$);
End;


I am really not sure, if this is the right way, to change the background of a form or control.
It is not working 100% properly:
- if I switch on the soft keyboard (SIP), the color disappears for the group control
- it is not possible to change the background color of a control as text box, because the text disappears.
when I mark the text, it is readable again, but the background is white again.
- I cannot change the background of statics (labels) using this way.

Best regards
Joerg
Code:
Here are my results from over the weekend.

I started working on an example that responds to the WM_ERASEBKGND message. It sounded simple, just use the Device Context that is received, get the size of the client rectangle and draw a rectangle with the colored brush of choice and return a non-zero value, like this:

Code:
WM_EraseBkGND:
struct(rc$, RECT);
hDC$ = wParam$;
GetClientRect(hWnd$, &rc;$);
SelectObject(hDC$,GetStockObject(Gray_BRUSH));
rectangle(hDC$, 0, 0, rc.Right$, rc.Bottom$);
SelectObject(hDC$,GetStockObject(WHITE_BRUSH));


I never completed this test, but I will get round to it. The reason that I took off in another direction is that the above will draw the background to a window. A form or dialog is a slightly different animal. I took the request to mean that he has a form application and wants to color the form. To do this, you need the handle the WM_CTLCOLOR* messages.

There are a bunch of WM_CTLCOLOR* messages. WM_CTLCOLORDLG, WM_CTLCOLORBTN, WM_CTLCOLORSTATIC, etc... This looks like simplicity itself but Petzold-Programming Windows 5th Ed. lists a bunch of caviates. For example, the button message only works for Buttons, not for Radio Buttons, etc... These messages are sent to the parent window of the control with the exception of the message for the dialog and it is sent to the dialog WinProc. Here is a quick example to color the form and a button:

Code:
WM_CTLCOLORDLG:
ok$ = BkBrush$; // a brush defined in the creation code
WM_CTLCOLORBTN:
hDC$ = wParam$;
SetBkColor(hDC$, 0xC0B0FF); // pink
SetTextColor(hDC$, 0xFFFFFF); // white


The problem is that nothing I have tried works. I'm including my example form. It includes a button, a static and a form. The WM_CTLCOLOR* messages are received (I left the ShowMessage statements in) for the static and the button. I don't seem to get a message for the dialog itself.

Kornalius, I think this is worth trying to get working. Look at the call to SetTextColor in the above example. You allow color selection in the PIDE when creating a control, but you hadn't found an easy way to implement the colored text on the control without subclassing... I think that this is it.

Everyone feel free to jump in with a better answer.

bmanske
Windows sends a WM_ERASEBKGND first then sends a WM_PAINT to any window when it is needed to be repainted. Every control you see on a window is a window itself just painted differently and reacting to user inputs in its own way.

Check these:

http://msdn.microsoft.com/library/defau ... ebkgnd.asp

http://msdn.microsoft.com/library/defau ... w_88ac.asp

Btw, to repaint a control, do an InvalidateRect(), dont call the WM_PAINT directly.
Here is a link with an example of using the WM_CTLCOLOR messages

http://www.winprog.org/tutorial/dlgfaq.html

I will take a stab at getting the WM_EraseBKGND to work.

bmanske
Thanks Brad.

Btw, there is a 64k limit in the editor.ppl. It's a Windows limitation of the standard Edit control. Do you think you can find a way to replace it by a RichEdit. I don't even know if it's possible on the PPC, just asking. Let me know how big of a job it will be too. I don't want you to start anything too big just before the release.