how can I assign this values then I could deside where and when to create and paint.

Dani AI

Generated

Short answer: those messages come from Windows. asked how to “assign” them to control when creation and painting happen; correctly pointed to the API that drives that behavior. The important part is how Windows generates and delivers those messages, not treating the numeric constants as something to fabricate.

WM_CREATE is sent by the system as part of the window creation sequence (it is delivered synchronously during CreateWindow/CreateWindowEx). WM_PAINT is a posted message that the system enqueues when a window’s update region is non‑empty; handling it normally requires the BeginPaint/EndPaint pair. See the official docs for details on WM_CREATE and WM_PAINT and on how the Windows message queue works: WM_CREATE, WM_PAINT, about messages and message queues.

Practical implications:

  • Initialization and resource allocation belong in the creation path (WM_CREATE or earlier), and cleanup in WM_DESTROY.
  • Painting code belongs in WM_PAINT and must validate the update region (BeginPaint/EndPaint). For an immediate redraw, mark the region with InvalidateRect and call UpdateWindow rather than posting WM_PAINT manually.
  • For thread-to-window notifications, post a custom message (WM_USER+n) to the window thread instead of faking system messages.

Troubleshooting notes:

  • If WM_PAINT never arrives, check the thread’s message loop and whether BeginPaint is used correctly (unvalidated regions will keep WM_PAINT posted).
  • If WM_CREATE handler returns -1 the CreateWindow call fails; inspect the CREATESTRUCT and return values.

Using the documented APIs keeps the system bookkeeping correct and avoids subtle bugs from manually posting system messages.

InvalidateRect() causes WM_PAINT message. CreateWindow() causes WM_CREATE message. You should not post either of those messages yourself but call the win32 api functions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.