News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Dialog as main and dialog as about issue

Started by white scorpion, May 28, 2006, 10:09:39 AM

Previous topic - Next topic

white scorpion

Hi all,

I'm using the RadASM IDE to create a program. I have chosen Dialog as main template for the actual program and i am now trying to create another dialog for the about box.
I've designed the dialog by selecting "Project", "Add New", "Dialog".
I've given it the same classname, set child=TRUE, put a button on it and declared the IDD_ABOUT in the .inc file.
Now i'm kindof stuck.
I've tried calling the dialogbox by using all parameters from WinProc and WinMain. This however results in an unwanted image & menu in the about dialog.

Then i tried creating a whole new class, with DlgMain & DlgProc.
This works, but it has some disadvantages:
- The about dialog stays open even when you close the program itself
- As soon as the about dialog is closed the main dialog is not updated anymore, which means that part of it's text, buttons and editboxes are not visible anymore.
- The about dialog doesn't popup in front of my main dialog but behind it.

Normally i always used a simple messagebox for the about message, but this time i would like to put in a working hyperlink to my website which is (to my knowledge) impossible in a messagebox.

Finally i want to keep a static size for both the main dialog and about dialog. i've already set sizeborder to false, but if you doubleclick the window title bar it still maximizes over the full screen.

Ossa

A different dialog should have a different class name (I think). Can you post some code that exhibits the behavior you describe in the second half of your post?

Ossa
Website (very old): ossa.the-wot.co.uk

PBrennick

White Scorpion,
I guess I am confused.  I thought I had given you a working example that explains how to do this.  Are you harvesting or do you have a problem with my code?

Paul
The GeneSys Project is available from:
The Repository or My crappy website

white scorpion

Paul,

You gave me a working example,but i'm afraid i can't get it to work without rewriting a large part of the program (i think i just don't really get the dialog functions yet  :'( ).

You use about dialog data from a .rc file.
Hutch showed me how to create an in memory dialog, but i can't get that to work either.

here are the functions i've used to create the dialog:

;****************************************************************
; the procedure to show the about dialog
;****************************************************************
ShowAboutDialog PROC
invoke  CreateDialogParam, hInstance, addr AboutName,
                hWnd, OFFSET DlgProc, NULL
ret
ShowAboutDialog ENDP

;****************************************************************
; the procedure to handle about dialog messages
;****************************************************************
DlgProc PROC hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,uMsg
.if eax==WM_INITDIALOG
push hWin
pop hWnd
.elseif eax==WM_COMMAND
mov eax,wParam
and eax,0FFFFh
.if eax==IDC_ABOUT_OK
invoke SendMessage,hWin,WM_CLOSE,0,0
.endif
.elseif eax==WM_CLOSE
invoke DestroyWindow,hWin
.elseif uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.endif
xor    eax,eax
ret

DlgProc ENDP


here's another function:

;****************************************************************
; the procedure to show the about dialog
;****************************************************************
ShowAboutDialog PROC
invoke CreateDialogParam,hInstance,IDD_ABOUT,NULL,addr WndProc,NULL
ret
ShowAboutDialog ENDP


I've done some more as well, but i cannot retrieve the code anymore. I didn't want to keep every thing i tried since it would make me confused.

here's the code that hutch showed me, but i haven't got a clue on how to implement a hyperlink and text here. (without using paint)

       invoke GetModuleHandle,NULL
      mov hInstance,eax

      call main

      invoke ExitProcess,eax

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    Dialog "About Dialog", \             ; caption
           "MS Sans Serif",10, \            ; font,pointsize
            WS_OVERLAPPED or \              ; styles for
            WS_SYSMENU or DS_CENTER, \      ; dialog window
            1, \                           ; number of controls
            50,50,230,150, \                ; x y co-ordinates
            1024                            ; memory buffer size

    DlgButton "OK",WS_TABSTOP,162,100,50,12,250

    CallModalDialog hInstance,0,dlgproc,NULL

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

dlgproc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    .if uMsg == WM_INITDIALOG
       invoke LoadIcon,NULL,IDI_ASTERISK
      invoke SendMessage,hWin,WM_SETICON,1,eax
                       
    .elseif uMsg == WM_COMMAND

      .elseif wParam == 250     ; OK
        jmp quit_dialog
      .endif

    .elseif uMsg == WM_CLOSE
      quit_dialog:
      invoke EndDialog,hWin,0

    .endif

    xor eax, eax
    ret

dlgproc endp

This code is working though.

ToutEnMasm

Hello,
Further things are important to know before writing dialog box.
1) The dialog is the main window or not  (it is not the same loop)
2) In the ressource the dialog is designed by a number or a name
    If it is a name , verify that others instructions don't refer to the name with a number in the rc file
     when creating verify that the name is in the data .
