Click here to Skip to main content
14,639,623 members
Rate this:
Please Sign up or sign in to vote.
I have a weird issue with Dialog box on Windows XP it doesn't draw correctly,

The listview doesn't redraw unless i do some thing that forces repaints like clicking on the size boarders then the listview show. But if i move the application somewhere on screen it goes hidden again.

This picture illustrates the problem

https://i.imgur.com/JPgBG8x.png



To avoid flickering i have set the WS_CLIPCHILDREN on the main dialog. The tab control is a child on the main dialog which is invoked through DialogBoxParam. And the Listview control is on another dialog which is a child and attached to the main dialog on runtime using CreateDialogParam API with the main dialog as a parent window. On Windows 7 i have no problem with the drawing except if i turn off windows composition then i get some flickering on the resize. But on windows XP the drawing is very sluggish. And the Listview doesn't update properly like it get mixed with the tab control some parts of it show if i hold left click and drag.

Any body has any clue why this happens on XP only? I have WS_EX_COMPOSITED flag set on Tab control only. But i removed it and it doesn't fix the issue. The WM_ERASEBKGND messaged is disabled to reduce flickering.


This is a picture describing what happens when the listview is not drawn correctly and i try to hold left click mouse and drag over it starts to show

https://i.imgur.com/uqcbTMF.png


Here is my code

.code

MainTabProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
	
	
	LOCAL PS:PAINTSTRUCT
	.if uMsg==WM_INITDIALOG
			
		invoke GetDlgItem,hWnd,ConnectionsLVID
		MOV ConnectionsLVHandle,EAX	
		
		invoke SendMessage,ConnectionsLVHandle,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT  OR LVS_EX_GRIDLINES,LVS_EX_FULLROWSELECT  OR LVS_EX_GRIDLINES
		mov		lvc.imask,LVCF_TEXT or LVCF_WIDTH or LVCF_SUBITEM
		mov		lvc.pszText,chr$("1")
		mov		lvc.lx, 40	
	
		mov		lvc.iSubItem, 0
		
		invoke	SendMessage, ConnectionsLVHandle, LVM_INSERTCOLUMN, 0,addr lvc	
		mov		lvc.imask,LVCF_TEXT or LVCF_WIDTH or LVCF_SUBITEM
		mov		lvc.pszText,chr$("2")
		mov		lvc.lx, 90	
	
		mov		lvc.iSubItem, 1
		invoke	SendMessage, ConnectionsLVHandle, LVM_INSERTCOLUMN, 1,addr lvc	
		
		
		mov		lvc.imask,LVCF_TEXT or LVCF_WIDTH or LVCF_SUBITEM
		mov		lvc.pszText,chr$("3")
		mov		lvc.lx, 90	
	
		mov		lvc.iSubItem, 2
		invoke	SendMessage, ConnectionsLVHandle, LVM_INSERTCOLUMN, 2,addr lvc	
		
	
		mov		lvc.imask,LVCF_TEXT or LVCF_WIDTH or LVCF_SUBITEM
		mov		lvc.pszText,chr$("4")
		mov		lvc.lx, 130	
	
		mov		lvc.iSubItem, 3
		 
		
		
		invoke	SendMessage, ConnectionsLVHandle, LVM_INSERTCOLUMN, 3,addr lvc	
		invoke  SendMessage, ConnectionsLVHandle, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER
		
		
		
		
		
		
		
	
	.elseif uMsg == WM_CTLCOLORDLG 
		
	.elseif uMsg == WM_ERASEBKGND
			MOV EAX,1
			RET
	
		
	.elseif uMsg == WM_PAINT
			
	.elseif uMsg == WM_SIZE
				
	.else
		
	.endif
	XOR EAX,EAX
	ret

MainTabProc endp
SettingsTabProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
	
	.if uMsg==WM_INITDIALOG
	.elseif uMsg == WM_CTLCOLORDLG 
		
	.elseif uMsg == WM_ERASEBKGND
		MOV EAX,1
		RET
		
						
	.else
		
	.endif
	XOR EAX,EAX
	ret

SettingsTabProc endp

DialogProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD 
	LOCAL   ts:TCITEM
	LOCAL COLOR: COLORREF
	LOCAL CLRECT:RECT
	LOCAL PS:PAINTSTRUCT 
	LOCAL hrgnUpdate: HRGN  		
	LOCAL MAXINFO:MINMAXINFO
	LOCAL pp: INITCOMMONCONTROLSEX
	.if uMsg == WM_INITDIALOG
		;Create the tabs
		
		mov		ts.imask,TCIF_TEXT OR TCIF_IMAGE

		mov		ts.lpReserved1,0
		mov		ts.lpReserved2,0
		mov		ts.iImage,0
		mov		ts.lParam,0
		mov		ts.pszText,offset TabConnections
		mov		ts.cchTextMax,sizeof TabConnections
		
		
		
		MOV pp.dwSize,sizeof pp
		mov pp.dwICC,ICC_TAB_CLASSES

		invoke InitCommonControlsEx,addr pp
		invoke ImageList_Create,20,20,ILC_COLOR32 	 OR ILC_MASK ,3,10 ;Create ImageList
		MOV ImageListHandle,EAX
		MOV EDI,EAX
		
		invoke LoadBitmap,hInstance,1
		invoke ImageList_AddMasked,EDI,EAX,0 ;Add bitmap masked
		
		
		
		
		invoke SendDlgItemMessage,hWnd,MainTabID,TCM_SETIMAGELIST,0,EDI ;Assosiate ImageList with Tabs
		invoke LoadBitmap,hInstance,2 ;Load Bitmap

		invoke ImageList_AddMasked,EDI,EAX,0 ;Add Bitmap to imagelist
		
		invoke SendDlgItemMessage,hWnd,MainTabID,TCM_SETIMAGELIST,0,EDI ;Set image on tab
		
		invoke SendDlgItemMessage,hWnd,MainTabID,TCM_INSERTITEM,0,addr ts ;Insesrt tab
		mov		ts.iImage,1
		
		mov		ts.pszText,offset TabSettings
		mov		ts.cchTextMax,sizeof TabSettings






		
		invoke SendDlgItemMessage,hWnd,MainTabID,TCM_INSERTITEM,1,addr ts ;Set image on tab
		
		invoke GetDlgItem,hWnd,MainTabID ;BUG
		mov		[MainTabHandle],eax
		
		
		invoke SendDlgItemMessage,hWnd,MainTabID,TCM_SETITEMSIZE,NULL,110 ;Extend tab width + height
		
		
