News:

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

Main Menu

Dialog Box not popping up

Started by Derriuz, December 17, 2012, 12:55:44 PM

Previous topic - Next topic

Derriuz

Hello, everyone!

Maybe this will be a stupid question and I should be ashamed of myself, but I'm stuck at this for a few hours already and tried fixing it in tons of different ways.
Whether I'm using CreateDialogParam or DialogBoxParam to create a Dialog Box nothing seems to happen when it should pop up (or maybe it stays invisible?).
This is what is in the .IF connected to the event (it's tied with picking a certain option in main window's menu, however I'm quite sure that the menu by itself is okay, as other functions in it work as intended).

INVOKE DialogBoxParam, hInstance, ADDR TrollDialogClass,hWnd,OFFSET DlgProc, NULL

With hInstance being a handle to instance of my app (sorry, i know, obvious), TrollDialogClass being:

TrollDialogClass DB "TrollDialog",0

In my .DATA section, DlgProc being (didn't get to proper reactions to actions in dialog box, since i wouldn't even be able to test those if the dialog itself does not appear):

DlgProc PROC hWnd:HWND, iMsg:DWORD, wParam:WPARAM, lParam:LPARAM

mov EAX,wParam

.IF iMsg==WM_INITDIALOG
invoke SetFocus, hwndDlg
.ELSEIF iMsg==WM_CLOSE
        INVOKE EndDialog, hWnd, NULL
    .ELSEIF iMsg==WM_COMMAND
       
    .ENDIF
    mov eax, TRUE
    ret

DlgProc ENDP


And my resource file contains following code:

#define IDM_MENU 1000
#define IDM_SAVEAS 1005
#define IDM_OPEN 1004
#define IDM_NEW 1001
#define IDM_CLOSE 1007
#define IDM_FILE 1009
#define IDM_BONUS 1010
#define IDM_TROLL 1011
#define IDM_HELP 1008
#define IDM_ABOUT 1014
#define TrollDialog 2001
#define IDC_OPTION1 2002
#define IDC_OPTION2 2003
#define IDC_BUTTON 2004

IDM_MENU MENUEX DISCARDABLE
BEGIN
POPUP "Plik",IDM_FILE
BEGIN
MENUITEM "Nowy",IDM_NEW
MENUITEM "Otwórz...",IDM_OPEN
MENUITEM "Zapisz jako...",IDM_SAVEAS
MENUITEM "Zamknij",IDM_CLOSE
END
POPUP "Bonus",IDM_BONUS
BEGIN
MENUITEM "Trolluj mnie!",IDM_TROLL
END
POPUP "Pomoc",IDM_HELP
BEGIN
MENUITEM "O programie...",IDM_ABOUT
END
END

TrollDialog DIALOGEX 0,0,224,297
CAPTION "Wybierz trolling..."
FONT 8,"MS Sans Serif"
CLASS "TrollDialog"
STYLE 0x50cc0882
EXSTYLE 0x00000000
BEGIN
CONTROL "IDC_OPTION1",IDC_OPTION1,"Button",0x50010009,23,12,124,47,0x00000000
CONTROL "IDC_OPTION2",IDC_OPTION2,"Button",0x50010009,33,83,137,59,0x00000000
CONTROL "IDC_BUTTON",IDC_BUTTON,"Button",0x50010000,47,222,107,56,0x00000000
END


If required I'll gladly put here the whole code, anything if you could help me.  I've got a feeling I already looked everywhere with no luck. :/
I am currently working with WinASM if this information helps.

qWord

Hello,
use the resource ID instead of the string:
INVOKE DialogBoxParam, hInstance, 2001,hWnd,OFFSET DlgProc, NULL

Also, AFAIK, the CLASS directive in your dialog removes the common message processing of dialogs - you may comment it out.
MREAL macros - when you need floating point arithmetic while assembling!

Vortex

Hi Derriuz,

Here is a quick example :

.386
.model flat,stdcall
option casemap:none

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

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

DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

.data

DlgBox db 'DLGBOX',0

.code

start:

    invoke  GetModuleHandle,0
    invoke  DialogBoxParam,eax,ADDR DlgBox,0,ADDR DlgProc,0
    invoke  ExitProcess,eax

DlgProc PROC hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

    .IF uMsg==WM_CLOSE

        invoke    EndDialog,hWnd,0

    .ELSE

        xor eax,eax
        ret

    .ENDIF

    mov    eax,1
    ret

DlgProc ENDP

END start


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

DLGBOX DIALOGEX MOVEABLE PURE LOADONCALL DISCARDABLE 20, 10, 200, 120, 18481280
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED
CAPTION "Dialog box"
FONT 12, "System", 700, 0
BEGIN
END


invoke  DialogBoxParam,eax,ADDR DlgBox,0,ADDR DlgProc,0

As you can see, DlgBox refers to a dialog box resource template.

Derriuz

Thanks a lot to both of you for fast response! It's working now! Both of the posts came in handy :D . Now I can finally move on. Wish me luck.
Damn I knew it was something stupid there :D . I guess the longer you learn and the bigger the file gets, the more confused you become. Thanks to you guys I also eliminated a couple of other mistakes (bad style choices and troublesome DlgProc).

Vortex

Hi Derriuz,

My best wishes for you and good luck.

No need to feel ashamed or embarrassed here. Feel yourself comfortable.

Quote by the legendary physicist Richard Feynman :

QuoteWe absolutely must leave room for doubt or there is no progress and no learning. There is no learning without having to pose a question. And a question requires doubt.