NO

Author Topic: StatusBar - insert CheckBoxes or Buttons  (Read 8709 times)

sergey

  • Guest
StatusBar - insert CheckBoxes or Buttons
« on: January 16, 2013, 10:21:26 AM »
As in StatusBar to insert Buttons (and it is better CheckBoxes) with Text-labels: SNAP, GRID, ORTHO... As on a screenshot?

That by pressing by a mouse these pseudo-buttons functions corresponding to them (I know these functions) were caused.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2098
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #1 on: January 16, 2013, 02:19:31 PM »
Just create PUSHLIKE AUTOCHECKBOX buttons to statusbar
Code: [Select]
HWND hButton = CreateWindowEx(0, WC_BUTTON, TEXT("SNAP"),
WS_CHILD | WS_VISIBLE| BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT
, 50, 3, 50, 20,
hStatus, (HMENU)4000, hInst, NULL);
SendMessage(hButton, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
hButton = CreateWindowEx(0, WC_BUTTON, TEXT("GRID"),
WS_CHILD | WS_VISIBLE| BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT
, 100, 3, 50, 20,
hStatus, (HMENU)4001, hInst, NULL);
SendMessage(hButton, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
« Last Edit: January 16, 2013, 02:24:47 PM by timovjl »
May the source be with you

CommonTater

  • Guest
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #2 on: January 16, 2013, 03:44:22 PM »
It's not really obvious in Timo's code ... but you just create the status bar as a child of your main window, then create the buttons as child windows of the status bar.   (Note the hStatus value in Timo's example)
 


 

sergey

  • Guest
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #3 on: January 16, 2013, 06:03:09 PM »
Thanks timovjl
Thanks CommonTater
Thanks, you have very well helped me!

I yesterday and today searched on the Internet about subject programming on C, but have found very little and only on C++ (ООП).
And to understand it for me it is impossible.

Now to me it should be moved in the second section of StatusBar and to add other buttons, it is already much easier.

Here that turns out in StatusBar now:

CommonTater

  • Guest
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #4 on: January 16, 2013, 07:17:25 PM »
I yesterday and today searched on the Internet about subject programming on C, but have found very little and only on

Give this a read ....  http://forum.pellesc.de/index.php?topic=4644.msg17797#msg17797

One thing is for certain ... you can't "dumbass" your way through C programming.
« Last Edit: January 16, 2013, 07:21:31 PM by CommonTater »

sergey

  • Guest
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #5 on: January 19, 2013, 11:09:33 PM »
To ask about the help timovjl it is already awkward, but a problem much more above level of my knowledge.

Buttons in StatusBar are, they are pressed and pushed out, but ANYTHING more don't do.

On the Internet and in textbooks almost all examples for StatusBar show only as in it to place the text.
Has found 2 examples which place in StatusBar EditBox and ComboBox.
But these examples again on C ++ they create the classes.
Examples MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb760726%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775583%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775494%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775941%28v=vs.85%29.aspx
 as always very foggy, I have altered an example from listView into Buttons - it doesn't work.
Has checked up the most different variants for reception of messages from the created buttons - they don't work.
At me such impression that the program doesn't receive ANYTHING from these buttons.

To dispel doubts, I have moved these buttons from StatusBar in Clien-area of main window. And then all these buttons began to work.
But to allocate for them space in the main window it is impossible - the empty seat isn't present. Therefore all xxxx-CAD systems use for them StatusBar (it practically the standard).
---------------------------------------------------------------------

In func. WndProc() case WM_NOTIFY call CALLBACK WndStatusBar() and I see my debug MessageBox() - NOT more.

Fragments of code:
from main.h
-----------
HWND   hwMain;     // Main window
HANDLE hLcWnd;     // Design window  hwndChild2
HANDLE hLcCmd;     // Command window  hwndChild3
HANDLE hLcProp;    // Properties window  hwndChild1
HANDLE hLcDrw;     // LiteCAD drawing
HWND   hwStatBar;  // Status bar

HANDLE hView, hBlock, hLayer, hPline, hEnt, hText, hTStyle;
HWND hButton;  // Buttons in StatusBar

// Global Variables:
HINSTANCE hInst;        // current instance of main window
// ... ... ...
// Forward declarations of functions included in this code module:
ATOM  MyRegisterClass (HINSTANCE hInstance);
BOOL  InitInstance    (HINSTANCE, int);
// ... ... ...
void CALLBACK EventMouseMove (HANDLE hWnd, int Button, int Flags, int Xwin, int Ywin, double X, double Y);

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK WndStatusBar(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK Users1(HWND, UINT, WPARAM, LPARAM);  // SNK additions

LRESULT Splitter_OnLButtonDown (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
LRESULT Splitter_OnLButtonUp   (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
LRESULT Splitter_OnMouseMove   (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);

from main.c
-----------
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
// ... ... ...
   // StatusBar
//   hwStatBar = CreateWindow( STATUSCLASSNAME, TEXT("NULL"), WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
//      0,0,60,20, hwMain, (HMENU)101, hInstance, NULL );
   hwStatBar = CreateWindowEx( 0, STATUSCLASSNAME, TEXT("NULL"), WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
      0,0,60,20, hwMain, (HMENU)101, hInstance, NULL );
   if (!hwStatBar){
   return FALSE;
   }
   //SendMessage( hwStatBar, SB_SIMPLE, TRUE, 0 );  // for Simple-mode StatusBar
   //SendMessage( <HandleStatusBar>, WM_<COMMAND>, (WPARAM)<CMD-PARAM1>, (LPARAM)<CMD-PARAM2> );

   INT Parts[3];
   Parts[0] = 290;
   //Parts[1] = 10;
   Parts[1] = 610;
   Parts[2] = -1;
   SendMessage (hwStatBar, SB_SETPARTS, (WPARAM)2, (LPARAM)Parts );

   /* Create PUSHLIKE AUTOCHECKBOX Buttons in StatusBar */
   hButton = CreateWindowEx(0, WC_BUTTON, TEXT("SNAP"),
      WS_CHILD | WS_VISIBLE| BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT,
      300, 4, 50, 16, hwStatBar, (HMENU)4000, hInstance, NULL);
   hButton = CreateWindowEx( 0, WC_BUTTON, TEXT("GRID"),
      WS_CHILD | WS_VISIBLE| BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT,
      350, 4, 50, 16, hwStatBar, (HMENU)4001, hInstance, NULL );
   hButton = CreateWindowEx( 0, WC_BUTTON, TEXT("ORTHO"),
      WS_CHILD | WS_VISIBLE| BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT,
      400, 4, 50, 16, hwStatBar, (HMENU)4002, hInstance, NULL );
   hButton = CreateWindowEx( 0, WC_BUTTON, TEXT("POLAR"),
      WS_CHILD | WS_VISIBLE| BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT
      , 450, 4, 50, 16, hwStatBar, (HMENU)4003, hInstance, NULL );
   hButton = CreateWindowEx( 0, WC_BUTTON, TEXT("OSNAP"),
      WS_CHILD | WS_VISIBLE| BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT,
      500, 4, 50, 16, hwStatBar, (HMENU)4004, hInstance, NULL );
   hButton = CreateWindowEx( 0, WC_BUTTON, TEXT("LWT"),
      WS_CHILD | WS_VISIBLE| BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT,
      550, 4, 50, 16, hwStatBar, (HMENU)4005, hInstance, NULL );
// ... ... ...
   return TRUE;
}
/* end of InitInstance() */


LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// ... ... ...
   case WM_NOTIFY:  // bipass control to callback-function WndStatusBar()
   WndStatusBar( hWnd, message, wParam, lParam); break;
   break;
// ... ... ...
  return 0;
}
/* end of CALLBACK WndProc () - main window processing */


//LRESULT CALLBACK WndStatusBar(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK WndStatusBar(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
MessageBox( NULL, TEXT("... NOW in WndStatusBar ..."), NULL, MB_OK );  // Error-Message
//   UNREFERENCED_PARAMETER(lParam);
NMHDR nmh;
nmh.code = NM_CLICK;    // Message type defined by control.
nmh.idFrom = GetDlgCtrlID(hWnd);
nmh.hwndFrom = hWnd;
SendMessage( GetParent(hWnd), WM_NOTIFY, (WPARAM)hWnd, (LPARAM)&nmh );

   switch (message)
   {
   case WM_NOTIFY:
      switch (((LPNMHDR)lParam)->code)
      // or lParam)->idFrom = GetDlgCtrlID(m_controlHwnd)
      // or lParam)->hwndFrom = m_controlHwnd
      {
      case NM_CLICK:
         if (((LPNMHDR)lParam)->idFrom == IDC_GRID)
         {  // Respond to message
            SendMessage(hButton, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
            MessageBox(NULL, TEXT("the button GRID is clicked."), TEXT("Event"), MB_OK|MB_ICONINFORMATION);
            lcWndExeCommand( hLcWnd, LC_CMD_SW_GRID, 0 );
             return TRUE;
         }
         break;
      // More cases on WM_NOTIFY switch.
      }
      break;

   //case BN_CLICKED:  // Notification message from Button
   case NM_CLICK:  // Notification message from StatusBar
      switch (LOWORD(wParam))
      {
      case IDC_SNAP:    SendMessage(hButton, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
               MessageBox(hWnd, TEXT("the button SNAP is clicked."), TEXT("Event"), MB_OK|MB_ICONINFORMATION);
               lcWndExeCommand( hLcWnd, LC_CMD_SW_GRIDSNAP, 0 ); break;
      case IDC_GRID:    SendMessage(hButton, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
               lcWndExeCommand( hLcWnd, LC_CMD_SW_GRID, 0 ); break;
      case IDC_ORTHO:    SendMessage(hButton, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
               lcWndExeCommand( hLcWnd, LC_CMD_SW_ORTHO, 0 ); break;
      case IDC_POLAR:    SendMessage(hButton, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
               lcWndExeCommand( hLcWnd, LC_CMD_SW_POLAR, 0 ); break;
      case IDC_OSNAP:    SendMessage(hButton, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
               lcWndExeCommand( hLcWnd, LC_CMD_SW_OSNAP, 0 ); break;
      case IDC_LWT:    SendMessage(hButton, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), 0L);
               lcWndExeCommand( hLcWnd, LC_CMD_SW_LWEIGHT, 0 ); break;
      }
      break;
   }
   return (INT_PTR)FALSE;
}
// end of CALLBACK WndStatusBar()

Buttons and MessageBox "the button SNAP is clicked."  not works (!?)
« Last Edit: January 19, 2013, 11:28:08 PM by sergey »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2098
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #6 on: January 20, 2013, 04:36:23 PM »
Use SubClassing:
Code: [Select]
LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
WNDPROC OldStatusWndProc = 0;
After creating StatusBar
Code: [Select]
OldStatusWndProc = (WNDPROC)SetWindowLongPtr(hStatus, GWLP_WNDPROC, (LONG_PTR)StatusWndProc);
Code: [Select]
LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_COMMAND:
PostMessage(GetParent(hWnd), WM_COMMAND, wParam, lParam);
break;
}
return CallWindowProc(OldStatusWndProc, hWnd, uMsg, wParam, lParam);
}
May the source be with you

sergey

  • Guest
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #7 on: January 20, 2013, 07:42:13 PM »
Big, big to you thanks, timovjl!!!

To me there was a word "SubClassing" but I have understood nothing.
I and now don't understand, how it works.
BUT IT WORKS! Besides began to work right after addition of these of 10 lines of code.

I will attentively read that such "SubClassing".
Possibly it is a way to solve some challenges connected with absence (and simultaneously with necessity) classes in nonclassed C (Pelles-C, LCC...)
« Last Edit: January 20, 2013, 10:07:19 PM by sergey »

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #8 on: January 20, 2013, 09:08:00 PM »
Big, big to you thanks, timovjl!!!

To me there was a word "SubClassung" but I have understood nothing.
I and now don't understand, how it works.
BUT IT WORKS! Besides began to work right after addition of these of 10 lines of code.

I will attentively read that such "SubClassung".
Possibly it is a way to solve some challenges connected with absence (and simultaneously with necessity) classes in nonclassed C (Pelles-C, LCC...)
First of all, be aware that timovjl is talking about "SubClassing" (not SubClassung!)
And in this regard, it is referring to a Windows feature rather than a specific programming language feature...

And some basic info about Windows (Control) Subclassing can be found at http://msdn.microsoft.com/en-us/library/windows/desktop/bb773183%28v=vs.85%29.aspx

Ralf

sergey

  • Guest
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #9 on: January 20, 2013, 10:18:01 PM »
Jawohl, Herr Oberst ! Alles ist schon gerichten!

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #10 on: January 21, 2013, 12:50:00 AM »
Jawohl, Herr Oberst ! Alles ist schon gerichten!
Und wenn es schlimmer wird, tun wir ein Läppchen drauf...

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #11 on: January 23, 2013, 02:33:39 AM »
You are bad, boys ::ROFL::
---
Stefan

Proud member of the UltraDefrag Development Team

sergey

  • Guest
Re: StatusBar - insert CheckBoxes or Buttons
« Reply #12 on: January 30, 2013, 11:38:55 AM »