News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

CreateWindowEx fails

Started by GoneFishing, March 24, 2013, 01:43:45 AM

Previous topic - Next topic

jj2007

Quote from: dedndave on March 24, 2013, 03:37:02 AM
if you use CreateWindowEx to create a status bar, i think you do have to size and locate it

Microsoft thinks you don't have to.

WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
  .if uMsg == WM_CREATE
      mov hWndStat, rv(CreateWindowEx, 0, "msctls_statusbar32", "Hello Dave", WS_CHILD or WS_VISIBLE, 0, 0, 0, 0, hWnd, 0, 0, 0)
  .elseif uMsg == WM_DESTROY
      invoke PostQuitMessage, NULL
  .endif
  invoke DefWindowProc, hWnd, uMsg, wParam, lParam
  ret
WndProc endp


GoneFishing

I found an example of CHECKED MENUITEM in masm32\examples\exampl01\showdib
Then I took a glance to rc.hlp
I use MENUEX in my resource file and making one of the menuitems CHECKED caused compilation error.

#include "\masm32\include\resource.h"

600 MENUEX MOVEABLE IMPURE LOADONCALL DISCARDABLE
BEGIN
    POPUP "&File", , , 0
    BEGIN
        MENUITEM "&Open\tCtrl+O", 1000
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "&Exit\tEsc", 1001
    END
    POPUP "&View" ,,,0
    BEGIN
        MENUITEM "Toolbar",1100
        MENUITEM "Status bar",1101
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "Font",1102
        MENUITEM "Options",1103
    END
    POPUP "&Debug",,,0
    BEGIN
        MENUITEM "&Go\tF5", 1200
        MENUITEM "&Restart\tCtrl+Shift+F5", 1201
        MENUITEM "Stop debugging\tShift+F5", 1202
        MENUITEM "Break\tCtrl+Break", 1203
        MENUITEM "Step\tF8",1204
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "Source mode", 1205,CHECKED

    END
 
    POPUP "&Help", , , 0
    BEGIN
        MENUITEM "&About", 1900
    END
END


Now you see I'm writing my "Hello World Debugger"  :biggrin:
It's my first "big" project
And I want to add an option to choose from source  and assembly mode debugging  .


dedndave

it would help if you showed us the error(s)
but, i think i know where one is   :P

CHECKED is not defined
try using MF_CHECKED or, more appropriately, MFS_CHECKED (same value)

MENUEX is a little harder to use than MENU

dedndave

Jochen - did you try that in a program
and - try sizing the main window

jj2007

Quote from: dedndave on March 24, 2013, 06:26:19 AM
Jochen - did you try that in a program
and - try sizing the main window

Of course I tried it before posting :biggrin:
Just take the OP's original code, replace in line 93 hwnd with hWnd, and see the result.

But you are right about sizing. If the main window is sizable, then you better handle WM_SIZE also for the status bar. If it's fixed size, no need for that.

dedndave

whew - thought i was doing something wrong - lol

i played with it a little bit
and, even when using CreateStatusWindow, i have to set the size when WM_SIZE on the main window
so, on the bright side, i was also wrong   :biggrin:

GoneFishing

What is going on?
I've wrote two posts but  cant see them
About errors - MAKEIT.BAT quits quickly and silently producing only MineDbg.obj
My status bar is divided into four equal parts and while sizing the window all of them stay equal.

dedndave

please attach the project, all the files, including makeit.bat

GoneFishing

Just tried MF_CHECKED and MFS_CHECKED with MENUEX
All compiles  but my  window starts without menu at all!

MineDbg.asm
.486
.model flat, stdcall
option casemap:none

include  \masm32\include\comctl32.inc
include  \masm32\include\comdlg32.inc
include  \masm32\include\windows.inc
include  \masm32\include\kernel32.inc
include  \masm32\include\user32.inc
include  \masm32\include\gdi32.inc

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



WinMain PROTO STDCALL   :DWORD, :DWORD, :DWORD, :DWORD
WndProc PROTO STDCALL   :DWORD, :DWORD, :DWORD, :DWORD

