Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

option fields in Win32 API

Status
Not open for further replies.

simmeone

Programmer
Mar 16, 2000
29
DE
Hi folks<br><br>I'm new in Win32 API programming and I have the following problem:<br><br>I have created a dialog with option fields where the user can set different options, and must press a OK-Button. The problem now is, that the OK-button don't works, and I don't know why.<br><br>Here the example of my code:<br><b><br>#include &lt;windows.h&gt;<br>#include &quot;resource.h&quot;<br><br>HWND hwndModeless;<br>HINSTANCE hInst;<br><br><br>BOOL CALLBACK AboutDlgProc ( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )<br><font color=red>// About Window</font><br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;switch ( message )<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;case WM_INITDIALOG:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return TRUE;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;case WM_COMMAND:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;switch ( LOWORD ( wParam ))<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;case IDOK:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EndDialog ( hDlg, 0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return TRUE;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;return FALSE;<br>}<br><br><br>BOOL CALLBACK MainDlg ( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;switch ( message )<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;case WM_INITDIALOG:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CheckRadioButton ( hDlg, IDC_REBOOT, IDC_SHUTDOWN, 0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendMessage ( hDlg, WM_COMMAND, IDOK, 0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;} <br>&nbsp;&nbsp;&nbsp;&nbsp;return FALSE;<br>}<br><br>LRESULT CALLBACK WndProc ( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;switch ( message )<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;case WM_COMMAND:<br> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch ( LOWORD ( wParam ))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case IDM_APP_ABOUT:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DialogBox ( hInst, MAKEINTRESOURCE ( IDD_ABOUT ), hwnd, AboutDlgProc );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case IDOK:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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bsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case WM_DESTROY:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PostQuitMessage ( 0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return DefWindowProc ( hwnd, message, wParam, lParam );<br>}<br><br><br>int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, <br> PSTR szCmdLine, int iCmdShow )<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;TCHAR static szAppName [ ] = TEXT ( &quot;SELECT&quot; );<br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;HWND hwnd;<br>&nbsp;&nbsp;&nbsp;&nbsp;MSG msg;<br>&nbsp;&nbsp;&nbsp;&nbsp;RECT rect;<br>&nbsp;&nbsp;&nbsp;&nbsp;WNDCLASS wndclass;<br> <br>&nbsp;&nbsp;&nbsp;&nbsp;hInst = hInstance;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.style = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.lpfnWndProc = WndProc;<br>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.cbClsExtra = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.cbWndExtra = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.hInstance = hInstance;<br>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.hIcon = LoadIcon ( hInstance, MAKEINTRESOURCE ( IDI_ICON2 ));<br>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.hCursor = LoadCursor ( NULL, IDC_ARROW );<br>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.hbrBackground = NULL;<br>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.lpszMenuName = szAppName;<br>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.lpszClassName = szAppName;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;if ( !RegisterClass ( &wndclass )) <br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageBox ( NULL, TEXT ( &quot;Only for Windows NT or Windows 2000&quot; ), szAppName,<br> MB_ICONERROR );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;hwnd = CreateWindow ( szAppName, TEXT ( &quot;Killing Windows&quot; ), <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WS_OVERLAPPED ¦ WS_CAPTION ¦ WS_SYSMENU ¦ WS_BORDER ¦ WS_MINIMIZEBOX,<br> &nbsp;&nbsp;CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, <br> &nbsp;&nbsp;NULL, NULL, hInstance, NULL );&nbsp;&nbsp;<br> <br>&nbsp;&nbsp;&nbsp;&nbsp;hwndModeless = CreateDialog ( hInstance, szAppName, hwnd, MainDlg );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;GetWindowRect&nbsp;&nbsp;&nbsp;&nbsp;( hwndModeless, &rect );<br>&nbsp;&nbsp;&nbsp;&nbsp;AdjustWindowRect ( &rect, WS_CAPTION ¦ WS_BORDER, FALSE );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;SetWindowPos ( hwnd, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;ShowWindow ( hwndModeless, SW_SHOW );<br>&nbsp;&nbsp;&nbsp;&nbsp;ShowWindow ( hwnd, iCmdShow );<br>&nbsp;&nbsp;&nbsp;&nbsp;UpdateWindow ( hwnd );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;while ( GetMessage ( &msg, NULL, 0, 0 ))<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( hwndModeless == 0 ¦¦ !IsDialogMessage ( hwndModeless, &msg ))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TranslateMessage ( &msg );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DispatchMessage ( &msg );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;return msg.wParam;<br>}<br></b><br>And a other problem I have: the reboot and poweroff function don't works with WinNT and Win2k why?? Is there a option that I have forgot in my source?<br><br>At the moment I don't have any idea for my problem I hope you can help me.<br><br>Greeting SiM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top