News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to correctky process WM_PAINT

Started by xandaz, August 26, 2011, 06:45:53 PM

Previous topic - Next topic

xandaz

   i was trying to create too static controls with notify style. One for the pen color and another for the brush. i process the wm_paint message to do the painting of these controls. the thing is that when i click the foreground color static the choose color dialog doesnt appear. I found out that it works when i comment the wm_paint message processing. Can someone have a look? Thanks and bests

ToutEnMasm


xandaz

   I don't really understand... are you talking about wParam==0? I've tried it but does the same exact thing. Can you help a little more? Thanks TEM
   Best regards from X :U

qWord

your code, modified:
Quote.586   
.model flat,stdcall
option casemap:none

WinMain PROTO   :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\comctl32.inc
include \masm32\include\gdi32.inc
include \masm32\include\comdlg32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comdlg32.lib

.const

MainWindowWidth     equ     600
MainWindowHeight    equ     350

.data

hInstance       dd      ?
hMainWindow     dd      ?
MainWindowClass db      'MainWindowClass',0
MainWindowName  db      '???',0

wc          WNDCLASSEX  <sizeof wc,CS_HREDRAW or CS_VREDRAW,offset WndProc,NULL,NULL,NULL, \
                        NULL,NULL,COLOR_WINDOW,NULL,offset MainWindowClass,NULL>
StaticClass db      'STATIC',0
hStatic     dd          ?
cc      CHOOSECOLOR     <sizeof cc,?,?,0ffh,offset CustColors,CC_FULLOPEN or CC_RGBINIT,0,0,0>
CustColors  dd          040h,080h,0c0h,0ffh
            dd          4000h,8000h,0c000h,0ff00h
            dd          400000h,80000h,0c00000h,0ff0000h
            dd          40000000h,80000000h,0c0000000h,0ff000000h

currColor    COLORREF ?

.code
    start:
        invoke  GetModuleHandle,NULL
        mov hInstance,eax
        invoke  WinMain,hInstance,NULL,NULL,SW_SHOWNORMAL
        invoke  ExitProcess,eax

WinMain PROC    hInst:DWORD,hPInst:DWORD,CmdLine:DWORD,CmdShow:DWORD

    local   msg:MSG
   invoke   InitCommonControls
   
    push    hInstance
    pop     wc.hInstance
    invoke  LoadIcon,NULL,IDI_APPLICATION
    mov     wc.hIcon,eax
    mov     wc.hIconSm,eax
    invoke  LoadCursor,NULL,IDC_ARROW
    mov     wc.hCursor,eax
    invoke  RegisterClassEx,addr wc
    invoke  GetSystemMetrics,SM_CYSCREEN
    shr     eax,1
    sub     eax,MainWindowHeight/2
    push    eax
    invoke  GetSystemMetrics,SM_CXSCREEN
    shr     eax,1
    sub     eax,MainWindowWidth/2
    pop     ebx
    invoke  CreateWindowEx,NULL,addr MainWindowClass,addr MainWindowName,WS_TILEDWINDOW,\
               eax,ebx,MainWindowWidth,MainWindowHeight,NULL,NULL,hInstance,NULL
    mov     hMainWindow,eax
    invoke  ShowWindow,eax,CmdShow
    invoke  UpdateWindow,hMainWindow

msg_loop:
    invoke  GetMessage,addr msg,NULL,0,0
    or      eax,eax
    jz      end_msg_loop
    cmp eax,-1
    je end_msg_loop
    invoke  TranslateMessage,addr msg
    invoke  DispatchMessage,addr msg
    jmp     msg_loop
end_msg_loop:
    mov     eax,msg.wParam
    ret

WinMain     endp

WndProc PROC  uses ebx  hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
local hBr:HBRUSH

    .if uMsg==WM_DESTROY
        invoke  PostQuitMessage,NULL
   .elseif   uMsg==WM_CREATE
      mov      edi,lParam
      .if   [edi.CREATESTRUCT].hWndParent==NULL
            invoke    CreateWindowEx,WS_EX_CLIENTEDGE,addr StaticClass,NULL,WS_VISIBLE or WS_CHILD or SS_OWNERDRAW or SS_NOTIFY,0,0,32,32,hWnd,10,hInstance,NULL 
            mov     hStatic,eax
            push        hWnd
            pop         cc.hwndOwner
        .endif
        
        mov currColor,0ffffffh ; color = white
    .elseif uMsg==WM_DRAWITEM
       mov ebx,lParam
       mov eax,[ebx].DRAWITEMSTRUCT.hwndItem
       .if eax == hStatic
          invoke CreateSolidBrush,currColor
          mov hBr,eax
          invoke FillRect,[ebx].DRAWITEMSTRUCT.hdc,ADDR [ebx].DRAWITEMSTRUCT.rcItem,hBr
          invoke DeleteObject,hBr
         mov eax,1
         ret
       .endif
      xor eax,eax
      ret
    .elseif     uMsg==WM_COMMAND
        mov     eax,wParam
        ror     eax,16
        .if ax==STN_CLICKED
            rol eax,16
            .if ax==10
                invoke  Beep,200,20
                invoke  SetFocus,hWnd               
                invoke  ChooseColor,addr cc
               .if eax
                  push cc.rgbResult
                  pop currColor
                  invoke InvalidateRect,hWnd,0,TRUE
               .endif
            .elseif ax==20
                invoke  Beep,400,20
            .endif                               
        .elseif ax==STN_DBLCLK
            rol     eax,16
            .if     ax==20
                invoke  Beep,600,20
            .endif
        .endif                                       
    .else
        invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
    .endif
    xor eax,eax
    ret

WndProc     endp
end   start
FPU in a trice: SmplMath
It's that simple!

baltoro

XANDAZ,    
When you call UpdateWindow in your code, the system sends the WM_PAINT message to the window's Window Procedure, if there is a region that has been invalidated. It's not intuitive, at all. What you have to do is call GetClientRect and pass the RECT structure to InvalidateRect otherwise there is nothing to paint, and the WM_PAINT message is not sent. And, the WM_PAINT handler should only be composed of code that paints the client area of the Window.
You can call GetUpdateRect to determine if there is an update region.

:bg Looks like QWORD has come up with the optimal solution, as always,...  :bg
Baltoro

xandaz

   thanks guys. As usually you didnt let me down.
   Hail M32...
   Best regards from X