CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [win32] - how can i call the WM_DRAWITEM message?

    i'm trying call the wm_drawitem message without sucess

    Code:
    if(KeyPressed(VK_MENU)==true) SendMessage(hButton,WM_DRAWITEM,NULL,NULL);
    what i'm doing wrong?

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: [win32] - how can i call the WM_DRAWITEM message?

    See http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    wParam Specifies the identifier of the control that sent the WM_DRAWITEM message. If the message was sent by a menu, this parameter is zero.

    lParam Pointer to a DRAWITEMSTRUCT structure containing information about the item to be drawn and the type of drawing required.

    You need to pass a pointer to a DRAWITEMSTRUCT structure that contains the required info.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - how can i call the WM_DRAWITEM message?

    "wParam Specifies the identifier of the control that sent the WM_DRAWITEM message. If the message was sent by a menu, this parameter is zero."
    i belive you mean the ID... but how i get the ID?

    "lParam Pointer to a DRAWITEMSTRUCT structure containing information about the item to be drawn and the type of drawing required.


    You need to pass a pointer to a DRAWITEMSTRUCT structure that contains the required info."
    how can i get the DRAWITEMSTRUCT from actual state?

  4. #4
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - how can i call the WM_DRAWITEM message?

    heres what i did:

    Code:
    if(KeyPressed(VK_MENU)==true) SendMessage(hButton,WM_DRAWITEM,GetDlgCtrlID(hButton),MAKEWPARAM(GetDlgCtrlID(hButton),BN_PUSHED));
    but isn't working
    please tell me more

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: [win32] - how can i call the WM_DRAWITEM message?

    Quote Originally Posted by Cambalinho View Post
    heres what i did:

    Code:
    if(KeyPressed(VK_MENU)==true) SendMessage(hButton,WM_DRAWITEM,GetDlgCtrlID(hButton),MAKEWPARAM(GetDlgCtrlID(hButton),BN_PUSHED));
    but isn't working
    please tell me more
    First do NOT place more than one statement in one line. Do it like
    Code:
    if(KeyPressed(VK_MENU))
         SendMessage(hButton,WM_DRAWITEM,GetDlgCtrlID(hButton),MAKEWPARAM(GetDlgCtrlID(hButton),BN_PUSHED));
    Second, never compare something returning BOOL with TRUE nor with true. The return value of the Win API may be either 0 (FALSE) or any other non-zero integer that is interpreted as TRUE.
    After that you could debug your code and what goes wrong and why...
    Victor Nijegorodov

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: [win32] - how can i call the WM_DRAWITEM message?

    The lparam needs to be a pointer to a DRAWITEMSTRUCT as I indicated in my post #2. What you have shown in post #4 isn't a pointer for the lparam parameter. You need to initialise a struct and then pass its memory address. The format of the structure is here http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    So you need something like this
    Code:
    DRAWITEMSTRUCT dis = {0};
    //Initialise the fields for dis
    if (KeyPressed(VK_MENU))
        SendMessage(hButton, WM_DRAWITEM, (WPARAM)GetDlgCtrlID(hButton), (LPARAM)&dis);
    Are you sure you need to send this message? What are you trying to accomplish? There may be better ways of achieving it.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: [win32] - how can i call the WM_DRAWITEM message?

    WM_DRAWITEM message is...
    [ MSDN ]
    ...sent to the parent window of an owner-drawn button, combo box, list box, or menu when a visual aspect of the button, combo box, list box, or menu has changed.
    It is sent by the system when needed, and it has no sense to be directly sent from your application.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured