#1
  1. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95

    win32 windows with buttons


    I have a button class that creates a child window like this...
    hButtonWnd = CreateWindow
    (
    TEXT("button"),
    mCaption,
    WS_CHILD|BS_DEFPUSHBUTTON,...etc


    i want to take an action when the button is clicked. im trying to figure out how this button recieves messages. it does not have a WndProc. when the user does click in the space where the button is, no message gets send to the parent window WndProc. or at least not the WM_BUTTONUP messages taht are usually sent when a mouse button is clicked. reason why i have this class that doesnt fully work is b/c my teacher started working on it and never finished it, so all i have is code to create and show it.
  2. #2
  3. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    >> it does not have a WndProc.

    Yes it does. All windows with the WS_CHILD use the WNDPROC defined for the parents HWND.

    >>no message gets send to the parent window WndProc

    Did you cast the HMENU param as an int ID#?

    #define IDC_BUTTON1 40001//defined so as to not conflict with the values in resource.h (ie no repeats)
    ie (HMENU)IDC_BUTTON1

    Then msg's will be routed through the WM_COMMAND of the parents wndproc.



    Code:
    //Look for the resource ID in the msg
    idControl	= GET_WM_COMMAND_ID( wParam, lParam) ;
    //switch ctrl ID#'s
    case IDC_BUTTON1:
    if (BN_CLICKED == HIWORD(wParam))//button was clicked
    Else use

    SetWindowLong() to retrieve the current wndproc and subclass it to one you specify.

    origButtonWndProc = (WNDPROC) SetWindowLong( hButton, GWL_WNDPROC, (DWORD) NewButtonWndProc);
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  4. #3
  5. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    hey thanks man that made my life a lot easier. that's cool how easy it is to do that, i was thinking i was going to have to write a whole other wndproc. :)

    edit: do you know how i could have it so that when a user right clicks on a name in my listbox i can have a small menu pop up like windows does? i understand how to realize the right click, and how to get the idx of the name selected, but how do get the menu there? is that a window class ?
    also, i have an edit box class that is a child window as well. when the user types text into it, i want them to be able to push enter and have that send the text. when the edit box gets focus it sends a ID_ED_SEND_MSG message to my wndProc which i can handle in WM_COMMAND. but how can i obtain the action that the user took on that edit box? like if it is just a mouse click or if it is the enter which is what im looking for. i tried looking at the various wParam, lParam fields but none worked.
    Last edited by infamous41md; May 26th, 2003 at 04:07 PM.
  6. #4
  7. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    >>when a user right clicks on a name in my listbox i can have a small menu pop up like windows does?

    the LV sends WM_NOTIFY msg's. Look for NM_RCLICK in the code member of the NM_LISTVIEW struct.

    Code:
    case	WM_NOTIFY:
    switch(wParam)
    {
    	case IDC_LISTVIEW:
    	LView = (NM_LISTVIEW FAR *) lParam; 
    	switch (LView->hdr.code) 
    	{
    		case NM_RCLICK:

    or look for the WM_PARENTNOTIFY in the owners (parents) callback, depending on how you set up the Listview

    Code:
    case	WM_PARENTNOTIFY:
    if(WM_RBUTTONDOWN == (WPARAM)wParam)
    {
    	GetCursorPos(&point);//find mouse pos to display menu
    	hPopup=LoadMenu( hInst, MAKEINTRESOURCE( IDR_POPUPMENU1) );//load your menu
    hTrackPopup = GetSubMenu( hPopup, 0 );//has to be a pop-up of the menu
    iReturn = TrackPopupMenu( hTrackPopup, TPM_LEFTALIGN |TPM_RETURNCMD ,point.x ,point.y, 0, hWndParent ,0 );//find out the menu item clicked
    //process
    the menu has to be a pop-up. That is the items go down the menu (not across) with no header (top item you click to get the pop-up)


    >> i want them to be able to push enter and have that send the text.

    I would sub class the edit's WNDPROC and switch the WM_CHAR msg's.

    Look for the WM_KEYDOWN, switch them looking for the VK_RETURN.

    Make sure you have the ES_WANTRETURN | ES_MULTILINE style on the edit.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa

IMN logo majestic logo threadwatch logo seochat tools logo