I have a program that emmediatly starts a thread created in response to WM_Create for an animation. What is really strange is that sometimes the windows does exactly what i want it to. And then when i close and launch the window again peices of my window in the client are are missing. Now i thought that once a window is assembled it should act the same way everytime. Any body ever run into this? I'm beginning to think the CIA is fucking with me.

P.S.

Whats even stranger is when i recompile the code without changing any of the code i can get different results again.

I'm really getting pissed.

Anybody having experienced this "phenomena" i would respect your comments.

The code i was fooling with when this all started is below and is contained in my thread. The program is not complex and niether is my code.

invoke MoveToEx,hdc,XBOXS,29,NULL
invoke LineTo,hdc, XBOXE,29
invoke LineTo,hdc,XBOXE, 70 <This makes a box
invoke LineTo,hdc,XBOXS,70
invoke LineTo,hdc,XBOXS,29



mov X,30
mov Y,200
.while Y < 500
.while X<400
invoke SetPixel,hdc,X,Y,999h < this makes a square
inc X
.endw
mov X,30
inc Y
.endw
Posted on 2001-10-01 19:52:17 by titan
First of all, use FillRect instead of the PutPixel solution :).

When you say

when i close and launch the window again

do you mean the program, or the window?

Do you always remember to clean up? (Release/Delete the
HDC, stop the thread when closing the window, etc).

Do you spawn multiple threads? Do your main thread and
the spawned thread share data?

Try uploading the .asm file here :).
Posted on 2001-10-01 21:09:22 by f0dder
fodder my program does not need to release the DC because i use OWN_DC in the window creation.

When i say i launch the program i mean i click on the icon

I'm a newbie

My prog has at most two threads

That is the main window and my thread that is initialized with the response to WM_CREATE

Here is the code

Hope you can make sense of it

The previose code i posted is in my thread.


A lot of stuff is bleaped out with the colon as i am always experimenting:
.586
.model flat,stdcall
OPTION SCOPED
option casemap:none

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
SETGAME PROTO :DWORD
GETARRAYSIZE PROTO :DWORD
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\winmm.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\winmm.lib

include d:\masm32\mystuff\gamedata.asm
include d:\masm32\mystuff\gamedatani.asm
include d:\masm32\mystuff\gameconst.asm
include d:\masm32\mystuff\gamemacros.asm
include d:\masm32\mystuff\gamethread.asm
include d:\masm32\mystuff\gamestruct.asm
.code




GETARRAYSIZE proc uses ebx sizeArray:DWORD
xor edx,edx
mov eax,sizeArray
mov ebx,4
div ebx
mov N,eax
sub N,1
xor eax,eax
ret
GETARRAYSIZE endp

SETGAME proc uses ebx ecx lpArray:DWORD
XOR ECX,ECX

@@:

mov EAX,lpArray
MOV ebx,
mov BMID,ebx
inc ecx
mov ebx,
mov XPOS,ebx
inc ecx
mov ebx,
mov YPOS,ebx
push ecx
GETDIM

BLITMAP
pop ecx
CMP ecx,N
inc ecx
JB @B
xor eax,eax

ret 0

SETGAME endp

Play Proc uses ebx
LOCAL lop:DWORD

mov lop,0
.while lop<3
mov eax, RAND32(36)
.IF ax < 12
mov ebx,23
push ebx
.ELSEIF ax >24
mov ebx,24
push ebx
.ELSE
mov ebx,25
push ebx
.ENDIF
inc lop
.endw

XOR ECX,ECX

@@:
LEA EAX,play_array

mov ebx,
mov XPOS,ebx
inc ecx
mov ebx,
mov YPOS,ebx
pop BMID
push ecx
GETDIM
BLITMAP
pop ecx
CMP ecx,N
inc ecx
JB @B


xor eax,eax

ret 0

Play ENDP

start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_NORMAL
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_BYTEALIGNCLIENT or CS_HREDRAW or CS_VREDRAW or CS_OWNDC
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+2
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_WINLOGO
mov wc.hIcon,eax
;mov wc.hIconSm,eax
invoke LoadCursor,hInstance,IDC_1
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc

INVOKE CreateWindowEx,WS_EX_CONTEXTHELP,ADDR ClassName,ADDR AppName,\
WS_CAPTION or WS_SYSMENU,CW_USEDEFAULT,\
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,\
NULL,hInst,NULL


mov hwnd,eax
INVOKE ShowWindow, hwnd,SW_SHOWMAXIMIZED
INVOKE UpdateWindow, hwnd

.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)

INVOKE DispatchMessage, ADDR msg

.ENDW

mov eax,msg.wParam
ret ;< IS THIS RIGHT?
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL ps:PAINTSTRUCT


.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL

.ELSEIF uMsg==WM_CREATE

invoke GetDC,hWnd
mov hdc,eax
invoke SetICMMode,hdc,ICM_ON
invoke CreateCompatibleDC,NULL
mov cdc,eax
invoke SetICMMode,cdc,ICM_ON
;invoke GetClientRect,hWnd,ADDR rect

mov eax,OFFSET ThreadProc
invoke CreateThread,NULL,NULL,eax,\
hWnd,0,\
ADDR ThreadID
mov Threadh,eax




.ELSEIF uMsg==WM_TIMER

;invoke MessageBox,hWnd,ADDR Hello_string,OFFSET AppName,MB_OK or MB_APPLMODAL or MB_HELP or MB_ICONQUESTION
;.ELSEIF uMsg==BN_PUSHED
;invoke Beep,NULL,NULL

.ELSEIF uMsg==WM_COMMAND
mov eax,wParam


.IF ax==IDM_NEW
invoke SuspendThread,Threadh
invoke CloseHandle,Threadh

invoke GETARRAYSIZE, sizeof my_array
invoke SETGAME,addr my_array
invoke PlaySound,IDW_2,hInstance,SND_RESOURCE
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonText,\
WS_CHILD or WS_VISIBLE or BS_PUSHBUTTON or BS_BITMAP or BS_NOTIFY,\
80,110,124,40,hWnd,ButtonID,hInstance,NULL
mov hwndButton,eax
invoke LoadBitmap,hInstance,30
mov hBitBtnBmp,eax
invoke PostMessage,hwndButton,BM_SETIMAGE,IMAGE_BITMAP,hBitBtnBmp


.ELSEIF wParam==ButtonID
invoke PlaySound,IDW_1,hInstance,SND_RESOURCE
invoke GETARRAYSIZE, sizeof play_array
call Play
invoke GETARRAYSIZE, sizeof cash_array
invoke SETGAME,addr cash_array


.ELSEIF ax==IDM_OPEN
invoke MessageBox,NULL,ADDR Goodbye_string,OFFSET AppName,MB_OK


EnableMenuItem,hMenu,IDM_SCROLL,MF_BYCOMMAND or MF_GRAYED

;invoke EnableMenuItem,hMenu,IDM_STOPSCROLL,MF_BYCOMMAND or MF_ENABLED
;invoke CloseHandle,hMenu


.ELSEIF ax==IDM_SAVE
invoke MessageBox,hWnd,ADDR Hello_string,OFFSET AppName,MB_OK or MB_APPLMODAL or MB_HELP or MB_ICONQUESTION

.ELSEIF ax==IDM_EXIT
invoke DestroyWindow,hWnd



.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam

ret


.ENDIF


xor eax,eax
ret

WndProc endp


end start
Posted on 2001-10-01 21:32:59 by titan