Problème de focus entre deux dialogBox

Résolu
cs_parki Messages postés 75 Date d'inscription mardi 29 juillet 2008 Statut Membre Dernière intervention 25 mars 2019 - 10 janv. 2013 à 11:21
cs_parki Messages postés 75 Date d'inscription mardi 29 juillet 2008 Statut Membre Dernière intervention 25 mars 2019 - 13 janv. 2013 à 12:27
Bonjour,je veux utiliser plusieurs boites de dialogues dans un prog MASM.J'affiche la seconde boite de dialogue grâce au menu de la première,mais lorsque je ferme la seconde boite de dialogue,la fenêtre principale (=la première dialog box) n'a plus le focus.
J'ai essayé plusieurs combinaison possibles (fenetre normale qui ouvre une dialogueBox non modale,dialog box non modale qui en ouvre une autre,dialog box non modale qui ouvre une dialog box modale) mais j'ai toujours le même problème;à la fermeture de la seconde dialog box,la fenétre parent est inactivée.
J'ai étudié de près les tuts de ICZELION sur le sujet,les dialog box prédefinies de windows (GetOpenFileName,..)fonctionnent sans problème,mais dès que j'essaie de travailler avec deux dialogbox perso en ressource,j'ai le même problème.
Je suis sous windows XP.

voici le code asm;

.386
.model flat,stdcall
option casemap:none

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
WndProc proto :DWORD,:DWORD,:DWORD,:DWORD
;proc des DBOX secondaires
DBOX_CONFIGURATION proto :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\windows.inc

include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comctl32.inc

includelib \masm32\lib\comctl32.lib ;lib des controles windows
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
ClassName db "DLGCLASS",0
MenuName db "AU_MENU",0
DlgName db "MyDialog",0
DlgName1 db "DBOX_CONFIG",0
AppName db "Our First Dialog Box",0
wc WNDCLASSEX <48,CS_HREDRAW or CS_VREDRAW,WndProc,0,DLGWINDOWEXTRA,hInstance,0,0,COLOR_WINDOW+1,MenuName,ClassName,0>

.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
buffer db 512 dup(?)

HDL_DBOX_PRINCIPALE DWORD ? ;hdle DBOX principale
HDL_DBOX_CONFIG DWORD ?

.const


;define icone
;------------

PersoICON equ 100

;define de la dialogbox principale
;---------------------------------

IDC_TAB1 equ 32000

;menu fichiers
IDM_Nouveau_projet equ 3000
IDM_Ouvrir_projet equ 3001
IDM_Enregistrer_projet equ 3002
IDM_Supprimer_projet equ 3003
IDM_Ouvrir_fichier equ 3004
IDM_EXIT equ 3005

;define de la DBOX fichiers/Nouveau projet/CONFIGURATION
;-------------------------------------------------------

IDD_DLG1 equ 1000
IDC_RBN1 equ 1001
IDC_RBN2 equ 1002
IDC_CHK1 equ 1003
IDC_CHK2 equ 1004
IDC_STC1 equ 1005
IDC_EDT1 equ 1006
IDC_quit_config equ 1007

.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax

invoke InitCommonControls ;non executé,pour le loader qui chargera "comctl32.lib"

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD

LOCAL msg:MSG

push hInst
pop wc.hInstance

invoke LoadIcon,hInst,PersoICON
mov wc.hIcon,eax ;grand icone
mov wc.hIconSm,eax ;petit icone

invoke RegisterClassEx, addr wc


;dialog Box non modale (peut donner le focus à une autre)
invoke CreateDialogParam,hInstance,ADDR DlgName,NULL,addr WndProc,NULL
mov HDL_DBOX_PRINCIPALE,eax

invoke ShowWindow, HDL_DBOX_PRINCIPALE,SW_SHOWNORMAL
invoke UpdateWindow, HDL_DBOX_PRINCIPALE

.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
;les événements clavier de la BOXprincipale sont
;gérés par WINDOWS (IsDialogMessage renvoie TRUE si c'est un
;message concernant la BOX,FALSE sinon)
invoke IsDialogMessage, HDL_DBOX_PRINCIPALE, ADDR msg
.IF eax ==FALSE
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDIF
.ENDW
mov eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd_DBOX_PRINCIPALE:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

; traitement des messages de la BOX PRINCIPALE

.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_INITDIALOG
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF ax==IDM_Nouveau_projet

invoke CreateDialogParam,hInstance,ADDR DlgName1,hWnd_DBOX_PRINCIPALE,addr DBOX_CONFIGURATION,0
mov HDL_DBOX_CONFIG,eax

;ca ne marche pas non plus avec
;invoke DialogBoxParam,hInstance,IDD_DLG1,hWnd,addr DBOX_CONFIGURATION,0
;mov HDL_DBOX_CONFIG,eax


.ELSEIF ax==IDM_EXIT
invoke DestroyWindow,hWnd_DBOX_PRINCIPALE
.ENDIF
.ELSE
invoke DefWindowProc,hWnd_DBOX_PRINCIPALE,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp

DBOX_CONFIGURATION proc hWND_DBOX_CONFIG:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

.if uMsg==WM_INITDIALOG

.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
mov edx,wParam
shr edx,16
.IF dx==BN_CLICKED
.if ax==IDC_quit_config
invoke EndDialog,hWND_DBOX_CONFIG,0
.endif
.ENDIF
.ELSEIF uMsg==WM_DESTROY
invoke SetFocus,HDL_DBOX_PRINCIPALE
.endif

ret

DBOX_CONFIGURATION endp
end start


le fichier RC;
--------------

#include "DefRc.inc" ;def supplementaire pour les ressources

;icone de l'application
;----------------------

#define PersoICON 100
PersoICON ICON DISCARDABLE "essai.ico"

;---------------------
;Dialog box principale
;---------------------

;define de la dialogbox principale
#define IDC_TAB1 32000

;define du menu de la dialogbox principale

;menu fichiers
#define IDM_Nouveau_projet 3000
#define IDM_Ouvrir_projet 3001
#define IDM_Enregistrer_projet 3002
#define IDM_Supprimer_projet 3003
#define IDM_Ouvrir_fichier 3004
#define IDM_EXIT 3005

;dialog box
MyDialog DIALOGEX 6,6,609,459
CAPTION "Our First Dialog Box"
FONT 8,"MS Sans Serif",400,0
STYLE 0x10CF0000
EXSTYLE 0x00000000
CLASS "DLGCLASS"
BEGIN
;CONTROL "",IDC_TAB1,"SysTabControl32",0x50018200,16,16,556,419,0x00000000
END

;menu de la dialogbox

AU_MENU MENU
BEGIN
POPUP "Fichiers"
BEGIN
MENUITEM "Nouveau Projet", IDM_Nouveau_projet
MENUITEM "Ouvrir Projet", IDM_Ouvrir_projet
MENUITEM "Enregistrer Projet",IDM_Enregistrer_projet
MENUITEM "Supprimer Projet",IDM_Supprimer_projet
MENUITEM "Ouvrir Fichier",IDM_Ouvrir_fichier
MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
MENUITEM "E&xit", IDM_EXIT
END

END

;-----------------------------------------------
;dialogbox fichiers/Nouveau projet/CONFIGURATION
;-----------------------------------------------

;define de la DBOX

#define IDD_DLG1 1000
#define IDC_RBN1 1001
#define IDC_RBN2 1002
#define IDC_CHK1 1003
#define IDC_CHK2 1004
#define IDC_STC1 1005
#define IDC_EDT1 1006
#define IDC_quit_config 1007

;DBOX

;IDD_DLG1 DIALOGEX 6,6,243,132
DBOX_CONFIG DIALOGEX 6,6,243,132
CAPTION "Configuration"
FONT 8,"MS Sans Serif",400,0
STYLE 0x10CF0000
EXSTYLE 0x00000000
BEGIN
CONTROL " ASM 16 Bits",IDC_RBN1,"Button",0x50010009,18,16,66,12,0x00000000
CONTROL " ASM 32 Bits",IDC_RBN2,"Button",0x50010009,130,16,66,12,0x00000000
CONTROL " Suppression des .OBJ",IDC_CHK1,"Button",0x50010003,66,72,88,12,0x00000000
CONTROL " Suppression des .LST",IDC_CHK2,"Button",0x50010003,66,96,88,12,0x00000000
CONTROL " Nom du répertoire du projet",IDC_STC1,"Static",0x50001000,14,46,98,9,0x00000000
CONTROL "",IDC_EDT1,"Edit",0x50010000,118,44,98,13,0x00000200
PUSHBUTTON "OK",IDC_quit_config,10,10,52,13
END

qu'est ce qui ne va pas ???

3 réponses

cs_parki Messages postés 75 Date d'inscription mardi 29 juillet 2008 Statut Membre Dernière intervention 25 mars 2019
13 janv. 2013 à 12:27
Un grand MERCI ToutEnMasm,j'ai rajouté dans la definition de la deuxième dialogBox WS_CHILD et ça marche.

Bonne Prog.
3
ToutEnMasm Messages postés 587 Date d'inscription jeudi 28 novembre 2002 Statut Membre Dernière intervention 13 décembre 2022 3
12 janv. 2013 à 18:09
Les dialog box n'ont pas le même comportement qu'une fenêtre.
Pour ce genre de problême il faut chercher..
Essayer setfocus (sur la main dialog) en fermant la dialog fille.
On peut essayer une propriété child.
0
cs_parki Messages postés 75 Date d'inscription mardi 29 juillet 2008 Statut Membre Dernière intervention 25 mars 2019
13 janv. 2013 à 12:08
j'ai le même problème en rendant le focus à la DialogBox principale quand je quitte .
Je vais chercher du coté des propriétées child.
Merci du conseil.
0
Rejoignez-nous