3) when ending,the return value is not the same as a normal window
4) creating the dialog with CreateDialogParam or DialogBoxParam have not the same effect.

Follow a child dialog,with a named resource and choice between CreateDialogParam and DialogBoxParam.it must work at the first time
                           
if your resource is named IDD_NAMEDRES (modify NAMEDRES) try this ,it must work at the first time

                           ToutEnMasm


;call the dialog like that
invoke DialogBox
;----------- declare
DialogBox     PROTO
DlgDialogBox   PROTO  :DWORD,:DWORD,:DWORD,:DWORD
;---------------------------------------------------
;################################################################
DialogBox  PROC
local valeurinitialisation :DWORD
                                jmp overtext
zzzzDialogBox db "IDD_NAMEDRES",0
                                overtext:
mov eax,NULL
mov valeurinitialisation,eax
;*** you can clic only inside the dialog  *******
invoke CreateDialogParam,Hinst, addr zzzzDialogBox,Hwnd,OFFSET DlgDialogBox,valeurinitialisation
;you can clic inside and outside the dialog
;invoke DialogBoxParam,Hinst, addr zzzzDialogBox,Hwnd,OFFSET DlgDialogBox,valeurinitialisation
;invoke SetFocus,Hredit

FindeDialogBox:
ret
DialogBox endp

;################################################################

DlgDialogBox  PROC HdialBox:DWORD,uMsg:DWORD,wParam:DWORD, lParam:DWORD
Local HListBox1:DWORD
Local phrase[MAX_PATH]:BYTE

; gere les evenements
.if     uMsg == WM_INITDIALOG
;quelques incantations utiles
;  invoke GetDlgItem,HdialBox,IDC_LISTBOX1
;  mov HListBox1,eax
;  invoke SetFocus,eax
;  invoke SetWindowLong,HListBox1,GWL_WNDPROC,EventDldBlocNote
;invoke SendDlgItemMessage,HdialBox,IDC_EDITRECAPI,WM_SETTEXT,0,addr MotderechercheAPI
; .if eax == 0
mov eax,FALSE
; INVOKE     SendMessage,HdialBox , WM_CLOSE, 0 ,0
;  .endif
                .elseif uMsg == WM_COMMAND
return TRUE ;windows put focus
;return FALSE ; the dialog put the focus
.elseif uMsg == WM_CLOSE
invoke EndDialog,HdialBox,NULL
.elseif uMsg == WM_COMMAND
HIWORD wParam ;evenements des listbox ,combo sont ici
mov edx,eax
LOWORD wParam ;IDentificateurs de  commandes
mov ebx,lParam ; handle du controle
.if eax == 0 ;remplacer par ID boutons ....
.elseif eax == 1
.endif
.else
mov eax,FALSE
jmp FindeDlgDialogBox
.endif
mov  eax,TRUE
FindeDlgDialogBox:
ret
DlgDialogBox endp

;#########################################################################





white scorpion

I'm sure this will work if i copy and paste your code, but i still haven't got a clue why this would work.

1) I understand i can't use the WndProc for my second dialog.
2) This i know, it's the same as every other resource, declare in .rc, declare in .asm like "IDC_BUTTON equ 1000"
3) why is the return value important? as far as i can tell it's never checked.
4) This i do not understand.

Some questions:
- Should i use the same dialogclass as the main one, or should i use a different one?
- I must use another MessageLoop for every dialogbox?
- Should i start the whole process again like in WinMain for every dialogbox?
- I like the in memory dialogboxes, isn't this a good option?
- If so, how do i put text, hyperlink etc in the in memory dialogbox?


white scorpion

Well,

Got the in memory dialog box working and studied the dialog.inc file for more info.
I think this is the most easy solution, but i still have a question about it:


;****************************************************************
; the procedure to show the about dialog
;****************************************************************
ShowAboutDialog PROC
Dialog "About","MS Sans Serif",8,WS_OVERLAPPED or WS_SYSMENU or DS_CENTER,\
2,50,50,160,150,1024
    DlgButton "OK",WS_TABSTOP,45,100,70,20,250   
    DlgStatic "http://www.white-scorpion.nl",WS_TABSTOP,30,85,100,12,251   
    CallModalDialog hInstance,0,AboutDlgProc,NULL
ret
ShowAboutDialog ENDP

;****************************************************************
; the procedure to process the about dialog messages
;****************************************************************
AboutDlgProc PROC hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
    .if uMsg==WM_INITDIALOG
    invoke LoadIcon,NULL,IDI_ASTERISK
      invoke SendMessage,hWin,WM_SETICON,1,eax
    .elseif uMsg==WM_COMMAND
    .if wParam==250
        jmp quit_dialog
        .elseif wParam==251
        invoke  ShellExecute, NULL, offset szOpen, offset MySite, NULL, NULL, SW_MAXIMIZE
      .endif
    .elseif uMsg==WM_CLOSE
      quit_dialog:
      invoke EndDialog,hWin,0
    .endif
    xor eax,eax
    ret
AboutDlgProc ENDP


This is the code i used, it works great, but as you can see i haven't put in any text yet.
Is it possible to put in multilines of text using the DlgStatic macro?

Second and final question: as you can see i've tried to use the url as hyperlink to my website using ShellExexute, but this doesn't work.
What should i add to get it to work?
I don't necessarily need to change the url text if a mouse get's hoovered over it.

Thanks a lot for all of your time!

PBrennick

White Scorpion,
Here is an extraction of the code that you need from my program.  The beginning lines tell you how to weave it into your program.

;-----------------------------------------------------;
; Add all the MugShot files to the project and do the ;
; appropriate includes as listed below:               ;
;     In the .asm file use, include MugShot.asm       ;
;     In the .rc  file use, #include <MugShot.rc>     ;
; Finally, add the code below to the Messaging loop.  ;
;-----------------------------------------------------;
; .ElseIf Eax == IDM_ABOUT                            ;
;   invoke  CreateDialogParam, hInst, addr AboutName, ;
;           hWnd, OFFSET AboutDlgProc, NULL           ;
;-----------------------------------------------------;

AboutDlgProc        PROTO  hWnd:HWND, iMsg:DWORD, wParam:WPARAM, lParam:LPARAM
HyperLinkWndProc    PROTO   :DWORD, :DWORD, :DWORD, :DWORD
;
.const
;---------------------------------------
IDC_URL             equ 9
IDC_EXIT            equ 3002
;
.data
;---------------------------------------;
szOpen         db  "open", 0            ; Action to perform
;
.data?
;---------------------------------------
; Structures used by the Printer Routines
doci    DOCINFO         <?>             ; Docinfo (printing support)
fr_1    FORMATRANGE     <?>             ; For EM_FORMATRANGE
psd     PAGESETUPDLG    <?>             ; Page setup common dialog structure
pd      PRINTDLG        <?>             ; Print
rect_1  RECT            <?>             ; Rectangle
;
hover           BOOL    ?
orgStatic       DD      ?
hFinger         DD      ?
buff            db      256 dup (?)
;
.code
;---------------------------------------
HyperLinkWndProc PROC uses ebx HWnd:DWORD,
                      uMsg:DWORD,
                      wParam:DWORD,
                      lParam:DWORD
;---------------------------------------
        Local   tmpFont:LOGFONT
        Local   rect:RECT
        Local   pt:POINT
;
        mov     eax, uMsg
        .if eax==WM_NCHITTEST
          mov     eax, 1                ; We want to handle the non client hit test so we return true or 1
          ret
        .elseif eax == WM_CTLCOLORSTATIC
          push    ebx
          push    edx
          invoke  SendMessage, HWnd, WM_GETFONT, 0, 0
          mov     edx, eax
          invoke  GetObject, edx, sizeof LOGFONT, addr tmpFont
          mov     tmpFont.lfUnderline, TRUE
          invoke  CreateFontIndirect, addr tmpFont
          mov     ebx, eax
          invoke  SelectObject, wParam, ebx
          .if hover == FALSE
            invoke  SetTextColor, wParam, Blue
          .else
            invoke  SetTextColor, wParam, Red
          .endif
          invoke  GetSysColor, COLOR_MENU
          invoke  SetBkColor, wParam, eax
          invoke  DeleteObject, ebx
          invoke  GetStockObject, HOLLOW_BRUSH
          pop     edx
          pop     ebx
          ret
        .elseif eax==WM_MOUSEMOVE
          invoke  GetParent, HWnd
          push    ebx
          mov     ebx, eax
          invoke  GetActiveWindow
          .if eax == ebx
            invoke  GetCursorPos, addr pt
            invoke  GetWindowRect, HWnd, addr rect
            invoke  PtInRect, addr rect, pt.x, pt.y
            .if eax
              invoke  GetCapture
              .if !eax
                invoke  SetCapture, HWnd
                mov     hover, TRUE
                invoke  InvalidateRect, HWnd, FALSE, FALSE
                invoke  SetCursor, hFinger
              .endif
            .else
              invoke  GetCapture
              .if eax
                invoke  ReleaseCapture
                mov     hover, FALSE
                invoke  InvalidateRect, HWnd, FALSE, FALSE
              .endif
            .endif
          .endif
          pop     ebx
          xor     eax, eax
          ret
        .elseif eax==WM_LBUTTONDOWN
          invoke  GetWindowText, HWnd, offset buff, sizeof buff ; Change this for using a preset url
          invoke  ShellExecute, NULL, offset szOpen, offset buff, NULL, NULL, SW_MAXIMIZE   ; Change this to represent your preset url
          mov     hover, FALSE
          invoke  InvalidateRect, HWnd, FALSE, FALSE
          invoke  SendMessage, HWnd, WM_GETFONT, 0, 0           ; Get the defualt system font
          mov     edx, eax                                      ; Store result
          invoke  GetObject, edx, sizeof LOGFONT, addr tmpFont  ; Get our font into a logfont structure
          mov     tmpFont.lfUnderline, TRUE                     ; Under line the link
          invoke  CreateFontIndirect, addr tmpFont              ; Create the new font
          mov     ebx, eax                                      ; We need the return to free the memory later
          invoke  SelectObject, wParam, ebx                     ; Select our control
          invoke  SetTextColor, wParam, Blue                    ; Change this to change the color of the link
          xor     eax, eax                                      ; No errors
          ret                                                   ; Return
        .endif
        invoke  CallWindowProc, orgStatic, HWnd, uMsg, wParam, lParam   ;Passes message information to the next stop
        ret                                                 ; Return