;	
		invoke CreateDialogParam,hInstance,MainContentDlgID,hWnd,addr MainTabProc,0
		mov MainTabContentDialogHandle,eax
		
		
		
		
		
		
		
		
		
		
		
		
		invoke CreateDialogParam,hInstance,SettingsDlgID,hWnd,addr SettingsTabProc,0
		mov SettingsTabDialogHandle,eax
		invoke ShowWindow, SettingsTabDialogHandle,SW_HIDE
		
		
		
		
		invoke EnableThemeDialogTexture,hWnd,6
	
		invoke GetDlgItem,hWnd,1011
		
		invoke ResizeWindow,hWnd,uMsg,lParam
	
		invoke ShowWindow, MainTabContentDialogHandle,SW_SHOWDEFAULT	
		MOV Tabchoosen,0
	
			
			
		
		MOV EAX,hWnd
		MOV [DlgHandle],EAX
		invoke LoadIcon,[hInstance],1
		invoke SendMessage,hWnd,WM_SETICON,1,EAX
		
	
		
		
	

	.elseif uMsg == WM_GETMINMAXINFO 
			MOV EAX,lParam
			MOV [EAX].MINMAXINFO.ptMinTrackSize.x,874
			MOV [EAX].MINMAXINFO.ptMinTrackSize.y,466
		
	.elseif uMsg == WM_SETFONT
			MOV EAX,wParam
			MOV hfnt,EAX	
	.elseif uMsg == WM_SIZE
			
	.elseif uMsg == WM_MOUSEMOVE
		
	.elseif uMsg == WM_SIZING
			
			
		
	.elseif uMsg == WM_WINDOWPOSCHANGED
			
			invoke ResizeWindow,hWnd,uMsg,lParam
			
		
	.elseif uMsg == WM_CTLCOLORSTATIC
  				
			
	.elseif uMsg == WM_SYSCOMMAND 
			MOV EAX,wParam
			
			.if EAX == SC_MAXIMIZE
				invoke RedrawWindow,hWnd,NULL,NULL,RDW_INVALIDATE OR RDW_ALLCHILDREN 
				
			.endif	
				
	.elseif uMsg == WM_PAINT 
		
			
			invoke RedrawWindow,hWnd,NULL,NULL,RDW_INVALIDATE OR RDW_ALLCHILDREN
			
	
			invoke BeginPaint,hWnd,addr PS

			invoke Paint,hWnd,addr PS,hfnt
			invoke EndPaint,hWnd,addr PS
			
			
			
		

	.elseif uMsg == WM_SYNCPAINT
	
		invoke RedrawWindow,hWnd,NULL,NULL,RDW_INVALIDATE OR RDW_ALLCHILDREN

	.elseif uMsg == WM_ACTIVATE
		invoke RedrawWindow,hWnd,NULL,NULL,RDW_INVALIDATE OR RDW_ALLCHILDREN	
	.elseif uMsg == WM_ENTERSIZEMOVE 
		
		
		invoke RedrawWindow,hWnd,NULL,NULL,RDW_INVALIDATE OR RDW_ALLCHILDREN	
	.elseif uMsg == WM_EXITSIZEMOVE
			
	.elseif uMsg == WM_ERASEBKGND
		
		MOV EAX,1
		RET
			
	.elseif uMsg == WM_NOTIFY
        mov     edx, wParam
        .if edx == MainTabID
            mov     eax, lParam
	        mov     eax, (NMHDR ptr [eax]).code
	        .if eax == TCN_SELCHANGE
	        	invoke RedrawWindow,hWnd,NULL,NULL,RDW_INVALIDATE OR RDW_ALLCHILDREN
	            mov     ebx, Tabchoosen
	            mov     eax, [TabHandles + ebx * 4]
	            invoke  ShowWindow, eax, SW_HIDE
	            
	            invoke  SendMessage, MainTabHandle, TCM_GETCURSEL, 0, 0
	            mov     Tabchoosen, eax
	            mov     ebx, [TabHandles + eax * 4]
	            invoke  ShowWindow, ebx, SW_SHOWDEFAULT     
	        .endif             
            
        .endif	
		
		
		
		
		
		
		
		

	
	.elseif uMsg == WM_COMMAND
			
				NOP
	.elseif uMsg == WM_CLOSE
		invoke CloseHandle,[CompletionPort]
		invoke closesocket,[Listen]
		invoke EndDialog,hWnd,NULL
	
	.else
		
	.endif
	
	XOR EAX,EAX
	ret

DialogProc endp

  align 4
  Main proc 
	

	invoke GetModuleHandle,NULL
	
	MOV [hInstance],EAX
	invoke HeapCreate, NULL,4,NULL
	MOV [HeapH],EAX
	
	invoke DialogBoxParam,[hInstance],DialogBox,NULL,addr DialogProc, NULL
	ret
	
	
	
	
	
	
	

Main endp
Paint Proc hWnd:DWORD,  pPAINTSTRUCT:PPAINTSTRUCT,FNT:HFONT
	LOCAL rc:RECT ;
    LOCAL hdcMem:HDC ;
    LOCAL hBITMAP:HANDLE
    LOCAL hbmMem:HANDLE
    LOCAL hbmOld:HANDLE

    LOCAL hbrBkGnd:HBRUSH ;
    LOCAL hfntOld:HFONT ;
	
	invoke GetUpdateRgn,hWnd,addr rc,FALSE
	.if EAX == NULL
		ret
		
	.endif
	invoke GetClientRect,hWnd,addr rc
	MOV EAX,pPAINTSTRUCT
	invoke CreateCompatibleDC,[EAX].PAINTSTRUCT.hdc
	MOV hdcMem ,EAX
	MOV EAX,pPAINTSTRUCT
	
	invoke CreateCompatibleBitmap,[EAX].PAINTSTRUCT.hdc,rc.right,rc.bottom
	MOV hbmMem,EAX
	invoke SelectObject,hdcMem,hbmMem
	MOV hbmOld,EAX
	invoke GetSysColor,COLOR_WINDOW
	invoke CreateSolidBrush,EAX
	MOV hbrBkGnd,EAX
	invoke FillRect,hdcMem,addr rc,hbrBkGnd
	invoke DeleteObject,hbrBkGnd
	
	 .if FNT
	 	invoke SelectObject,hdcMem,FNT
		MOV hfntOld,EAX
	 .endif
		
	
	
	invoke SetBkMode,hdcMem,TRANSPARENT
	invoke GetSysColor,COLOR_WINDOWTEXT
	invoke SetTextColor,hdcMem,EAX
	
	
	 
	 	invoke SelectObject,hdcMem,hfntOld
	
	         
	MOV EAX,pPAINTSTRUCT
	LEA EBX,rc
	MOV EDX,[EBX].RECT.right
	SUB EDX,[EBX].RECT.left
	
	MOV ECX,[EBX].RECT.bottom
	SUB ECX,[EBX].RECT.top
	
	invoke BitBlt,[EAX].PAINTSTRUCT.hdc,rc.left,rc.top,0,0,hdcMem,0, 0,SRCCOPY
  	invoke SelectObject,hdcMem, hbmOld
 
    invoke DeleteObject,hbmMem;
    invoke DeleteDC,hdcMem;
    
             
	ret

