0

信じられないかもしれませんが、私はこれに5時間も費やしました。とても基本的なことのように思えて、とてもストレスを感じています。実際にこれらすべてのリソースを手に入れると、プログラムの作成がずっと簡単になります。

私のコードは次のとおりです。

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

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK AboutDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR lpszCmdParam, int nCmdShow)
     {
     static char szAppName[] = "ErrorSample";
     HWND           hwnd;
     MSG            msg;    // Look how this struct is defined-see help/class notes NOW
     WNDCLASSEX     wndclass; 
     HWND           hwndDialogBox = NULL;
     HMENU  hMenu;

          wndclass.cbSize        = sizeof(wndclass);
          wndclass.style         = CS_HREDRAW | CS_VREDRAW;
          wndclass.lpfnWndProc   = WndProc;
          wndclass.cbClsExtra    = 0;
          wndclass.cbWndExtra    = 0;
          wndclass.hInstance     = hInstance;
          wndclass.hIcon         = LoadIcon (NULL, IDC_ICON);

          wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
          wndclass.hbrBackground = static_cast<HBRUSH>(GetStockObject (WHITE_BRUSH));
          wndclass.lpszMenuName  = NULL;
          wndclass.lpszClassName = szAppName;
          wndclass.hIconSm       = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ERROR));

          RegisterClassEx (&wndclass);

          hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(102));

     hwnd = CreateWindow (szAppName,         // window class name
                    "Trying my damndest",            // window caption
                    WS_OVERLAPPEDWINDOW,     // window style
                    CW_USEDEFAULT,           // initial x position
                    CW_USEDEFAULT,           // initial y position
                    CW_USEDEFAULT,           // initial x size
                    CW_USEDEFAULT,           // initial y size
                    NULL,                    // parent window handle
                    hMenu,                    // window menu handle
                    hInstance,               // program instance handle
                    NULL);                   // creation parameters


     ShowWindow (hwnd, nCmdShow);
     UpdateWindow (hwnd);

     while (GetMessage (&msg, NULL, 0, 0))
          {
          TranslateMessage (&msg);
          DispatchMessage (&msg);
          }
     return (int) msg.wParam;
     }

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, 
                          WPARAM wParam, LPARAM lParam)
     {
     static HINSTANCE    hInstance;

     switch (message)
         {

         case WM_CREATE:
             hInstance = ((LPCREATESTRUCT) lParam) ->hInstance;
             return 0;

         case WM_COMMAND:
             switch(LOWORD(wParam))
             {
             case ID_HELP_ABOUT:
                 DialogBox( hInstance, "AboutBox", hwnd, AboutDlgProc);
                 break;
             }

             return 0;

         case WM_DESTROY:
             PostQuitMessage(0);
             return 0;
         }

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

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

    case WM_COMMAND:
        switch(LOWORD(wParam))
        {
        case IDOK:
        case IDCANCEL:
            EndDialog(hDlg, 0);
            return TRUE;
        }
        break;
    }
    return FALSE;
}

WndProc の WM_COMMAND で ID_HELP_ABOUT ケース ステートメントをクリックしても、何も起こりません。私のAboutDlgProc関数にも入りません。

Resource.h

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Practice.rc
//
#define DIALOG_BOX                      9
#define IDR_MENU1                       102
#define ID_HELP_ABOUT                   40001

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        103
#define _APS_NEXT_COMMAND_VALUE         40002
#define _APS_NEXT_CONTROL_VALUE         1001
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

.rc ファイル

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

DIALOG_BOX DIALOGEX 32, 32, 309, 178
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,198,157,50,14
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
    DIALOG_BOX, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 302
        TOPMARGIN, 7
        BOTTOMMARGIN, 171
    END
END
#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

IDR_MENU1 MENU
BEGIN
    MENUITEM "&File",                       0
    POPUP "&Help"
    BEGIN
        MENUITEM "&About",                      ID_HELP_ABOUT
    END
END

#endif    // English (United States) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

助けてください!=)

4

1 に答える 1