Konsolenprogramm und Dialog ... einmal gehts, einmal net

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Konsolenprogramm und Dialog ... einmal gehts, einmal net

    hallo,

    ich habe eine dll geschrieben. die habe ich selber mit den mfc-libraries ergänzt (ohne assistent), um dialoge und messageboxes aufpoppen zu können.
    meine dll wird von einem tool benutzt, das sowohl als windowsapplikation, als auch als konsolenapplikation verwendet wird.

    mein dialog wird in der windowsapplikation einwandfrei aufgepoppt. jedoch bleibt der prozess an der stelle des aufpoppens in der
    konsolenapplikation hängen (vermute mal, da er kein mainwindow findet).
    wie kann ich denn in der konsolenappliaktion den dialog aufrufen?
    kann ich eine fakewindow erzeugen oder so?

    Kurioses:
    meine dll hat 2 modes.
    in einem rufe ich mit doModal() einen filedialog vor meinem dialog auf.
    dieser filedialog funktioniert auch in der konsolenapplikation. anschließend würde mein dialog aufpoppen. und siehe da .. es poppt auch auf.
    somit habe ich festgestellt, dass auch wenn ich vorher nur eine afxmessagebox aufrufe, mein dialog auf einmal funktioniert.
    in dem 2ten mode benötige ich kein filedialog. und dann bleibt der prozess hängen. also was macht der filedialog und die afxmessagebox, dass es danach geht?
    fehlt was in meiner klasse? aber was?

    also nochmal...
    wenn ich in der konsolenapplikation nur meinen dialog aufpoppen will, dann geht es nicht.
    wenn ich vorher cfiledialog oder afxmessagebox aufrufe, dann geht mein dialog danach auch.

    hier meine dialog-klasse. habe ein wenig raus, da es meine diplomarbeit ist ... aber nur die combobox-sachen und so ... also nix dialogrelevantes.

    Quellcode

    1. #pragma once
    2. #include "afxwin.h"
    3. #include "resource.h"
    4. class CMyDlg : public CDialog
    5. {
    6. DECLARE_DYNAMIC(CMyDlg)
    7. public:
    8. CMyDlg(CWnd* pParent = NULL);
    9. virtual ~CMyDlg();
    10. // Dialog Data
    11. enum { IDD = IDD_MYDLG };
    12. protected:
    13. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    14. virtual BOOL OnInitDialog();
    15. DECLARE_MESSAGE_MAP()
    16. public:
    17. afx_msg void OnBnClickedOk();
    18. afx_msg void OnCbnSelchangeCombo();
    19. CComboBox m_ComboCtrl;
    20. };
    Alles anzeigen

    Quellcode

    1. #include "stdafx.h"
    2. #include "MyDlg.h"
    3. #include <string>
    4. IMPLEMENT_DYNAMIC(CMyDlg, CDialog)
    5. CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
    6. : CDialog(CMyDlg::IDD, pParent)
    7. {
    8. }
    9. CMyDlg::~CMyDlg()
    10. {
    11. }
    12. void CMyDlg::DoDataExchange(CDataExchange* pDX)
    13. {
    14. CDialog::DoDataExchange(pDX);
    15. DDX_Control(pDX, IDC_COMBO, m_ComboCtrl);
    16. }
    17. BOOL CMyDlg::OnInitDialog()
    18. {
    19. CDialog::OnInitDialog();
    20. return TRUE;
    21. }
    22. BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
    23. ON_BN_CLICKED(IDOK, &CMyDlg::OnBnClickedOk)
    24. ON_CBN_SELCHANGE(IDC_COMBO, &CMyDlg::OnCbnSelchangeCombo)
    25. END_MESSAGE_MAP()
    26. // CMyDlg message handlers
    27. void CMyDlg::OnBnClickedOk()
    28. {
    29. // TODO: Add your control notification handler code here
    30. OnOK();
    31. }
    Alles anzeigen


    danke schonmal
    Gruß
    Steff
    ___

    Der Optimist sieht in jedem Problem eine Aufgabe.
    Der Pessimist sieht in jeder Aufgabe ein Problem.

    http://autoexport.sunbird-kalender.de
  • hi, danke erstmal für die schnelle antwort

    also in der funktion DoModal() hängt er im try-block (siehe 1. unten) bei ... "VERIFY(RunModalLoop(dwFlags) == m_nModalResult);"
    wenn ich reinsteppe, dann kommt er zu der funktion ... "int CWnd::RunModalLoop(DWORD dwFlags)" (siehe 2. unten)
    darin läuft er die endlos for-schleife durch und darin die while und die do-while schleife.
    erst im 2. for-schleifen durchlauf bleibt er in der do-while schleife bei "AfxPumpMessage()" hängen.
    wenn ich hier reinsteppe ruft er "AfxInternalPumpMessage()" auf, wo er dann endgültig bei
    "if (!::GetMessage(&(pState->m_msgCur), NULL, NULL, NULL))" hängen bleibt. da kann ich auch nimmer reinsteppen.

    windows-api dialoge habe ich noch nie gemacht und mfc wäre mir dann schon lieber,
    da ich es ja sowieso wegen den messageboxen und asserts eingefügt habe.

    comment ... Kann es sein, dass MFC in der Konsole-Application nicht richtig initialisiert wurde?
    wie meinst du das? ich rufe halt vorher "AFX_MANAGE_STATE(AfxGetStaticModuleState());" auf.
    speziell habe ich nix initialisiert.
    aber sonst funktioniert ja alles (filedialog und afxmessagebox; und auch mein dialog wenn ich eins der beiden vorher aufrufe).

    1.

    Quellcode

    1. TRY
    2. {
    3. // create modeless dialog
    4. AfxHookWindowCreate(this);
    5. if (CreateDlgIndirect(lpDialogTemplate,
    6. CWnd::FromHandle(hWndParent), hInst))
    7. {
    8. if (m_nFlags & WF_CONTINUEMODAL)
    9. {
    10. // enter modal loop
    11. DWORD dwFlags = MLF_SHOWONIDLE;
    12. if (GetStyle() & DS_NOIDLEMSG)
    13. dwFlags |= MLF_NOIDLEMSG;
    14. VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
    15. }
    16. // hide the window before enabling the parent, etc.
    17. if (m_hWnd != NULL)
    18. SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW|
    19. SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
    20. }
    21. }
    Alles anzeigen

    2.

    Quellcode

    1. int CWnd::RunModalLoop(DWORD dwFlags)
    2. {
    3. ASSERT(::IsWindow(m_hWnd)); // window must be created
    4. ASSERT(!(m_nFlags & WF_MODALLOOP)); // window must not already be in modal state
    5. // for tracking the idle time state
    6. BOOL bIdle = TRUE;
    7. LONG lIdleCount = 0;
    8. BOOL bShowIdle = (dwFlags & MLF_SHOWONIDLE) && !(GetStyle() & WS_VISIBLE);
    9. HWND hWndParent = ::GetParent(m_hWnd);
    10. m_nFlags |= (WF_MODALLOOP|WF_CONTINUEMODAL);
    11. MSG *pMsg = AfxGetCurrentMessage();
    12. // acquire and dispatch messages until the modal state is done
    13. for (;;)
    14. {
    15. ASSERT(ContinueModal());
    16. // phase1: check to see if we can do idle work
    17. while (bIdle &&
    18. !::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE))
    19. {
    20. ASSERT(ContinueModal());
    21. // show the dialog when the message queue goes idle
    22. if (bShowIdle)
    23. {
    24. ShowWindow(SW_SHOWNORMAL);
    25. UpdateWindow();
    26. bShowIdle = FALSE;
    27. }
    28. // call OnIdle while in bIdle state
    29. if (!(dwFlags & MLF_NOIDLEMSG) && hWndParent != NULL && lIdleCount == 0)
    30. {
    31. // send WM_ENTERIDLE to the parent
    32. ::SendMessage(hWndParent, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)m_hWnd);
    33. }
    34. if ((dwFlags & MLF_NOKICKIDLE) ||
    35. !SendMessage(WM_KICKIDLE, MSGF_DIALOGBOX, lIdleCount++))
    36. {
    37. // stop idle processing next time
    38. bIdle = FALSE;
    39. }
    40. }
    41. // phase2: pump messages while available
    42. do
    43. {
    44. ASSERT(ContinueModal());
    45. // pump message, but quit on WM_QUIT
    46. if (!AfxPumpMessage())
    47. {
    48. AfxPostQuitMessage(0);
    49. return -1;
    50. }
    51. // show the window when certain special messages rec'd
    52. if (bShowIdle &&
    53. (pMsg->message == 0x118 || pMsg->message == WM_SYSKEYDOWN))
    54. {
    55. ShowWindow(SW_SHOWNORMAL);
    56. UpdateWindow();
    57. bShowIdle = FALSE;
    58. }
    59. if (!ContinueModal())
    60. goto ExitModal;
    61. // reset "no idle" state after pumping "normal" message
    62. if (AfxIsIdleMessage(pMsg))
    63. {
    64. bIdle = TRUE;
    65. lIdleCount = 0;
    66. }
    67. } while (::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE));
    68. }
    69. ExitModal:
    70. m_nFlags &= ~(WF_MODALLOOP|WF_CONTINUEMODAL);
    71. return m_nModalResult;
    72. }
    Alles anzeigen
    Gruß
    Steff
    ___

    Der Optimist sieht in jedem Problem eine Aufgabe.
    Der Pessimist sieht in jeder Aufgabe ein Problem.

    http://autoexport.sunbird-kalender.de