News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Help Plz

Started by mabdelouahab, October 24, 2013, 12:16:15 PM

Previous topic - Next topic

mabdelouahab

Hi;
I want to draw a shape transparent
I created the following procedure

CreateDraw proc hwnd:DWORD, x:DWORD, y:DWORD
LOCAL xySize:sxySIZE
LOCAL cxA:DWORD
LOCAL cyA:DWORD
LOCAL ghWndMain:HWND
LOCAL hdc:DWORD
LOCAL bitmap:DWORD
LOCAL memDC:DWORD
LOCAL aV:DWORD
LOCAL nV:DWORD
LOCAL graph:PVOID
LOCAL pen2:PVOID         
LOCAL blend:BLENDFUNCTION         
   

mov eax, x
mov cxA, eax
mov xySize.dWidth, eax

mov eax, y
mov cyA, eax
mov xySize.dHeight, eax

mov eax, hwnd
mov ghWndMain, eax


   invoke   GetWindowLong,ghWndMain,GWL_EXSTYLE
      or   eax,WS_EX_LAYERED
   invoke   SetWindowLong,ghWndMain,GWL_EXSTYLE,eax

   invoke GetDC,ghWndMain
   mov hdc,eax   

   invoke CreateCompatibleBitmap,hdc, cxA, cyA
   mov bitmap,eax   

   invoke CreateCompatibleDC,hdc
   mov memDC,eax   
   
   invoke SelectObject,memDC, bitmap;,hdc
   invoke ReleaseDC,ghWndMain, hdc;,hdc

   invoke GdipCreateFromHDC,memDC,ADDR graph
   invoke GdipGraphicsClear,graph,0

   For_ nV=0 To cyA
      invoke division,nV,cyA
      invoke Multipl,eax,255
       invoke GdipCreatePen1,ARGB1(100,0,0,0),FP4(0.1), UnitWorld, ADDR pen2
      invoke GdipDrawLineI,graph, pen2, 0, nV, cxA, nV
   Next


   mov blend.BlendOp,AC_SRC_OVER;
        mov blend.BlendFlags , 0;
        mov blend.AlphaFormat,AC_SRC_ALPHA;
        mov blend.SourceConstantAlpha, 190;

      invoke UpdateLayeredWindow,ghWndMain, hdc, NULL,addr xySize, memDC,addr ptZero, 0,addr blend, ULW_ALPHA;


CreateDraw endp

...............

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
   LOCAL wc:WNDCLASSEX
   LOCAL msg:MSG
   LOCAL hwnd:HWND
LOCAL gsi:GdiplusStartupInput
LOCAL gtkn:PULONG

   mov gsi.GdiplusVersion,1
   mov gsi.DebugEventCallback,0
   mov gsi.SuppressBackgroundThread,0
   mov gsi.SuppressExternalCodecs,0
   invoke GdiplusStartup,ADDR gtkn,ADDR gsi,0
   
   mov   wc.cbSize,SIZEOF WNDCLASSEX
   mov   wc.style, CS_HREDRAW or CS_VREDRAW   ; or CS_BYTEALIGNWINDOW
   mov   wc.lpfnWndProc, OFFSET WndProc
   mov   wc.cbClsExtra,NULL
   mov   wc.cbWndExtra,SIZEOF WND_DATA
   push  hInstance
   pop   wc.hInstance
   mov   wc.hbrBackground,COLOR_BTNFACE+1
   mov   wc.lpszMenuName,NULL
   mov   wc.lpszClassName,OFFSET ClassName
   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; or  or

   INVOKE CreateWindowEx,WS_EX_LAYERED,\
         ADDR ClassName,ADDR AppName,\
               NULL,CW_USEDEFAULT,\
              CW_USEDEFAULT ,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
              hInst,NULL

   mov   hwnd,eax


   invoke ShowWindow, hwnd,SW_SHOWNORMAL
   invoke UpdateWindow, hwnd
   
   .WHILE TRUE
      invoke GetMessage, ADDR msg,NULL,0,0
      .BREAK .IF (!eax)
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage, ADDR msg
   .ENDW
   
   mov     eax,msg.wParam
   ret
WinMain endp
......


   .ELSEIF uMsg==WM_CREATE
               invoke CreateDraw,hWnd,100,100
......

I got the error contained in Attachments
result...Error

Thank you for your help...

dedndave

i can't read French   :P
you should be able to use Ctrl-C to copy the text (the messagebox must have focus)
then paste it to the forum reply window

use "code" tags around code - see the # icon above the reply window
also - the Campus sub-forum is a better place to post this kind of question

that's a lot of code to draw a box (or whatever it makes)
and - shouldn't need to use GDI+, normal GDI MoveToEx and LineTo functions should work
there are also Rect and other functions to draw different shapes with a selected pen

as for being transparent - i take it you mean that the background is untouched ?
or - do you mean alpha blend (opacity)

if you draw a line - the surrounding background is not affected
maybe you can google a picture that is similar to what you want to do

jj2007

Quote from: dedndave on October 24, 2013, 12:28:26 PM
i can't read French   :P

"The memory could not be read" - he got an exception...

mabdelouahab,

First things first: Welcome to the Forum :icon14:

You should zip your code, including specific rc and inc files, and post it here. The bug should be easy to find with Olly, but without the code it's not possible.

Farabi

I used to be get used to Graphics, but for GDI+ Im not good with it. Telling him about the formula to make a transparent pixel would be an overkill for a newbie. I guess I remain silent.  :icon_mrgreen:
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

mabdelouahab

Thank you  for all

I'm not the best English Language, Sorry

I've modified the code
The procedure is called after the button is pressed
I have added other action but I have two problems:
1. Transparency does not extend behind then Main Form background, is applicable only in background, I want her to come out to the Desktop
2. I could not hide the Caption and Border of the Form

https://drive.google.com/file/d/0B5q3H3sB5u6QZXA3OXZEWFBtYnc/edit?usp=sharing

The program Zip in Attachment
Thank you for your help

avcaballero

Hello, I did something like that here, just in TinyC for the moment you'd better to download the source code and try to compile it...  :P

jj2007

This will avoid the crash:

      invoke UpdateLayeredWindow,ghWndMain, hdc, NULL,addr xySize, memDC,addr ptZero, 0,addr blend, ULW_ALPHA
   ret

CreateDraw endp


You can shorten the top of your code a bit:

include \masm32\MasmBasic\MasmBasic.inc
uselib gdiplus

CreateDraw                         PROTO   :DWORD,:DWORD,:DWORD
...


All the .model etc stuff is already done in MasmBasic.inc, except the gdiplus library. The Masm32 uselib macro takes care of that.

Nice work :t

mabdelouahab

Thank  :biggrin: avcaballero ...
Not what I'm looking for
I'm looking for transparency with the desktop
https://drive.google.com/file/d/0B5q3H3sB5u6QbC0xc1Exa1VCZzA/edit?usp=sharing

mabdelouahab

