Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Dialog Box based App.

VinayKhareVinayKhare Member Posts: 69
Hello Everybody,

I do not know programming dialog based programming very well, but after a lot of effort I got to write the following code:
[code]
//Program to take the Name of person as input in a TEXT box and display //it in a MessageBox
//I created a dialog box with id = "IDD_ASK" which include a "Text Box" //with the id = "IDC_NAME" and OK and CANCEL button with the ids "IDOK" //and "IDCANCEL".
#include
#include "resource.h"

HINSTANCE TheInstance = 0;
HWND hDialog;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd);
LRESULT CALLBACK DialogProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
MSG m;
TheInstance = hInstance;
DialogBox(TheInstance, MAKEINTRESOURCE(IDD_ASK),hDialog, reinterpret_cast(DialogProc));
/*hDialog = CreateDialog(TheInstance,MAKEINTRESOURCE(IDD_ASK),0,(DLGPROC)DialogProc);
ShowWindow(hDialog,SW_SHOW); */
while ( GetMessage (&m, NULL, 0, 0 ) )
{
if (!IsDialogMessage (hDialog, &m))
{
TranslateMessage ( &m );
DispatchMessage ( &m );
}
}
return m.wParam;
}

LRESULT CALLBACK DialogProc(HWND hWnd,UINT m,WPARAM wParam,LPARAM lParam)
{
char buf[30];
switch(m)
{
case WM_INITDIALOG:
GetDlgItem(hWnd,IDC_NAME);
SetFocus(hWnd);
return TRUE;
case WM_COMMAND:
{
switch(LOWORD(wParam))
case IDOK:
MessageBox(hWnd,buf,"Name is:",MB_OK);
case IDCANCEL:
EndDialog (hWnd, 0);
return TRUE;
case IDC_NAME:
SendMessage (hWnd, WM_SETTEXT, 0, (LPARAM) buf);
return TRUE;
}
case WM_CLOSE:
EndDialog(hWnd,0);
DestroyWindow (hWnd);
return TRUE;
}
return FALSE;
}
[/code]
Compiling and Linking: 0 error, 0 warning.

Q: After executing When I clicked over the the text box, window disappears. Why? and How to correct it?

->When I clicked over ok button directly. Message Box appears.

Q: Can you please provide me a code for same(non - MFC). So that I could understand the right way of implementing this.

Q: Program doesn't end in any situation. I have to close it through Task Manager everytime I run it. Why?

And finally, can you please provide me some online tutorials for vc++ (resource programming)

Comments

  • toddlerasimtoddlerasim Member Posts: 93
    I was waiting for somebody more experienced to answer your query but since there seems to be no answer let me see if I can be of any help. As far as I can make out when you press ID_OK you get the message box popping out. This is mainly due to the fact that you have coded the message box in your ID_OK button. It has to pop out then. Regarding your window disappearing when you click the text box I think it is the lack of break in your case statements that seems to be responsible for that.

    But then I am a toddler in C/C++.
Sign In or Register to comment.