Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 605
  • Last Modified:

SetWindowsPlacement() API in MASM32.

I just joined and I would like to find out how to use the SetWindowsPlacement() API in Masm32.

Where should this code be placed in the program below ?

Thanks for your attention

Newbit

#######################################################

.486
.model flat, stdcall
option casemap:none

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

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc
WinMain PROTO STDCALL   :DWORD, :DWORD, :DWORD, :DWORD
WndProc PROTO STDCALL   :DWORD, :DWORD, :DWORD, :DWORD
.data?
hInstance       dd      ?

.data
ClassName       db      "Simple Window", 0
AppName         db      "Press the OK button to see the random position of the window.", 0

.code
start:

    invoke  GetModuleHandle, NULL
    mov     hInstance, eax
    invoke  WinMain, hInstance, NULL, NULL, SW_SHOWNORMAL
    invoke  ExitProcess, NULL

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
    LOCAL wc:WNDCLASSEX
    LOCAL hwnd:DWORD
    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
    push    hInst
    pop     wc.hInstance
    mov     wc.hbrBackground,COLOR_WINDOW
    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-WS_SIZEBOX-WS_MAXIMIZEBOX,CW_USEDEFAULT,\
           CW_USEDEFAULT,500,500,NULL,NULL,\
           hInst,NULL
    mov   hwnd,eax
    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:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
mov eax, uMsg
.IF eax==WM_CREATE
    invoke  MessageBox, NULL, ADDR AppName, ADDR AppName, NULL
.ELSEIF eax==WM_DESTROY
    invoke PostQuitMessage, NULL
.ELSE
    invoke DefWindowProc, hWnd, uMsg, wParam, lParam
.ENDIF
ret
WndProc endp
end start

########################################################
0
Newbit
Asked:
Newbit
1 Solution
 
craigwardmanCommented:
You can add additional code to your WndProc, but the above program is just using CW_USEDEFAULT for its startup position, so you could hard code the values you want to use in the CreateWindow..

Anyway, if you're just doing as a learning excercise, heres a quick example of how to do it:

WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
LOCAL wndPlacement:WINDOWPLACEMENT

mov eax, uMsg
.IF eax==WM_CREATE
    invoke  MessageBox, NULL, ADDR AppName, ADDR AppName, NULL
    mov wndPlacement.iLength, SIZEOF WINDOWPLACEMENT
    mov wndPlacement.flags, NULL
    mov wndPlacement.showCmd, SW_SHOWNORMAL
    mov wndPlacement.ptMinPosition.x, 0
    mov wndPlacement.ptMinPosition.y, 0
    mov wndPlacement.ptMaxPosition.x, 0
    mov wndPlacement.ptMaxPosition.y, 0
    mov wndPlacement.rcNormalPosition.left, 0Ah
    mov wndPlacement.rcNormalPosition.top, 0Ah
    mov wndPlacement.rcNormalPosition.right, 0Ah
    mov wndPlacement.rcNormalPosition.bottom, 0Ah
    Invoke SetWindowPlacement, hWnd, ADDR wndPlacement
.ELSEIF eax==WM_DESTROY
    invoke PostQuitMessage, NULL
.ELSE
    invoke DefWindowProc, hWnd, uMsg, wParam, lParam
.ENDIF
ret
WndProc endp
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now