Paint endp

ResizeWindow Proc hWnd:HWND,uMsg:DWORD,lParam:DWORD
	LOCAL CLRECT:RECT
	MOV EAX,uMsg
	
	
	.if uMsg == WM_WINDOWPOSCHANGED
		MOV EAX,lParam
		MOV EDX,offset ORGRECT
		MOV ECX,[EAX].WINDOWPOS.lx
		MOV EBX,[EAX].WINDOWPOS.cy
		.if [EDX].WINDOWPOS.lx == NULL
			
			MOV [EDX].WINDOWPOS.lx ,ECX
			MOV [EDX].WINDOWPOS.cy ,EBX
			
		.elseif [EDX].WINDOWPOS.lx == ECX && [EDX].WINDOWPOS.cy == EBX
			
			ret
		.else 
			MOV [EDX].WINDOWPOS.lx ,ECX
			MOV [EDX].WINDOWPOS.cy ,EBX
		.endif
		
	.endif
	

	invoke GetClientRect,hWnd,addr CLRECT
	LEA EAX, CLRECT
	SUB [EAX].RECT.bottom,23
	invoke MoveWindow,MainTabHandle,NULL,NULL,[EAX].RECT.right,[EAX].RECT.bottom,FALSE
			
	invoke GetClientRect,hWnd,addr CLRECT
	LEA EAX, CLRECT
	SUB [EAX].RECT.bottom,30
	invoke MoveWindow,MainTabContentDialogHandle,NULL,NULL,[EAX].RECT.right,[EAX].RECT.bottom,FALSE
			
			
	invoke GetClientRect,MainTabHandle,addr CLRECT
	LEA EAX, CLRECT
	SUB [EAX].RECT.bottom,38
	LEA EBX, CLRECT
	ADD [EBX].RECT.top,30
	LEA ECX, CLRECT
	SUB [ECX].RECT.right,10
	LEA EDX, CLRECT
	ADD [EDX].RECT.left,5
	invoke MoveWindow,ConnectionsLVHandle,[ECX].RECT.left,[EBX].RECT.top,[ECX].RECT.right,[EAX].RECT.bottom,FALSE
	

	invoke GetDlgItem,hWnd,1011
	MOV EDI,EAX
	invoke GetClientRect,MainTabHandle,addr CLRECT
	LEA EAX, CLRECT

	invoke MoveWindow,EDI,0,0,[EAX].RECT.right,[EAX].RECT.bottom,FALSE		

	ret

ResizeWindow endp


What I have tried:

I tried to call UpdateWindow,mainDlgHandle Listview handle. All the same. still not drawn correctly.

I tried to use RedrawWindow with RDW_ALLCHILDREN doesn't help either.

enabled WM_ERASEBKGND again doesn't help either.
Posted
Updated 20-Oct-17 15:20pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Issue is fixed by using SetParent on listview and the parent set is the main dialog and when switching between tabs using SetParent to return the parent of listview to the sub dialog so the code still hide it with ShowWindow. Now the Listview always show on top. No flickering. Very good.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100