May 15, 2024, 01:47:18 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Another custom control question

Started by LarryMc, August 08, 2008, 01:51:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

I have a custom control that has a button in it and I want to change the look based upon a left mouse up/down.

I know I trap WM_LBUTTONDOWN and WM_LBUTTONUP inside my control.

Question is how to pass the button press properly to the parent window handler?

Do I use this sort of code inside the case of the control and return 0
   NMHDR nmhdr
   nmhdr.hwndFrom = hWnd
   nmhdr.idFrom   = GetDlgCtrlID(hWnd)
   nmhdr.code     = code
  return(SendMessage(GetParent(hWnd), WM_NOTIFY, nmhdr.idFrom, &nmhdr))

or do I set up message,lparam,and hparam, and let it fall thru to the
return(DefWindowProc(hWnd, uMsg, wParam, lParam))

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Left mouse up/down on the button, or in the control.  Assuming there is more than the button there.

If on the button then you will need to subclass the button itself.  And pass the messages back to the replaced handler.

Paul.
Ionic Wind Support Team

LarryMc

My button in my control is going to be a custom looking, draw my on buttton.

I guess the best way for me to ask my question is this way.

I want to create my own custom type of button with it's own class name.
Therefore I want to pass the button presses to the parent window.

I've done the capturing the button presses in a custom control before by using regions but I've never tried to send the press to the parent for use in response to my control.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

If you just want to send a button press then it would be:

SendMessage( hwnd, WM_COMMAND, button_id, button_handle)

Emergence windows also respond to:

SendMessage( hwnd, @IDCONTROL, button_id, button_handle)

hwnd = the handle to the parent window
WM_COMMAND = 0x111

Buttons don't use NMHDR's.  If there is a custom notification code you OR it in with the wParam shifted left 16 bits.

SendMessage( hwnd, WM_COMMAND, button_id | (notify_code << 16) , button_handle)

Paul.
Ionic Wind Support Team

LarryMc

That's exactly what I needed to know.

Thanks for taking the time at this late hour.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Inside a custom control I can use GetParent(hwnd).

This gives me the handle for the controls parent.

How can I determine if the parent is a window or a dialog from inside the custom control?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Ionic Wind Support Team

LarryMc

I need to know the background color of the parent to fill some color in on my custom control.
I'm drawing a rectangle and then "removing" part of it.

When I do this on a dialog I don't get the dialog color.
pbkcolor=GetBkColor(GetDC(GetParent(hWnd)))
I get a color that is lighter than the dialog color.

If I use pbkcolor=getsyscolor(COLOR_MENU)then it looks right.
So I need to know when to use the latter.
And I would know that if I knew whether or not the parent is a dialog.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Larry,
Probably because the background color has nothing to do with the client color of a dialog, or window for that matter.  It is used by Windows DC when filling in the solid portions of fonts, rectangles, etc.

The correct way to do what you want, would probably be a little more code that you think.  As you have to get the parent DC and bitblt the rectangle you want into your controls DC, converting the coordinates of the rectangle from the parent window, to screen coordinates, to your client coordinates.

Lets see...

I've only done this for non-autodrawn custom controls, in the @IDPAINT handler.

GetSize control_win,_x,_y,_w,_h
pt.x = _x
pt.y = _y
ScreenToClient(parent_hwnd,pt)
UINT hDC:_hDC = GetHDC(control_win)
UINT parenthDC:_parentHDC = GetDC(parent_hwnd)
BitBlt(hDC,0,0,_w,_h,_parentDC,pt.x,pt.y,SRCCOPY)
...release the DC's

Then draw your control on top of that. 

Probably best to invalidate the rect your grabbing from the parent, so it redraws before you grab the bits from the rectangle.

This way if the background of the parent is not a solid color, like it has some bitmap under your control, or the user is using themes or Vista, then the transparent effect looks correct.

Paul.
Ionic Wind Support Team

LarryMc

Thanks,
I would have never figured that out.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Still haven't gotten it to work

Have this in my WM_CREATE section for my custom control  that is a child of a dialog and is working fine except I can't get the color of the pixel located on the parent before I initially draw my control.
GetWindowRect(hwnd,rc)
l = rc.left
t = rc.top
w = rc.right - rc.left
h = rc.bottom - rc.top
pt.x = l
pt.y = t
phwnd=getparent(hwnd)
ScreenToClient(phwnd,pt)
hdc2 = GetDC(hwnd)
phDC=GetDC(phwnd)
BitBlt(hdc2,0,0,w,h,phdc,pt.x,pt.y,SRCCOPY)
#g_dat.parent_bk_color =_GetPixel(hdc2,2,2)
print #g_dat.parent_bk_color                         /*4294967295  */

unRgb(#g_dat.parent_bk_color>>8,r,g,b)
print r,g,b                                                     /*  255,255,255  */
releasedc(GetParent(hWnd),phDC)
releasedc(hWnd,hDC2)

I guess I'm in over my head again.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Like I had mentioned you need to do that in @IDPAINT.  WM_CREATE is sent before your window has been shown, and it is not totally initialized at that point.  Things like BitBlt most likely won't work.

Paul.
Ionic Wind Support Team

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Worked like a champ.

Thanks again

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Thats good...considering I typed it from memory ;D
Ionic Wind Support Team

LarryMc

Instead of creating another custom control question I'll just tack my new question on to this one.

When I create my custom control I'm using _GetWindowLong(hWnd, GWL_USERDATA) to store information about that instance of the control.
In    select uMsg
      case WM_CREATE
I allocate the memory for the UDT whose pointer is stored in  GWL_USERDATA.
The scheme has worked great for me.

What I want to know is would I be asking too much to open a file and retrieve information to store in my UDT for that given instance. I would be doing it during WM_Create.
Right now I'm having to hardcode an awful lot of information in my .lib source.
Seems like if I could do the file thing that it would allow me to add additional variations of my custom control just by updating an external data file.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

I don't see any problem with it.

Paul.
Ionic Wind Support Team

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library