News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

problems with a window

Started by Ar0n, August 26, 2014, 07:31:45 AM

Previous topic - Next topic

Ar0n

Hello guys I'm having troubles with a simple windows of no border, I create it this way:

.586
.model flat,stdcall
option casemap:none
include masm32rt.inc

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD


.data
   ClassName db "MainWinClass",0
   AppName  db "Main Window",0
.data?
   hInstance HINSTANCE ?
   CommandLine LPSTR ?
.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_BTNFACE+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,200,200,NULL,NULL,\
           hInst,NULL
   mov   hwnd,eax
   invoke SetWindowLong,hwnd,GWL_STYLE,0
   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
   
   .IF uMsg==WM_DESTROY
      invoke PostQuitMessage,NULL
   .ELSEIF uMsg==WM_CREATE
      ;
   .ELSE
      invoke DefWindowProc,hWnd,uMsg,wParam,lParam      
      ret
   .ENDIF
   
   xor eax,eax
   ret
WndProc endp
end start

[ln][/ln]

But it seems to have problems with the repaint:


how can I resove this problem? thanks!


dedndave

   .IF uMsg==WM_DESTROY
      invoke PostQuitMessage,NULL
   .ELSEIF uMsg==WM_CREATE
      ;
   .ELSE
      invoke DefWindowProc,hWnd,uMsg,wParam,lParam     
      ret
   .ENDIF
   
   xor eax,eax
   ret

this method is problematic, but may work in some cases
it is better to allow a return value other than 0, though
   .IF uMsg==WM_DESTROY
      invoke PostQuitMessage,NULL
      xor     eax,eax                               ;return 0
   .ELSEIF uMsg==WM_CREATE

      xor     eax,eax                               ;return 0
   .ELSE
      invoke DefWindowProc,hWnd,uMsg,wParam,lParam     
   .ENDIF   
   ret

now - each message type can return an appropriate value
not all messages need to return 0

are you handling WM_PAINT ?

dedndave

;   invoke SetWindowLong,hwnd,GWL_STYLE,0

this line, not good - try commenting it out   :P

qWord

You might better try it with a pop-up window (WS_POPUP), rather than setting the windows style to zero.
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

qWord is right

replace "WS_OVERLAPPEDWINDOW"
with "WS_POPUP or WS_VISIBLE or WS_CLIPCHILDREN"

Ar0n

Quote from: dedndave on August 26, 2014, 08:05:42 AM
   .IF uMsg==WM_DESTROY
      invoke PostQuitMessage,NULL
   .ELSEIF uMsg==WM_CREATE
      ;
   .ELSE
      invoke DefWindowProc,hWnd,uMsg,wParam,lParam     
      ret
   .ENDIF
   
   xor eax,eax
   ret

this method is problematic, but may work in some cases
it is better to allow a return value other than 0, though
   .IF uMsg==WM_DESTROY
      invoke PostQuitMessage,NULL
      xor     eax,eax                               ;return 0
   .ELSEIF uMsg==WM_CREATE

      xor     eax,eax                               ;return 0
   .ELSE
      invoke DefWindowProc,hWnd,uMsg,wParam,lParam     
   .ENDIF   
   ret

now - each message type can return an appropriate value
not all messages need to return 0
Ok I'll consider

Quote from: dedndave on August 26, 2014, 08:05:42 AM
are you handling WM_PAINT ?
I tried and it didn't work :P

Quote from: dedndave on August 26, 2014, 08:08:52 AM
;   invoke SetWindowLong,hwnd,GWL_STYLE,0

this line, not good - try commenting it out   :P
Quote from: qWord on August 26, 2014, 08:10:04 AM
You might better try it with a pop-up window (WS_POPUP), rather than setting the windows style to zero.
I need to create a windows with no border... that is why I set zero value and I tried with WS_POPUP... didn't work :P

qWord

try this one:
include \masm32\include\masm32rt.inc
.686

WinMain proto :HWND,:UINT,:WPARAM,:LPARAM

.const
   ClassName db "MainWinClass",0
   AppName  db "Main Window",0
.data?
   hInstance HINSTANCE ?
   CommandLine LPSTR ?
.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
   
   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
   mrm   wc.hInstance,hInstance
   mov   wc.hbrBackground,COLOR_BTNFACE+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,0,ADDR ClassName,ADDR AppName,\
           WS_POPUP or WS_VISIBLE or WS_SYSMENU,100,\
           100,200,200,NULL,NULL,\
           hInst,NULL

   .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
   
   .IF uMsg==WM_DESTROY
      invoke PostQuitMessage,NULL
      xor eax,eax
   .ELSEIF uMsg==WM_CREATE
      xor eax,eax
   .ELSE
      invoke DefWindowProc,hWnd,uMsg,wParam,lParam     
   .ENDIF
   ret

WndProc endp
end start
MREAL macros - when you need floating point arithmetic while assembling!

Ar0n

Yeah It worked, thanks qWord.

hutch--

Hi Ar0n,

I have split off the rest of the topic as I saw it as a distraction to your original question.