Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

A stupid question but still...

Just what is the purpose of having WM_CUT, WM_COPY, WM_PASTE when CtrlX, CtrlC and CtrlV do the same job with no headache of programming. However, when I went in for a WM_CUT manually, for the perverse pleasure of going mad, I found it does not work. Trying to do it via a button. But no go. The SendMessage function merely removes the highlight on the data but leaves the data intact.

Why is that happening?
«1

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Just what is the purpose of having WM_CUT, WM_COPY, WM_PASTE when
    : CtrlX, CtrlC and CtrlV do the same job with no headache of
    : programming. However, when I went in for a WM_CUT manually, for the
    : perverse pleasure of going mad, I found it does not work. Trying to
    : do it via a button. But no go. The SendMessage function merely
    : removes the highlight on the data but leaves the data intact.
    :
    : Why is that happening?
    :

    These messages are to be sent only to Edit Controls or Combo Boxes. Did you make a selection in the control:

    [link=http://msdn.microsoft.com/en-us/library/ms649023(VS.85).aspx]http://msdn.microsoft.com/en-us/library/ms649023(VS.85).aspx[/link]
  • toddlerasimtoddlerasim Member Posts: 93
    : : Just what is the purpose of having WM_CUT, WM_COPY, WM_PASTE when
    : : CtrlX, CtrlC and CtrlV do the same job with no headache of
    : : programming. However, when I went in for a WM_CUT manually, for the
    : : perverse pleasure of going mad, I found it does not work. Trying to
    : : do it via a button. But no go. The SendMessage function merely
    : : removes the highlight on the data but leaves the data intact.
    : :
    : : Why is that happening?
    : :
    :
    : These messages are to be sent only to Edit Controls or Combo Boxes.
    : Did you make a selection in the control:
    :
    : [link=http://msdn.microsoft.com/en-us/library/ms649023(VS.85).aspx]ht
    : tp://msdn.microsoft.com/en-us/library/ms649023(VS.85).aspx[/link]

    :In fact I sent the WM_CUT to an Edit Control after I pressed a button in a Dialog Box. The name of the Dialog Box was IDD_DIALOG1 and the Edit Control was IDC_EDIT1. The HWND was IDD_DIALOG1 but only the highlight on the selected text was removed and the text still remained. The message was sent as follows..

    SendMessage((HWND)IDD_DIALOG1,WM_CUT,0,0);

    I then changed the HWND to IDC_EDIT1 but with no change in the output. I must be dumb but I definitely would like to do the WM_CUT, DELETE etc from my Combo Box.

    Looking forward to getting some idea as to where I am going wrong.
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : : : Just what is the purpose of having WM_CUT, WM_COPY, WM_PASTE when
    : : : CtrlX, CtrlC and CtrlV do the same job with no headache of
    : : : programming. However, when I went in for a WM_CUT manually, for the
    : : : perverse pleasure of going mad, I found it does not work. Trying to
    : : : do it via a button. But no go. The SendMessage function merely
    : : : removes the highlight on the data but leaves the data intact.
    : : :
    : : : Why is that happening?
    : : :
    : :
    : : These messages are to be sent only to Edit Controls or Combo Boxes.
    : : Did you make a selection in the control:
    : :
    : : [link=http://msdn.microsoft.com/en-us/library/ms649023(VS.85).aspx]ht
    : : tp://msdn.microsoft.com/en-us/library/ms649023(VS.85).aspx[/link]
    :
    : :In fact I sent the WM_CUT to an Edit Control after I pressed a
    : button in a Dialog Box. The name of the Dialog Box was IDD_DIALOG1
    : and the Edit Control was IDC_EDIT1. The HWND was IDD_DIALOG1 but
    : only the highlight on the selected text was removed and the text
    : still remained. The message was sent as follows..
    :
    : SendMessage((HWND)IDD_DIALOG1,WM_CUT,0,0);
    :
    : I then changed the HWND to IDC_EDIT1 but with no change in the
    : output. I must be dumb but I definitely would like to do the WM_CUT,
    : DELETE etc from my Combo Box.
    :
    : Looking forward to getting some idea as to where I am going wrong.
    :
    [color=Blue]
    It is possible that when you click a button - the focus goes out of edit control and into a button. This may (or may not) cause the selection to be lost.

    I will check it on my VC++ 2005.
    [/color]
  • Ed HallEd Hall Member Posts: 395
    I played with this some yesterday, including the lost focus issue mentioned by AsmGuru62, which I believe to be true. However, SetFocus back to the edit control did not help, either. But, I do believe that's why the highlight is lost.

    In my research, I only found examples dealing with CreateWindow using the "predefined" "EDIT" class. Here's one of the example pages I found:

    http://msdn.microsoft.com/en-us/library/bb775462(VS.85).aspx

    Is it possible that in the case of dialogs, CTRL+C, X, etc., and mouse menu events are going all the way back to the message handler of the Main Window? If this is the case, perhaps there needs to be a message handler for the dialog proc, or maybe the button needs to call all the way back to the Main Window.

    Take Care,
    Ed
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444

    Ha! Finally... I can log in again.
    The problem is you're casting IDD_ and IDC_'s to HWND ...
    The ID's of the controls are internal to your program. To send Window messages, you'll need to know the Window Handle (HWND).
    What you can do is store the hWnd returned by the CreateWindow function.
    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • Ed HallEd Hall Member Posts: 395
    Hi Richard,

    The OP appeared to be using a DialogBox, which is what I tried to use as well. I don't get a handle for my DialogBoxes (or I'm not recognizing one). Does this mean that a Dialog box won't work, or is there a method to obtain the handle from the CreateWindowEx that the DialogBox invokes (or am I just missing something obvious)?

    Take Care,
    Ed
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : Hi Richard,
    :
    : The OP appeared to be using a DialogBox, which is what I tried to
    : use as well. I don't get a handle for my DialogBoxes (or I'm not
    : recognizing one). Does this mean that a Dialog box won't work, or
    : is there a method to obtain the handle from the CreateWindowEx that
    : the DialogBox invokes (or am I just missing something obvious)?
    :
    : Take Care,
    : Ed
    :

    Took some browsing (because I forgot the exact name), but use the GetDlgItem function: [link=http://msdn.microsoft.com/en-us/library/ms645481(VS.85).aspx]http://msdn.microsoft.com/en-us/library/ms645481(VS.85).aspx[/link]
    This accepts ID's. Dialogs in Windows are a special type of resource, and are stored in the application's executable file as a resource template. The system then created the dialog for you from this template, using the ID's you specify.
    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [code]
    SendMessage((HWND)IDD_DIALOG1,WM_CUT,0,0);
    [/code]
    [color=Blue]omg!.. I missed this one ^^^ completely!
    Of course, ID is not a handle. You need GetDlgItem() here:
    [/color]
    [code]
    SendMessage (GetDlgItem (hDlg, IDC_EDIT1), WM_CUT, 0, 0);
    [/code]
  • Ed HallEd Hall Member Posts: 395
    Thanks Guys,

    It worked perfectly for me. Hopefully toddlerasim will have as good results as mine.

    Take Care,
    Ed
  • toddlerasimtoddlerasim Member Posts: 93
    : Thanks Guys,
    :
    : It worked perfectly for me. Hopefully toddlerasim will have as good
    : results as mine.
    :
    : Take Care,
    : Ed
    :
    Nope it isn't working for me. But since Ed has got it working then the problem is at my end. I will work at it and if I cant manage it I am going to go against my own code of conduct and ask for the coding. And Lundin, please, pretty polly please don't delete this post.
«1
Sign In or Register to comment.