;---------------------------------------
HyperLinkWndProc endp
;
;
AboutDlgProc proc hwnd:HWND, iMsg:DWORD, wParam:WPARAM, lParam:LPARAM
;---------------------------------------
        mov     eax, iMsg
        .if eax==WM_INITDIALOG
          invoke  GetDlgItem, hwnd, IDC_URL
          invoke  SetWindowLong, eax, GWL_WNDPROC, ADDR HyperLinkWndProc
          mov     orgStatic, eax
          mov     hFinger, eax
          xor     eax, eax
          ret
        .elseif eax == WM_CTLCOLORSTATIC
          invoke  SendMessage, lParam, iMsg, wParam, lParam
          ret
        .elseif eax==WM_CLOSE
          invoke  EndDialog, hwnd, NULL
        .elseif eax==WM_COMMAND
          push    edx
          mov     eax, wParam
          mov     edx, eax
          shr     edx, 16
          .if eax==IDC_EXIT
            invoke  SendMessage, hwnd, WM_CLOSE, NULL, NULL
            invoke  EndDialog, hwnd, NULL
          .endif
          pop     edx
        .else
          mov     eax, FALSE
          ret
        .endif
        mov      eax, TRUE
        ret
;---------------------------------------
AboutDlgProc endp


You do not need to alter the abovr two procedures.  The only changes you need to make are in the resource file to make sure the hyperlink will go to your site.

#include    <\masm32\include\resource.h>
                                         
#define     IDC_STATIC          -1
#define     IDB_TBRBMP          150
#define     VK_F3               0x72
#define     VK_DELETE           0x2E
#define     IDR_ACCEL           200
#define     IDB_BITMAP3         103
#define     IDC_EXIT            3002
#define     IDC_IMAGE3001       3001
#define     IDC_URL             9

// IDB_BITMAP3 must be defined before the bitmap is loaded.  If this rule is not
// followed, the program will compile without errors, but there will be runtime
// errors that will cause the bitmaps to remain unviewable.  It interesting to
// note that these errors will not cause the application to fail!

IDB_BITMAP3 BITMAP DISCARDABLE  "MugShot.bmp"

ABOUTDIALOG DIALOGEX 0,0,172,76
CAPTION "GeneSys MugShot"
FONT 8,"MS Sans Serif"
STYLE 0x90C80800
EXSTYLE 0x00000000
BEGIN
  CONTROL "GeneSys Mugshot 1.0.0\nWritten by Paul Brennick\nMay 27, 2006",IDC_STATIC,"Static",0x50020001,60,10,100,30,0x00000000
  CONTROL "OK",IDC_EXIT,"Button",0x50010001,85,55,50,14,0x00000000
  CONTROL "#103",IDC_IMAGE3001,"Static",0x1000000E,5,10,65,82,0x00000201
  CONTROL "http://www.pbrennick.com",IDC_URL,"Static",0x50020201,60,35,100,11,0x00000000
END



As you can see in the above, you need to make changes to two Controls.  You need to replace my website address with yours  and the Control that says Written by Paul E. Brennick and has a date - well, change them accordingly.at is ALL you have to do.  This will yeild an About box that does not have the look and feel that you need.  My MugShot, for example needs to be changed.  But you should do it EXACTLY as I say and DO NOT go off on a tanget, YET.   First, you need a working example.  This will give it to you.  From there and only after you have a working project, you would, then, go in and change the dialog box in MugShot.rc according to your needs.

The files needed are attached.

Paul


[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website

white scorpion

Paul,

Your code certainly is a great help in understanding the matter.
To be honest i got enough of trying to get a decent working dialog & hyperlink that i've solved the issue with a very simple:

ShowAboutDialog PROC
Dialog "My About Box","MS Sans Serif",8,WS_OVERLAPPED or WS_SYSMENU or DS_CENTER,\
2,50,50,160,150,1024
    DlgButton "OK",WS_TABSTOP,45,100,70,20,250 
    DlgButton "http://www.white-scorpion.nl",WS_TABSTOP or BS_FLAT,30,85,100,12,251
    CallModalDialog hInstance,0,AboutDlgProc,NULL
ret
ShowAboutDialog ENDP


The only thing that remains is making the color of the text on the button blue, but i doubt that should be very hard if i hold your code next to it.
I will use your code as reference for future programs, but for now i'll just stick to this so i can finally start concentrating on the algo and random generator for my program.

Thanks for your help!

Mark