.data?

hInstance       dd      ?
hWndStat        dd      ?
sbParts         dd   4  dup(?)
hWnd            dd      ?

.data

StatClass       db      "msctls_statusbar32",0
ClassName       db      "FirstWindowClass",0
AppName         db      "MineDbg",0

.code

start:

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

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
    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,WS_EX_CLIENTEDGE,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW or WS_SIZEBOX or WS_MAXIMIZEBOX,CW_USEDEFAULT,\
           CW_USEDEFAULT,400,300,NULL,NULL,\
           hInstance,NULL
    mov   hWnd,eax
    invoke LoadMenu,hInst,600  ; menu ID
    invoke SetMenu,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  uMsg == WM_CREATE

;---------- Create the status bar window ----------
     invoke  CreateWindowEx, 0, addr StatClass, 0,\
                     WS_CHILD or WS_BORDER or WS_VISIBLE or SBS_SIZEGRIP,\
                    0, 0, 0, 0,hwnd, 0, hInstance, 0 
            mov     hWndStat, eax
;---------- [Move and Size the Control(s)] ----------
.elseif uMsg == WM_SIZE

;---------- [Size the Statusbar Control] ----------
            mov     eax, lParam       ; Get width
            and     eax, 0ffffh       ; Lowword
            shr     eax, 2            ; /4
            mov     ecx, eax          ; Save factor
            mov     sbParts, eax      ; Make part 1 1/4 the width
            add     eax, ecx
            mov     [sbParts+4], eax  ; and also part2, .. etc
            add     eax, ecx
            mov     [sbParts+8], eax
            mov     [sbParts+12], -1  ; The last part extends to the end
         INVOKE     SendMessage, hWndStat, SB_SETPARTS, 4, addr sbParts
         INVOKE     MoveWindow, hWndStat, 0, 0, 0, 0, TRUE

.elseif  uMsg == WM_DESTROY
    invoke PostQuitMessage, NULL
.ELSE
    invoke DefWindowProc, hwnd, uMsg, wParam, lParam
    ret
.ENDIF
xor eax,eax
ret
WndProc endp

end start


rsrc.rc
#include "\masm32\include\resource.h"

600 MENUEX MOVEABLE IMPURE LOADONCALL DISCARDABLE
BEGIN
    POPUP "&File", , , 0
    BEGIN
        MENUITEM "&Open\tCtrl+O", 1000
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "&Exit\tEsc", 1001
    END
    POPUP "&View" ,,,0
    BEGIN
        MENUITEM "Toolbar",1100
        MENUITEM "Status bar",1101
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "Font",1102
        MENUITEM "Options",1103
    END
    POPUP "&Debug",,,0
    BEGIN
        MENUITEM "&Go\tF5", 1200
        MENUITEM "&Restart\tCtrl+Shift+F5", 1201
        MENUITEM "Stop debugging\tShift+F5", 1202
        MENUITEM "Break\tCtrl+Break", 1203
        MENUITEM "Step\tF8",1204
        MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
        MENUITEM "Source mode", 1205,MFS_CHECKED

    END
 
    POPUP "&Help", , , 0
    BEGIN
        MENUITEM "&About", 1900
    END
END



MAKEIT.BAT
@echo off
: -------------------------------
: if resources exist, build them
: -------------------------------
if not exist rsrc.rc goto over1
\MASM32\BIN\Rc.exe /v rsrc.rc
\MASM32\BIN\Cvtres.exe /machine:ix86 rsrc.res
:over1

if exist %1.obj del MineDbg.obj
if exist %1.exe del MineDbg.exe

: -----------------------------------------
: assemble MineDbg.asm into an OBJ file
: -----------------------------------------
\MASM32\BIN\Ml.exe /c /coff /Zi MineDbg.asm
if errorlevel 1 goto errasm

if not exist rsrc.obj goto nores

