News:

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

help, show static control color and bitmap

Started by RHL, April 10, 2012, 08:03:26 PM

Previous topic - Next topic

RHL

Hello MASM forum :)
well, I ask for your help, I want to show a draw into static control color, but cannot because static control covers the drawing :/
I try with SetWindowPost Function but I could not, help me please


edit:       
I am sorry,  I forgot the instructions:
xor eax,eax
ret

in the WM_PAINT message

jj2007

What about using standard Masm32 procedures, i.e. starting with
include \masm32\include\masm32rt.inc
instead of a bunch of includes without paths in a secondary inc file that even contains .data variables?


*** Assemble using \Masm32\bin\JWasm /nologo /c /coff  /Fl /Sn /Fo "test" ***
test.inc(2) : Error A2087: Cannot open include file 'windows.inc'
test.inc(2): Included by
  Tmp_File.asm(5): Main line code
test.inc(3) : Error A2087: Cannot open include file 'kernel32.inc'
test.inc(3): Included by
  Tmp_File.asm(5): Main line code
test.inc(4) : Error A2087: Cannot open include file 'user32.inc'
test.inc(4): Included by
  Tmp_File.asm(5): Main line code
test.inc(5) : Error A2087: Cannot open include file 'Comctl32.inc'
test.inc(5): Included by
  Tmp_File.asm(5): Main line code
test.inc(6) : Error A2087: Cannot open include file 'shell32.inc'
test.inc(6): Included by
  Tmp_File.asm(5): Main line code
test.inc(7) : Error A2087: Cannot open include file 'gdi32.inc'
test.inc(7): Included by
  Tmp_File.asm(5): Main line code
test.inc(15) : Error A2102: Symbol not defined : HWND
test.inc(15): Included by
  Tmp_File.asm(5): Main line code
Tmp_File.asm(11) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(14) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(15) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(16) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(20) : Error A2102: Symbol not defined : HWND
Tmp_File.asm(21) : Error A2102: Symbol not defined : PAINTSTRUCT
Tmp_File.asm(22) : Error A2102: Symbol not defined : HDC
Tmp_File.asm(23) : Error A2102: Symbol not defined : HDC
Tmp_File.asm(28) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(31) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(34) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(37) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(49) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(53) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(56) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(58) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(59) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(60) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm(61) : Error A2159: INVOKE requires prototype for procedure
Tmp_File.asm: 74 lines, 1 passes, 16 ms, 0 warnings, 26 errors

RHL

