2

Say that I want to send a message to my WndProc, but I want to also send an integer.

SendMessage (m_hWnd, WM_DISPLAYCHANGE, NULL, int?);

My WndProc will receive it right? Then I want to send that lParam(integer) to a function.

case WM_DISPLAYCHANGE:
    {
         pD2DResources->OnRender(lParam);
    }
    break;

How do I send an integer as a lParam or wParam and then resend that integer to a function as a parameter?

Mickael Bergeron Néron
  • 1,472
  • 1
  • 18
  • 31
  • 2
    I think if you try basically what you're suggesting in your question (give or take some casts and their consequences), you'll be pleasantly surprised... That said, you shouldn't send WM_DISPLAYCHANGE, Windows should. Pick something from the range of messages you're allowed to send. – ta.speot.is Mar 13 '13 at 23:19
  • 1
    http://stackoverflow.com/questions/2515261/what-are-the-definitions-for-lparam-and-wparam – ta.speot.is Mar 13 '13 at 23:21
  • 1
    `LPARAM` is a typedef (currently `LONG_PTR` which itself is a typedef that, according to http://msdn.microsoft.com/en-us/library/cc230349.aspx is "a long type used for pointer precision. It is used when casting a pointer to a long type to perform pointer arithmetic." You do the math ;) – Nik Bougalis Mar 13 '13 at 23:22
  • Thank you! I didn't know it was that simple. – Mickael Bergeron Néron Mar 13 '13 at 23:25

1 Answers1

1

LPARAM and WPARAM are just a typedef for long. So an int can be sent in as it is.

SendMessage(m_hWnd, WM_DISPLAYCHANGE, NULL, (LPARAM)yourInt)

In your wnd proc you could do

pD2DResource->Render((int)lParam)

As you are sending these custom information as a part of standard windows messages (message number below WM_USER) you should be careful to not pass the LPARAM values you receive in your window proc directly to DefWindowProc (default window proc) - because yourInt might have a special meaning for that particular standard windows message. Either you could pass in a fixed value from your window proc to the DefWindowProc or look at other ways to pass more than 4 byte of information through LPARAM/WPARAM. As SendMessage is synchronous, you could possibly pass address of a struct - just like many standard windows messages do.

nanda
  • 804
  • 4
  • 8
  • Or just don't use the system's messages, they might have special meaning for message hooks. – ta.speot.is Mar 14 '13 at 00:08
  • @ta.speot.is - Yes, valid point. A wndproc hook might be expecting a resolution information in LPARAM for a WM_DISPLAYCHANGE message but if it sees a custom int value of 1 in LPARAM it might go wonky. But hooking should be written to expect anything. Also send messages across process boundaries would involve some marshalling of parameters and that might go wonky too. – nanda Mar 14 '13 at 01:16