: --------------------------------------------------
: link the main OBJ file with the resource OBJ file
: --------------------------------------------------
\MASM32\BIN\Link.exe /DEBUG /DEBUGTYPE:CV /SUBSYSTEM:WINDOWS MineDbg.obj rsrc.obj
if errorlevel 1 goto errlink

dir MineDbg.*

goto TheEnd

:errlink
: ----------------------------------------------------
: display message if there is an error during linking
: ----------------------------------------------------
echo.
echo There has been an error while linking this project.
echo.
goto TheEnd

:errasm
: -----------------------------------------------------
: display message if there is an error during assembly
: -----------------------------------------------------
echo.
echo There has been an error while assembling this project.
echo.
goto TheEnd

:TheEnd
pause


That's only the skeleton of MineDbg

jj2007

    invoke LoadMenu,hInst,600  ; menu ID

Error "Invalid data"... now have fun chasing that problem. There is a reason why I avoid rc files ;-)

(hint: it's a comma :biggrin:)

OK, I won't be mean: MENUITEM "Source mode", 1205,, MFS_CHECKED

(and don't ask me why, there is no logic in it but it works :bgrin:)

GoneFishing

 :greenclp:
But how did you find it ?!!
Or you already knew it, didn't you?
Anyway,  thank you , Jochen!
I wish I found this hidden comma :-)





MichaelW

I think the resource statement is actually supposed to be:

MENUITEM "Source mode", 1205, MFT_STRING, MFS_CHECKED


Because whether I use MFT_STRING in the statement or leave the space between the commas empty, in this test app the menu displays correctly, GetMenuItemInfo returns the MFT_STRING type, and returns a pointer to the menu item string in the dwTypeData member:

;==============================================================================
; Build as a console app.
;==============================================================================
include \masm32\include\masm32rt.inc
;==============================================================================
.data
  hInst HMODULE 0
  hMenu HMENU 0
  buffer db 100 dup(0)
  FMASK = MIIM_FTYPE or MIIM_STATE or MIIM_STRING
  mii MENUITEMINFO <SIZEOF MENUITEMINFO, FMASK,,,,,,,, OFFSET buffer, 100>
.code
;==============================================================================
DlgProc proc hwndDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    SWITCH uMsg

        CASE WM_INITDIALOG

            invoke LoadMenu, hInst, 600
            mov hMenu, eax
            invoke SetMenu, hwndDlg, hMenu
            invoke GetMenuItemInfo, hMenu, 1205, FALSE, ADDR mii
            printf("%d\n", eax)
            printf("fType      %d\t%d\n", mii.MENUITEMINFO.fType, MFT_STRING )
            printf("fState     %d\t%d\n", mii.MENUITEMINFO.fState, MFS_CHECKED)
            printf("dwTypeData %s\n", mii.MENUITEMINFO.dwTypeData)

        CASE WM_COMMAND

            SWITCH wParam

                CASE IDCANCEL

                    invoke EndDialog, hwndDlg, 0

            ENDSW

        CASE WM_CLOSE

            invoke EndDialog, hwndDlg, 0

    ENDSW

    return 0

DlgProc endp
;==============================================================================
start:
;==============================================================================
    invoke GetModuleHandle, NULL
    mov hInst, eax

    Dialog "test", \
           "MS Sans Serif",10, \
           WS_VISIBLE or WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
           0,0,0,100,75,1024

    CallModalDialog NULL,0,DlgProc,NULL

    exit
;==============================================================================
end start


1
fType      0    0
fState     8    8
dwTypeData Source mode

Well Microsoft, here's another nice mess you've gotten us into.

GoneFishing


jj2007

Quote from: vertograd on March 24, 2013, 04:27:20 PM
Thank you, Michael!

Thanks from me, too, for showing me the missing logic :biggrin:
MENUITEM "text", ID, MFT_xxx, MFS_xxx

dedndave

notice that the value of MFT_STRING is 0
so, you can use .... ,MFT_STRING, ....
or .... ,0, ....
or .... ,, ....