but the code I assembled correctly, I do not know the masm32rt.inc library... : (
my problem is that static control covers the drawing


jj2007

The code assembles on your particular IDE, but not for people who do not use that software. Try this:

include \masm32\include\masm32rt.inc

DlgProc PROTO :HWND, :UINT, :WPARAM, :LPARAM

IDD_DIALOG1 equ 101

.data?
hInstance dd ?
hstatic1 dd ?
hstatic2 dd ?
mycolor dd ?
hbitmap dd ?

.code
start:


Looks better, is more transparent, and assembles correctly. Tell me if
Quote      invoke EndPaint,hstatic2,addr PAINSTR
         invoke ValidateRect, hWin, 0

fixes your problem.

RHL

jj,
thanks for u help but the static control disappears, I want my drawing on top the static control

jj2007

Bad luck - but at least the CPU doesn't run at 98%, as without the InvalidateRect. Probably the problem is hidden somewhere in the styles of the dialog. Perhaps somebody could translate them into the usual human-readable format, e.g. WS_CLIPCHILDREN etc...

#define IDD_DIALOG1 101
#define IDC_STC1 1001
#define IDC_STC2 1002
IDD_DIALOG1 DIALOGEX 6,6,358,62
FONT 8,"MS Sans Serif",0,0
STYLE 0x10CF0800
EXSTYLE 0x00000000
BEGIN
  CONTROL "",IDC_STC1,"Static",0x50000000,0,0,290,48,0x00000000
  CONTROL "",IDC_STC2,"Static",0x50000000,146,11,196,26,0x00000000
END

dedndave

#include "\masm32\include\resource.h"

#define IDD_DIALOG1 101
#define IDC_STC1 1001
#define IDC_STC2 1002

IDD_DIALOG1 DIALOGEX 6,6,358,62
FONT        8,"MS Sans Serif",0,0
STYLE       WS_VISIBLE|WS_OVERLAPPEDWINDOW|DS_CENTER
EXSTYLE     0
BEGIN
  CONTROL     "",IDC_STC1,"Static",WS_CHILD|WS_VISIBLE,0,0,290,48,0
  CONTROL     "",IDC_STC2,"Static",WS_CHILD|WS_VISIBLE,146,11,196,26,0
END


the resource.h file defines those constants for you
using them by name, rather than by number, makes it much easier to read and/or modify

dedndave

\masm32\include\masm32rt.inc, as with most INC files, is a text file
you may open it with Notepad to see what it does for you (saves a lot of typing)
do not worry if libraries are included that you do not use - they won't make any difference

dedndave

as for the paint...
the DlgProc routine receives WM_PAINT messages for the dialog box - not the control
generally, painting of the controls is handled by the OS, as they are system-defined windows
that means the WM_PAINT messages are already handled, and are not passed up the chain to the parent window

if you want to handle the WM_PAINT messages for the controls, i suggest you subclass them
with careful programming, you can probably use the same WndProc routine for all controls
that is because the PAINTSTRUCT has all the information about what needs to be painted

design your code so that the only part that is painted is the part in the PAINTSTRUCT RECT
this is a step that many guys skip over - lol
but - it makes for a fast paint routine if you only paint what the PAINTSTRUCT tells you to paint

RHL

thanks dedndave for u help and neither, static control covers the other static control (drawing)

edit:
then my code of the evening is bad, oh no I lost the time lol  :( thanks

dedndave

it's ok - as long as you are learning, it is not a waste of time   :U

MichaelW

Here is a MASM32 in-memory dialog example that uses a SS_BITMAP static control and a SS_OWNERDRAW static control, and no WM_PAINT or subclass. It appears to work OK, but note that I had very little time to code and test it so there may be some non-obvious errors.

Edit: I see now that I misunderstood what the goal of this thread is. I should have added code to my WM_DRAWITEM handler to draw something over the top of the bitmap. "Middle-aged" people just don't hurry well  :bg

Edit2: Added code to invert part of the stretched bitmap.

Note that a SS_BITMAP static control sizes itself to the bitmap. For the SS_OWNERDRAW static control I used StretchBlt to size the bitmap to the control.


;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
IDC_STC1 equ 1001
IDC_STC2 equ 1002
;==============================================================================
    .data
      hInstance HANDLE  0
      hwndSTC1  HWND    0
      hwndSTC2  HWND    0
      hBmp      HBITMAP 0
    .code
;==============================================================================

DlgProc proc uses esi edi hwndDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    LOCAL hdc:HDC, bmp:BITMAP, rc:RECT

    SWITCH uMsg

        CASE WM_INITDIALOG

            invoke GetDlgItem, hwndDlg, IDC_STC1
            mov hwndSTC1, eax
            invoke GetDlgItem, hwndDlg, IDC_STC2
            mov hwndSTC2, eax

            invoke LoadImage, 0, chr$("mypaint.bmp"), IMAGE_BITMAP,
                              0, 0, LR_LOADFROMFILE
            mov hBmp, eax

            invoke SendMessage, hwndSTC1, STM_SETIMAGE,IMAGE_BITMAP, hBmp

        CASE WM_DRAWITEM

            mov edi, lParam

            ASSUME edi:PTR DRAWITEMSTRUCT

            SWITCH [edi].itemAction

                CASE ODA_DRAWENTIRE

                    invoke CreateCompatibleDC, [edi].hdc
                    mov hdc, eax
                    invoke SelectObject, hdc, hBmp
                    push eax
                    invoke GetObject, hBmp, SIZEOF bmp, ADDR bmp
                    lea esi, bmp
                    ASSUME esi:PTR BITMAP

                    ;-----------------------------------------------------
                    ; The ASSUMEs for ESI and EDI, and the crowded layout
                    ; of the StretchBlt invoke, were necessary to avoid a
                    ; "error A2039: line too long".
                    ;-----------------------------------------------------

                    invoke StretchBlt,[edi].hdc,[edi].rcItem.left,
                                      [edi].rcItem.top,[edi].rcItem.right,
                                      [edi].rcItem.bottom,hdc,0,0,
                                      [esi].bmWidth,[esi].bmHeight,SRCCOPY

                    push 50
                    pop rc.left
                    push 30
                    pop rc.top
                    push [edi].rcItem.right
                    pop rc.right
                    push [edi].rcItem.bottom
                    pop rc.bottom
                    invoke InvertRect, [edi].hdc, ADDR rc

                    pop eax
                    invoke SelectObject, hdc, eax

            ENDSW

            ASSUME esi:NOTHING
            ASSUME edi:NOTHING

            return TRUE

        CASE WM_COMMAND

            SWITCH wParam

                CASE IDCANCEL

                    invoke EndDialog, hwndDlg, 0

            ENDSW

        CASE WM_CLOSE

            invoke EndDialog, hwndDlg, 0

    ENDSW

    return 0

DlgProc endp

;==============================================================================
start:
;==============================================================================

    invoke GetModuleHandle, NULL
    mov   hInstance, eax

    Dialog "Test", \
           "MS Sans Serif",10, \
           WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
           2,0,0,200,100,1024

    DlgStatic 0,SS_BITMAP or WS_BORDER,10,10,10,10,IDC_STC1

    DlgStatic 0,SS_OWNERDRAW or WS_BORDER,10,40,178,40,IDC_STC2

    CallModalDialog hInstance,0,DlgProc,NULL

    exit
;==============================================================================
end start



eschew obfuscation

RHL

MichaelW thanks bro, is interesant how you use the EDI register  :clap: