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

  • : 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]
  • : : 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.
  • : : : 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]
  • 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

  • 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
  • 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
  • : 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
  • [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]
  • Thanks Guys,

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

    Take Care,
    Ed
  • : 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.
  • Err... why would I delete it for?
  • : Err... why would I delete it for?

    Because you're evil and sadistic and get great pleasure from being the Forum Satan?


    [size=2](:P sorry... couldn't resist... you may however delete this post, though ofc you will be proving that you are truly Satan)[/size]


    Good luck with your project, and if you're still stuck post the code.
    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • : Because you're evil and sadistic and get great pleasure from being
    : the Forum Satan?

    Although that is all true, someone has to do it. Unless of course, you miss the informative posts about how to buy strange blue pills from India.

    :-)
  • :
    : Although that is all true, someone has to do it. Unless of course,
    : you miss the informative posts about how to buy strange blue pills
    : from India.
    :
    : :-)

    You're ruining a huge part of my income, you know.
    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • : :
    : : Although that is all true, someone has to do it. Unless of course,
    : : you miss the informative posts about how to buy strange blue pills
    : : from India.
    : :
    : : :-)
    :
    : You're ruining a huge part of my income, you know.
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry

    :Hey, what blue pills from India? I am from India and yet to see them here. But since they exist as you guys say, here is one for you all. Why is this august forum of programmersheaven using SendMessage to solve my problem when the more direct way would have been to use this:

    [code]SendDlgItemMessage(hDlg,IDC_EDIT1,WM_CUT,0,0);[/code]

    This does the same job and seems far more straightforward. Or am I wrong?
    And Oh yes. I got the code to work in my application. Many thanks for that.

    As an extension to this problem here is something to keep your minds off "blue pills from India".

    The messages are all hard coded with the edit control to which the WM_CUT message is to be sent. Since the edit control to be used will not be known till it is actually focused on and highlighted, how can a generalised SendMessage be sent that will determine the actual handle at run time.
Sign In or Register to comment.

Howdy, Stranger!

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

Categories