0

i have created a dialogbox using c++ win32 API... there are 3 text box,1 combo box and 3 buttons...

now i have 2 problems...

1.when i press the ENTER button,it invoke second button(ID_OK) function,but i want to invoke first button(ID_MYBUTTON)...

2.i am using the code to focus a textbox is,

SetFocus(GetDlgItem(_hwnd, IDC_NAME));

But it cant focus that dialogbox,i mean cursor position is there,but cant get any value,when i typed...

Can anyone resolve it?

Arjun babu
  • 607
  • 2
  • 13
  • 42

1 Answers1

2

This may answer both your questions: http://blogs.msdn.com/b/oldnewthing/archive/2004/08/02/205624.aspx:

Use the DM_SETDEFID message to set the default button in a dialog

Use the WM_NEXTDLGCTL message instead of SetFocus()

// set default button
SendMessage(_hwnd, DM_SETDEFID, (WPARAM)ID_MYBUTTON, 0);
//TODO: if the former default button's style remains, update with BM_SETSTYLE

// set focus
SendMessage(_hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(_hwnd, IDC_NAME), TRUE);
Community
  • 1
  • 1
Anonymous Coward
  • 6,186
  • 1
  • 23
  • 29
  • @Coward...thank u...set default button works fine...But cant focus that textbox...and also cant focus that dialogbox,bcz first i press the enter button,cant work anything,after i click the dialogbox only the default button function worked...so now i want **how to focus that dialogbox,then the textbox in dialogbox?** – Arjun babu Oct 25 '12 at 04:27
  • What function do you use to create the dialog? DialogBoxIndirect()? – Anonymous Coward Oct 25 '12 at 04:51
  • Using wlxDialogBoxParam() function...this problem occurs in logondialogbox while starting the system. – Arjun babu Oct 25 '12 at 05:09
  • It is difficult to tell without seeing the code; it could be a problem within your DialogProc. Does the problem persist if you create a test project where you call DialogBoxParam() directly in WinMain? – Anonymous Coward Oct 25 '12 at 06:02
  • i cant get u clearly Coward...But i am using `_pWinLogon->wlxDialogBoxParam(_hInst, MAKEINTRESOURCE(_dialogResourceID), 0, _dialogProc, (LPARAM)this); _dialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);` these code only... – Arjun babu Oct 25 '12 at 06:34
  • 1
    After some googling i found (1) someone with the very same problem [GINA logon dialog not in focus/active](http://stackoverflow.com/questions/1609750/gina-logon-dialog-not-in-focus-active) and (2) a possible [solution](http://www.44342.com/security-f1225-t949-p1.htm) to the problem: **In your _dialogProc, case WM_INITDIALOG must return TRUE (not FALSE). And you may have to add SetForegroundWindow(hwnd).** – Anonymous Coward Oct 25 '12 at 07:08
  • Thank u Coward,it works fine...just using SetForegroundWindow();not to specify return true or false...thanks a lot Coward... – Arjun babu Oct 25 '12 at 07:32