Thank jj2007  :t
I corrected the error message  :biggrin:
But I can not find the result that search for it  :(
I'm looking for transparency with the desktop

https://drive.google.com/file/d/0B5q3H3sB5u6QNEVxb25KaUxMNnM/edit?usp=sharing

Upon checking I find that transparency is only available with a black background molds

I also want to hide the Border and then Caption bar of the form

GoneFishing

Quote from: mabdelouahab on October 24, 2013, 10:15:22 PM
I also want to hide the Border and then Caption bar of the form

Maybe  this example (see screenshot)
will show you the way. It was included in the previous MASM32 package.

Also see the splashscreen example in \MASM32\examples\exampl01\splash folder

Gunther

Hi mabdelouahab,

welcome to the forum. Good work.

Gunther
You have to know the facts before you can distort them.

qWord

If per-pixel alpha values are needed, only the function UpdateLayeredWindow() must be called and WM_PAINT is gone out of use (if the window content or it's size has changed, the function must be called again). Unfortunately it seems that such windows can't have controls. Furthermore invisible pixels (alpha=0) are mouse-hit-transparent. The window region could be changed using SetWindowReg()**, if wished (the example use WS_EX_TOOLWINDOW to get a rectangular window region).
In the attachment a small example based on the above code, which shows a red point that can be drag with the mouse (close = right mouse button).
include \masm32\include\masm32rt.inc
include gdiplus.inc
includelib gdiplus.lib
.686
.mmx
.xmm

CreateDraw PROTO    :HWND
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD


ARGB1 MACRO alpha, red, green, blue
  EXITM % (alpha SHL 24) OR (red SHL 16) OR (green SHL 8) OR blue
ENDM

.data
    ClassName db "MainWinClass",0
    AppName  db "Main Window",0
.data?
    g_hInstance HINSTANCE ?
    ptZero POINT <>
.code
main proc
LOCAL CommandLine:LPSTR

    invoke GetModuleHandle, NULL
    mov    g_hInstance,eax
    invoke GetCommandLine
    mov    CommandLine,eax
    invoke WinMain, g_hInstance,NULL,CommandLine, SW_SHOWDEFAULT
    invoke ExitProcess,eax
   
main endp

CreateDraw proc hwnd:DWORD
LOCAL hdc:HDC,memDC:HDC
LOCAL bitmap:PVOID
LOCAL hBmp:HBITMAP
LOCAL graphics:PVOID,path:PVOID,brush:PVOID
LOCAL blend:BLENDFUNCTION
LOCAL rect:RECT
LOCAL color:DWORD,count:DWORD

    mov hdc,rv(GetDC,0)   

    invoke GetWindowRect,hwnd,ADDR rect
    mov edx,rect.right
    mov ecx,rect.bottom
    sub edx,rect.left
    sub ecx,rect.top
    add edx,1
    add ecx,1
    mov rect.right,edx
    mov rect.bottom,ecx
   
    invoke GdipCreateBitmapFromScan0,rect.right,rect.bottom,0,PixelFormat32bppPARGB,0,ADDR bitmap
    invoke GdipGetImageGraphicsContext,bitmap,ADDR graphics
    invoke GdipGraphicsClear,graphics,ARGB1(0,0,0,0)
   
   
    invoke GdipCreatePath,FillModeAlternate,ADDR path
    invoke GdipAddPathEllipseI,path,0,0,rect.right,rect.bottom
    invoke GdipCreatePathGradientFromPath,path,ADDR brush
    invoke GdipSetPathGradientCenterColor,brush,ARGB1(210,255,0,0)
    mov count,1
    mov color,ARGB1(0,255,0,0)
    invoke GdipSetPathGradientSurroundColorsWithCount,brush,ADDR color,ADDR count
    invoke GdipFillEllipseI,graphics,brush,0,0,rect.right,rect.bottom
    invoke GdipDeleteBrush,brush
    invoke GdipDeletePath,path
   
    mov blend.BlendOp,AC_SRC_OVER
    mov blend.BlendFlags , 0
    mov blend.AlphaFormat,AC_SRC_ALPHA
    mov blend.SourceConstantAlpha, 255
   
    mov memDC,rv(CreateCompatibleDC,hdc)
    invoke GdipCreateHBITMAPFromBitmap,bitmap,ADDR hBmp,0
    mov hBmp,rv(SelectObject,memDC,hBmp)

    invoke UpdateLayeredWindow,hwnd,0,ADDR rect,ADDR rect.right, memDC,addr ptZero, 0,addr blend, ULW_ALPHA
    invoke DeleteObject,rv(SelectObject,memDC,hBmp)
    invoke DeleteDC,memDC
   
    invoke GdipDisposeImage,bitmap
   
    ret

CreateDraw endp

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL gsi:GdiplusStartupInput
LOCAL gtkn:PULONG

    mov gsi.GdiplusVersion,1
    mov gsi.DebugEventCallback,0
    mov gsi.SuppressBackgroundThread,0
    mov gsi.SuppressExternalCodecs,0
    invoke GdiplusStartup,ADDR gtkn,ADDR gsi,0
   
    mov   wc.cbSize,SIZEOF WNDCLASSEX
    mov   wc.style, CS_HREDRAW or CS_VREDRAW
    mov   wc.lpfnWndProc, OFFSET WndProc
    mov   wc.cbClsExtra,NULL
    mov   wc.cbWndExtra,0 ;SIZEOF WND_DATA
    push  g_hInstance
    pop   wc.hInstance
    mov   wc.hbrBackground,0
    mov   wc.lpszMenuName,NULL
    mov   wc.lpszClassName,OFFSET ClassName
    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; or  or

    INVOKE CreateWindowEx,WS_EX_LAYERED or WS_EX_TOOLWINDOW or WS_EX_TOPMOST,\
            ADDR ClassName,ADDR AppName,\
             WS_VISIBLE,100,\
            100 ,200,200,NULL,NULL,\
            hInst,NULL
   
    .WHILE TRUE
        invoke GetMessage, ADDR msg,NULL,0,0
        .BREAK .IF (!eax)
        invoke TranslateMessage, ADDR msg
        invoke DispatchMessage, ADDR msg
    .ENDW
   
    mov     eax,msg.wParam
    ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
       
    .IF uMsg==WM_DESTROY
        invoke PostQuitMessage,NULL
    .ELSEIF uMsg==WM_CREATE
        invoke CreateDraw,hWnd
        ;fn CreateWindowEx,0,"button","Show",WS_CHILD or WS_VISIBLE,10,10,50,20,hWnd,0,g_hInstance,0
    .ELSEIF uMsg==WM_LBUTTONDOWN
        invoke  SendMessage,hWnd,WM_NCLBUTTONDOWN,HTCAPTION,lParam
    .ELSEIF uMsg==WM_RBUTTONUP
        invoke PostMessage,hWnd,WM_CLOSE,0,0
    .ELSE
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam       
        ret
    .ENDIF
    xor eax,eax
    ret
WndProc endp

end main


EDIT: ** WS_POPUP may be an alternative
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

qWord, what have you done??

avcaballero

Interesting, qWord :t

GoneFishing

very nice example, qWord  :t
the window looks like a breakpoint in VS  ;)
what if to add some (color / transparency / shape) animation  to it ?