News:

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

Some 'Window' questions

Started by Rainstorm, April 21, 2007, 01:11:46 AM

Previous topic - Next topic

Rainstorm

hi.

does the ShowWindow function keep getting called ?
in the win SDK for the nCmdShow value of the ShowWindow function, it says
QuoteAn application should specify this flag when displaying the window for the first time.
I thought the function is called once when the program is started, if so,...in that case the above quote wouldn't make much sense about displaying the window for the first time. - So what does that mean exactly ?

------------------

I was having a problem where the window would go from the screen but the application would still remain running in 'Task Manager' & I had to close it manually..- don't know what i changed exactly in the code but that's stopped. - why would that happen ?

--------------

when i run my app now i get the hour-glass icon for the cursor lingering after the Window starts.
why is this ? (processor usage doesn't hike up though)
here's the code...(the app doesn't have any resources or a .rc file)
Many Thanks...    .data?

  hInst HINSTANCE ?
  hWnd dd ?

    .data

  windowname db "WindowForge",0
  wclassname  db "classforge",0


;-------------------------------------------------------------------
    .code
start:

    invoke GetModuleHandle, NULL
    mov hInst, eax                  ; instance handle of this application.

    invoke WinMain,hInst,NULL,NULL,SW_SHOWDEFAULT
   
    invoke ExitProcess,eax   

 
WinMain proc hInstance:HINSTANCE,hPrevInstance:DWORD,lpCmdLine:DWORD,nCmdShow:DWORD

      LOCAL wcl   :WNDCLASSEX
      LOCAL msg   :MSG

   mov ebx, hInstance             ; handle to the current instance of the application
   mov hPrevInstance, NULL        ; Handle to the previous instance of the application
   mov lpCmdLine, NULL            ; pointer to commandline
   mov nCmdShow, SW_SHOW

   mov wcl.cbSize,           sizeof WNDCLASSEX
   mov wcl.style,            CS_HREDRAW or CS_VREDRAW \
                     or      CS_BYTEALIGNWINDOW
   mov wcl.lpfnWndProc,   offset WindowProc
   mov wcl.cbClsExtra,       0
   mov wcl.cbWndExtra,       0
   mov wcl.hInstance,        ebx
   mov wcl.hIcon,            NULL
   mov wcl.hCursor,          NULL
   mov wcl.hbrBackground,    COLOR_BTNFACE+1
   mov wcl.lpszMenuName,     0
   mov wcl.lpszClassName,    offset wclassname
   mov wcl.hIconSm,          NULL   


   invoke RegisterClassEx,addr wcl       ; Register the Class

  ; ·÷-·÷-·÷-·÷-·÷-·÷-·÷-·÷-·÷
  ;    Create the window
  ; ·÷-·÷-·÷-·÷-·÷-·÷-·÷-·÷-·÷

invoke CreateWindowEx,
       WS_EX_OVERLAPPEDWINDOW,\                       
       addr wclassname,\
       addr windowname,\         
       WS_OVERLAPPEDWINDOW\
             or WS_HSCROLL\   
             or WS_VSCROLL,\
       CW_USEDEFAULT,
       CW_USEDEFAULT,
       CW_USEDEFAULT,       
       CW_USEDEFAULT,
       NULL,\     
       NULL,\
       hInstance,\   
       NULL   
             
    mov hWnd, eax       ; returns the handle to the new window created.

   invoke ShowWindow,hWnd,SW_SHOWNORMAL
   invoke UpdateWindow,hWnd

    MessageLoop:
      invoke GetMessage,addr msg,NULL,0,0
     
      .if eax == -1             ;  check for an error
        push eax
        fn MessageBox,0,"error","Title",MB_OK
        pop eax
      .endif

      cmp eax, 0            ; check for WM_QUIT message retrieved by GetMessage
      je ExitMsgLoop        ; if 0 (WM_QUIT msg retrieved), then exit the Loop.
      invoke TranslateMessage, addr msg
      invoke DispatchMessage, addr msg
      jmp MessageLoop
   ExitMsgLoop:
      mov eax, msg.wParam
      ret

WinMain endp

    WindowProc proc hwnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    .if uMsg == WM_DESTROY
      invoke PostQuitMessage,NULL
      return 0
    .endif

    invoke DefWindowProc,hwnd,uMsg,wParam,lParam     
   
    ret

WindowProc endp

end start

zooba

ShowWindow can be called any number of times. I believe in this case the 'first time' bit (part of the description of the SW_SHOWNORMAL values for the nCmdShow parameter - a bit of context always helps :wink ) is basically a consistency issue. Any program that starts shouldn't start hidden/minimised or taking up the whole screen/maximised unless it has been specifically asked for. However, I am speculating here, and since the parameter is often ignored the first time anyway it may be completely irrelevant.

A PostQuitMessage() was probably missing from your window procedure. Without this, your message loop probably won't exit.

You're not specifying a class cursor nor are you handling WM_SETCURSOR messages. Basically, Windows has no idea what you want the cursor to be, so it keeps the same one it had before (the hourglass, from when it was loading). Either set wcl.hCursor to LoadCursor(0, IDC_ARROW) or handle WM_SETCURSOR in your message loop. If you want to be able to change the cursor while your program is running, you'll need to handle WM_SETCURSOR (though it can always fall through to the default class cursor). Don't go changing the class cursor - that's bad.

Cheers,

Zooba :U

Rainstorm

Zooba,
thanks for the info & clearing that cursor thing. : )
(small thing but kinda relieved)

i guess there are other ways of using showWindow that i don't know about, but in my code its used
& called just once & i thought that would be the case 'calling it once' after creating the window itc.

-