News:

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

Thread Problems

Started by xandaz, October 17, 2009, 03:32:09 PM

Previous topic - Next topic

xandaz

 :dazzled:

   Hi guys. It's me again: xandaz. I've been experiencing a new peoblem. I created a new thread inside an existing process. The thread creates a new window and once the WM_CREATE message is processeed a child window is created with the WS_POPUPWINDOW style, but the window doesnt show up. The idea is to create a presentation window for the main program and the window is destroyed 10 seconds after its creation. I'd like to know what's wrong if you can help me with it. Thanks.

This is more or less what is done:

start:
       invoke GetModuleHandle/CommandLine/InitCommonControls/WinMain....etc

WinMain PROC and the usual varials

local wc:WNDCLASSEX
inv. RegisterClassex,addr wc
inv. CreateWindowEx, stuff
hwnd,eax
inv. ShowWindow/UpdateWindow : hwnd/SW_SHOWNORMAL

msg_loop

endp

WndProc PROC usual varials

...
Case WM_CREATE

inv. CreateThread,NULL,NULL,addr NewThread,NULL,NULL,addr ThreadID
...
endp

NewThread PROC arg:DWORD

local   wc:WNDCLASSEX
inv. RegisterClassex,addr wc
inv. CreateWindowEx,WS_EX_TOPMOST,addr ThreadClass,\...\WS_POPUPWINDOW+WS_CHILD+WS_VISIBLE,\...\,hwnd,NULL,hInstance,NULL
hwnd2,eax
inv. ShowWindow/UpdateWindow :hwnd2/SW_SHOWNORMAL

msg_loop:
endp

ThreadProc  PROC usual varials for window procs

.if uMsg==WM_CREATE
inv. CreateWindowEx,NULL,addr StaticClass,NULL,WS_VISIBLE+WS_CHILD+SS_BITMAP,\...\,hwnd2,NULL,hInstance,NULL
hStatic,eax
inv. LoadImage, stuff...\...\
inv. SendMessage,hStatic,STM_SETIMAGE,NULL,eax

endp

after all this is done everything goes just fine except this last static control doesnt show. What could be wrong? i tried lots of stuff. I changed the window styles, i gave the window creation the thread handle but nothing seems to be working.
   Would someone look into it? Thanks guys. I appreciatte it.
   Ty and nite


ecube


call this function after one of the apis to see if a error returns

HandleError proc
     
    LOCAL lpMsgBuffer     : LPVOID
     
    ; calculate language ID, asm version of MAKELANGID
    mov cx, SUBLANG_DEFAULT
    shl ecx, 10

    push NULL               
    push 0                   
                       
    lea  eax, lpMsgBuffer         
    push eax               
    push ecx               
    invoke GetLastError           
    push eax               
    push NULL                 
    mov edx, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM
    push edx                 
    call FormatMessage           
     

    invoke MessageBox, NULL, lpMsgBuffer, NULL, MB_OK or MB_ICONSTOP
     
    invoke LocalFree, lpMsgBuffer
invoke ExitProcess,0
    ret
HandleError endp

japheth


inv. CreateWindowEx,NULL,addr StaticClass,NULL,WS_VISIBLE+WS_CHILD+SS_BITMAP,\...\,hwnd2,NULL,hInstance,NULL
hStatic,eax


How do you ensure that variable hwnd2 is valid at this point?

xandaz

   You guys are the best. The hwnd2 variable was no longer valid. How did that happen? Do you know why? I used the hWnd variable from the new thread's WndProc and it worked. Thanks guys and praise the lord for MASM32 Forum.

ty ty and bye till next doubt ( which will prolly be sooner than i imagine)

japheth

Quote from: xandaz on October 18, 2009, 02:26:55 PM
   You guys are the best. The hwnd2 variable was no longer valid. How did that happen? Do you know why?

Yes. The problem wasn't that "the hwnd2 variable was no longer valid", the problem was that the hwnd2 variable was not yet valid.

xandaz

   japeth? Not valid yet? Is the WM_CREATE faster than then the return from CreateWindowEx?
  I guess that that's it right?
  Thanks man, and thanks for this forum. This is really good. I hope the time comes soon when i'll be able to retribute all the halp given to me
  Bye and stay well