;I 'll be grateful if one helps me in correcting this code. ;Sorry for long writing. ;If I tried sizing the window from right side or ;maximizing it,the gradient background is disturbed + ;disappearance of button control.If I put the code in ;WM_SIZE I got flickering. ;Thanks. .386 .model flat,stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \MASM32\INCLUDE\gdi32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \MASM32\LIB\gdi32.lib WinMain proto :DWORD,:DWORD,:DWORD,:DWORD PushButton PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD RGB MACRO red, green, blue ;; Get composite number from red green and blue bytes mov bl,blue ;; ,,,blue shl ebx,8 ;; ,,blue, add bl,green ;; ,,blue,green shl ebx,8 ;; ,blue,green, add bl,red ;; ,blue,green,red and ebx,0FFFFFFh ;; Mask out top byte to complete COLORREF dword ENDM LOWORD MACRO bigword ;; Retrieves the low word from double word argument mov eax,bigword and eax,0FFFFh ;; Set to low word ENDM HIWORD MACRO bigword ;; Retrieves the high word from double word argument mov ebx,bigword shr ebx,16 ;; Shift 16 for high word to set to high word ENDM .data ClassName db "SimpleWinClass",0 AppName db "Our First Window",0 ButtonClassName db "BUTTON",0 ButtonCaption db "First Button",0 B BYTE 0 Step BYTE 0 .data? hInstance HINSTANCE ? CommandLine LPSTR ? cxClient DD ? cyClient DD ? hButton HWND ? .Const ButtonID equ 501 .code start: invoke GetModuleHandle, NULL mov hInstance,eax invoke GetCommandLine mov CommandLine,eax invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT invoke ExitProcess,eax WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG LOCAL hwnd:HWND 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,NULL push hInstance pop wc.hInstance mov wc.hbrBackground,COLOR_WINDOW+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 INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\ WS_OVERLAPPEDWINDOW,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 WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM LOCAL hdc:HDC LOCAL hBrush:HBRUSH LOCAL rect:RECT .IF uMsg==WM_DESTROY invoke PostQuitMessage,NULL .ELSEIF uMsg==WM_CREATE invoke PushButton,ADDR ButtonCaption,hWnd,20,20,100,25,ButtonID mov hButton,eax .ELSEIF uMsg==WM_SIZE LOWORD lParam mov cxClient, eax HIWORD lParam mov cyClient, ebx mov rect.left,0 mov rect.top,0 mov eax,cxClient mov rect.right,eax xor eax,eax mov eax,cyClient mov Step,63 DIV Step mov Step,al mov esi,64 mov B,255 .WHILE esi > 0 RGB 0,0,B invoke CreateSolidBrush, ebx mov hBrush, ea
Posted on 2001-05-24 20:12:00 by a.nada
memory DC should solve the flickering problem, see iczelion's tutorials for examples. if you're aiming for win98/w2k only, you could use GradientFill. also, you should do the painting on WM_ERASEBKGND in this case, i think (and call InvalidateRect from WM_SIZE).
Posted on 2001-05-25 06:04:00 by fresh
Much Thanks Fresh. The code improved much by using your advice. Trying to use memory DC I failed. Flicker now is limited as if the drawing is executed just twice. Thanks for the api GradientFill ,I donot know it. I found it in the MSDN. Hope you to find help if needed. A Nada
Posted on 2001-05-26 19:08:00 by a nada
You can try this in your WndProc:


xor eax,eax
Posted on 2001-05-27 00:30:00 by buliaNaza
the memory DC was the important part here ;) look at iczelion's tutorial to see how to implement one (basically CreateCompatibleDC and CreateCompatibleBitmap).
Posted on 2001-05-27 04:41:00 by fresh