×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

option fields in Win32 API

option fields in Win32 API

option fields in Win32 API

(OP)
Hi folks

I'm new in Win32 API programming and I have the following problem:

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.

Here the example of my code:

#include <windows.h>
#include "resource.h"

HWND hwndModeless;
HINSTANCE hInst;


BOOL CALLBACK AboutDlgProc ( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
// About Window
{
    switch ( message )
    {
    case WM_INITDIALOG:
        return TRUE;

    case WM_COMMAND:

    switch ( LOWORD ( wParam ))
    {
    case IDOK:

        EndDialog ( hDlg, 0 );
        return TRUE;
        }
    break;
    }
    return FALSE;
}


BOOL CALLBACK MainDlg ( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
    switch ( message )
    {
    case WM_INITDIALOG:

        CheckRadioButton ( hDlg, IDC_REBOOT, IDC_SHUTDOWN, 0 );
        SendMessage ( hDlg, WM_COMMAND, IDOK, 0 );
    }
    return FALSE;
}

LRESULT CALLBACK WndProc ( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    switch ( message )
    {
    case WM_COMMAND:

        switch ( LOWORD ( wParam ))
        {
        case IDM_APP_ABOUT:

            DialogBox ( hInst, MAKEINTRESOURCE ( IDD_ABOUT ), hwnd, AboutDlgProc );
            return 0;

            case IDOK:

            switch ( LOWORD ( wParam ))
            {
            case IDC_REBOOT:

                ExitWindowsEx ( EWX_REBOOT, 0xFFFFFFFF );
                return TRUE;

            case IDC_SHUTDOWN:

                ExitWindowsEx ( EWX_POWEROFF, 0xFFFFFFFF );
                return TRUE;
                }

            }
            break;
    
            case WM_DESTROY:

                PostQuitMessage ( 0 );
                return 0;
            }
            return DefWindowProc ( hwnd, message, wParam, lParam );
}


int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow )
{
    TCHAR static szAppName [ ] = TEXT ( "SELECT" );
   
    HWND hwnd;
    MSG msg;
    RECT rect;
    WNDCLASS wndclass;

    hInst = hInstance;

    wndclass.style = 0;
    wndclass.lpfnWndProc = WndProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon ( hInstance, MAKEINTRESOURCE ( IDI_ICON2 ));
    wndclass.hCursor = LoadCursor ( NULL, IDC_ARROW );
    wndclass.hbrBackground = NULL;
    wndclass.lpszMenuName = szAppName;
    wndclass.lpszClassName = szAppName;

    if ( !RegisterClass ( &wndclass ))
    {
        MessageBox ( NULL, TEXT ( "Only for Windows NT or Windows 2000" ), szAppName,
MB_ICONERROR );
        return 0;
    }

    hwnd = CreateWindow ( szAppName, TEXT ( "Killing Windows" ),
                          WS_OVERLAPPED ¦ WS_CAPTION ¦ WS_SYSMENU ¦ WS_BORDER ¦ WS_MINIMIZEBOX,
  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  NULL, NULL, hInstance, NULL );  

    hwndModeless = CreateDialog ( hInstance, szAppName, hwnd, MainDlg );

    GetWindowRect    ( hwndModeless, &rect );
    AdjustWindowRect ( &rect, WS_CAPTION ¦ WS_BORDER, FALSE );

    SetWindowPos ( hwnd, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE );

    ShowWindow ( hwndModeless, SW_SHOW );
    ShowWindow ( hwnd, iCmdShow );
    UpdateWindow ( hwnd );

    while ( GetMessage ( &msg, NULL, 0, 0 ))
    {
        if ( hwndModeless == 0 ¦¦ !IsDialogMessage ( hwndModeless, &msg ))
        {
            TranslateMessage ( &msg );
            DispatchMessage ( &msg );
        }
    }
    return msg.wParam;
}

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?

At the moment I don't have any idea for my problem I hope you can help me.

Greeting SiM

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close