Waitrud Weber’s blog

things and reminders for memories

Proporsal 003

In java swing source code, button needs size and message.
In the following way, the message is "Click Me..".

https://beginnersbook.com/2015/07/swing-jbutton-class/

Anyway, compiler can recognize Class of C++.
So, I created it like the button of swing.

...

// define a button
wButton button("Click Me..");

//------------------------------------------------
// Window Procedure
//------------------------------------------------
static LRESULT CALLBACK mainWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    switch ( uMsg ){
        CASE WM_CREATE:
            /*
            initialization
            */
        {
   button.setButton ( 100, 100,  200, 50 );
        }
        CASE WM_CLOSE:
            /*
            Deposition
            */
            DestroyWindow( hWnd );
        CASE WM_DESTROY:
            PostQuitMessage( 0 );
        CASE WM_PAINT:
        {
            PAINTSTRUCT ps;

   HDC hdc = BeginPaint(hWnd, &ps);
   HPEN hPen = CreatePen(PS_DASHDOTDOT, 2, NULL);
   SelectObject(hdc, hPen);


            // Button draw
   button.drawButton ( hdc );

   DeleteObject(hPen);
   EndPaint(hWnd, &ps);
        }
        CASE WM_ENDSESSION:         PostMessage( hWnd, WM_CLOSE, 0, 0 );
        ...
    }
    return 0;
}


1. Define button and set message.
 wButton button("Click Me..");
2. Set button scale(location x, location y, width, height ).
 button.setButton ( 100, 100,  200, 50 );
3. Draw button
 button.drawButton ( hdc );


Most of window toolkits omit Step:3.
Alternatively button is ridden on the Panel or Container or (etc... by the way of that pnl.addButton( button ).
Obiously this way is useful and easy, that assists computer programmer.
But Writting Drawing function in CASE WM_PAINT: is not so tough work and deos not have any difficulties, so that lets me use it.
I will not change the way soon.


----------------- wButton.cpp --------------------

int wButton::drawButton(  HDC hdc ) {

 RECT rect;

 // Calculation of right and bottom
 int right = this->x + this->width;
 int bottom = this->y + this->height;

    SetRect(&rect, this->x, this->y, right, bottom);

 SetTextColor( hdc, RGB(0 ,0, 255));
 Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
 DrawText( hdc, TEXT( this->button_name ), -1, &rect, DT_NOCLIP);

 return 1;
}

----------------- wButton.cpp --------------------

Thanks for the below. I still use it as software template.
https://blog.goo.ne.jp/masaki_goo_2006/e/d9a32b7fe29cf390597e420654868471
http://yoshiiz.blog129.fc2.com/blog-entry-208.html

My pleasure if you download the below for education.
https://github.com/WaitrudWeber/source_zip/blob/master/20180501-3rd.zip

Plese reffer to the below for compilation.
https://waitrudweber.hatenablog.com/entry/2018/05/01/005938

 

f:id:Waitrud_Weber:20180501225051p:plain