flat assembler
Message board for the users of flat assembler.

Index > Windows > trying to create 2 windows

Author
Thread Post new topic Reply to topic
oobie-noobie



Joined: 01 Apr 2008
Posts: 10
oobie-noobie
I'm new to all this so be gentle with me Smile

What I'm trying to do is create 2 separate windows (i.e. not one inside the other). Using the code below the 'auxiliary window' is always on top of the 'main window'. I want to be able to select either of the windows to be topmost.

How do I achieve this ?

thanks in advance,

oobie

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32axp.inc'

section '.code' code readable executable

  start:
        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  RegisterClass,wc
        invoke  CreateWindowEx,WS_EX_CLIENTEDGE,_Class,mainTitle,WS_CLIPCHILDREN+WS_VISIBLE+WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 600, 400, NULL, NULL, [wc.hInstance],NULL
        mov     [hWndMain], eax
        invoke  CreateWindowEx,0,_Class,auxTitle,WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 600, 400, [hWndMain], NULL, [wc.hInstance],NULL
        mov     [hWndAux], eax
  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        or      eax,eax
        jz      end_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop
  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc wndProc hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_DESTROY
        je      .wmDESTROY
    .wmDEFAULT:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .wmBYE
    .wmDESTROY:
        invoke  PostQuitMessage,0
        xor     eax,eax
    .wmBYE:
        pop     edi esi ebx
        ret
endp

section '.data' data readable writeable

_Class          db "tester", 0
mainTitle       db "Main window", 0
auxTitle        db "Auxiliary window", 0
hWndMain        dd 0
hWndAux         dd 0
msg             MSG
wc              WNDCLASS 0, wndProc, 0, 0, NULL, NULL, NULL, COLOR_BTNFACE+1, NULL, _Class


section '.idata' import data readable writeable

library kernel32,'KERNEL32.DLL',\
        user32,  'USER32.DLL'

include '%fasminc%\apia\Kernel32.inc'
include '%fasminc%\apia\User32.inc'
    
Post 01 Apr 2008, 14:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
If you mean topmost as in always over all other windows then try SetWindowLong

If you mean topmost as in only between the two windows in your app then try BringWindowToTop

And for finer control use SetWindowPos
Post 01 Apr 2008, 15:06
View user's profile Send private message Visit poster's website Reply with quote
oobie-noobie



Joined: 01 Apr 2008
Posts: 10
oobie-noobie
Thanks for the fast answer.

I tried both

Code:
invoke  BringWindowToTop, [hWndMain]
    

and
Code:
invoke  SetWindowPos, [hWndMain], HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE+SWP_NOSIZE+SWP_SHOWWINDOW
    

directly after creating the 2nd (auxiliary) window, but neither made any difference.

Yes, the overlapping is only between *my* 2 windows.
Post 01 Apr 2008, 15:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
SDK wrote:
If the SWP_SHOWWINDOW or SWP_HIDEWINDOW flag is set, the window cannot be moved or sized.
Post 01 Apr 2008, 15:30
View user's profile Send private message Visit poster's website Reply with quote
oobie-noobie



Joined: 01 Apr 2008
Posts: 10
oobie-noobie
Yup, sorry I hadn't seen that in the SDK remarks Sad

Anyway, with the SWP_SHOWWINDOW removed, the aux is still on top. Confused

Do I need to use a different class or a sub-class (?) for the aux window?
Post 01 Apr 2008, 15:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
Try adjusting some styles in the second call to CreateWindowEx.
Post 01 Apr 2008, 15:49
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
oobie-noobie wrote:
Do I need to use a different class or a sub-class (?) for the aux window?
I don't think so, there should not be any restriction there.
Post 01 Apr 2008, 15:50
View user's profile Send private message Visit poster's website Reply with quote
oobie-noobie



Joined: 01 Apr 2008
Posts: 10
oobie-noobie
I've tried all sorts of exotic mixes with both window styles, some resulting in aux being the child (inside main), others (WS_POPUPWINDOW+WS_CAPTION) where the aux fills the whole screen and even the caption bar isn't visible.
No matter what combinations I try, I can't get them so that I can bring either to the top, the aux always remains topmost Sad
Post 01 Apr 2008, 16:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
Can you click on each window to bring it to the top?
Post 01 Apr 2008, 16:23
View user's profile Send private message Visit poster's website Reply with quote
oobie-noobie



Joined: 01 Apr 2008
Posts: 10
oobie-noobie
I can click on both windows. The main window's title bar will appear as if it is the topmost window, but the aux window will still overlap it.

Anyway, the eureka moment...
I thought I *had* to declare the main window as the parent of the aux. Apparently not. If I make the owner of the aux window NULL, then either window comes to the top when clicked Razz

Thanks for your help revolution, we got there in the end Wink
Post 01 Apr 2008, 16:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
Yes, you can make as many main windows as you want, there are no restrictions on that. Having a parent window means it is constrained to fit inside and on top of said parent.

Actually a parent of 0 in really a child window on top of the desktop window.
Post 01 Apr 2008, 16:36
View user's profile Send private message Visit poster's website Reply with quote
oobie-noobie



Joined: 01 Apr 2008
Posts: 10
oobie-noobie
Thanks for the clarification Wink
Post 01 Apr 2008, 16:39
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.