NO

Author Topic: ERROR_RESOURCE_NAME_NOT_FOUND, CreateDialogParam  (Read 8358 times)

Kenny80

  • Guest
ERROR_RESOURCE_NAME_NOT_FOUND, CreateDialogParam
« on: September 17, 2011, 07:35:48 PM »
I'm trying to create a dialog with following code:

Code: [Select]
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
    INITCOMMONCONTROLSEX icc;
    WNDCLASSEX wcx;
MSG msg;
int msg_;
HWND hWnd;

    hInstance = GetModuleHandle(NULL);

    icc.dwSize = sizeof(icc);
    icc.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&icc);

    wcx.cbSize = sizeof(wcx);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = (WNDPROC)WndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = DLGWINDOWEXTRA;
wcx.hInstance = hInstance;
wcx.hbrBackground = (HBRUSH)COLOR_BTNFACE+1;
wcx.lpszMenuName = MAKEINTRESOURCE(IDM_MENU);
wcx.lpszClassName = _T("DLGCLASS");
wcx.hIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
wcx.hIconSm = wcx.hIcon;
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);

  if (!RegisterClassEx(&wcx)) { return 0; }

hWnd = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, (DLGPROC)WndProc, 0);
if (hWnd == NULL) {return 0; }

ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

do
{
msg_ = GetMessage(&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
while (msg_);

return msg.wParam;
}

But CreateDialogParam() returns with error "ERROR_RESOURCE_NAME_NOT_FOUND", i tried remove the menu, and cursor ID one by one and still same error so must have something todo with IDD_MAIN or the hInstance (i think).

whole project can be downloaded here http://www.mediafire.com/?a7x466ix78v6lo7

I just can't find what is causing the error.

Thx in advance!
« Last Edit: September 17, 2011, 07:39:22 PM by Kenny80 »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2123
Re: ERROR_RESOURCE_NAME_NOT_FOUND, CreateDialogParam
« Reply #1 on: September 18, 2011, 04:37:30 PM »
In FileHasher.rc correct least this:
MENU 10000
to
MENU 2000
or comment it out because this is already in FileHasher.c:
wcx.lpszMenuName = MAKEINTRESOURCE(IDM_MENU);

Check these too:
Code: [Select]
hWnd = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, NULL, 0);
Code: [Select]
        case WM_CLOSE:
            DestroyWindow(hWnd);
            return FALSE;

        case WM_DESTROY:
          PostQuitMessage (0) ;
          return FALSE;
« Last Edit: September 18, 2011, 05:07:07 PM by timovjl »
May the source be with you

Kenny80

  • Guest
Re: ERROR_RESOURCE_NAME_NOT_FOUND, CreateDialogParam
« Reply #2 on: September 19, 2011, 11:20:36 AM »
Yes noticed that too and other problem is that i'm missing a DefWindowProc(hWnd, uMsg, wParam, lParam) in WndProc.

CommonTater

  • Guest
Re: ERROR_RESOURCE_NAME_NOT_FOUND, CreateDialogParam
« Reply #3 on: September 19, 2011, 06:58:22 PM »
Yes noticed that too and other problem is that i'm missing a DefWindowProc(hWnd, uMsg, wParam, lParam) in WndProc.

If you are using a dialogbox you don't call DefWindowProc() ... that's only for top level windows.
For that matter when using dialog boxes you don't register a class either...

Although it's done all the time, I seriously doubt that Microsoft ever intended Dialogs to be a program's main window.... or anything but small pop-up windows like MessageBoxes() and such...
« Last Edit: September 19, 2011, 07:00:50 PM by CommonTater »

Kenny80

  • Guest
Re: ERROR_RESOURCE_NAME_NOT_FOUND, CreateDialogParam
« Reply #4 on: September 21, 2011, 08:42:51 AM »
Yes noticed that too and other problem is that i'm missing a DefWindowProc(hWnd, uMsg, wParam, lParam) in WndProc.

If you are using a dialogbox you don't call DefWindowProc() ... that's only for top level windows.
For that matter when using dialog boxes you don't register a class either...

Although it's done all the time, I seriously doubt that Microsoft ever intended Dialogs to be a program's main window.... or anything but small pop-up windows like MessageBoxes() and such...

If i leave it out then program will complain about invalid menu handle, problay a newbie error but it works.

i followed this guide: http://win32assembly.online.fr/tut10.html

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2123
Re: ERROR_RESOURCE_NAME_NOT_FOUND, CreateDialogParam
« Reply #5 on: September 21, 2011, 09:31:26 AM »
This example can't use it ?:
Code: [Select]
//testDlg.c
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

BOOL CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
return TRUE;

case WM_CLOSE:
DestroyWindow(hWnd);
return FALSE;

case WM_DESTROY:
PostQuitMessage(0);
return FALSE;
}
//return DefWindowProc(hWnd, uMsg, wParam, lParam);
return FALSE;
}

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
{
MSG Msg;
HWND hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(1001), NULL,(DLGPROC)DlgProc);
if (!hWnd) return 1;
while (GetMessage(&Msg, NULL, 0, 0) == TRUE)
{
if (!IsDialogMessage(hWnd, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return (int) Msg.wParam;
}
Code: [Select]
//testDlg.rc
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US

1001 DIALOGEX DISCARDABLE -1, -1, 156, 24
STYLE DS_CENTER|WS_CAPTION|WS_SYSMENU|WS_VISIBLE
FONT 8, "MS Sans Serif", 0, 0, 1
{
  CONTROL "OK", 4001, "Button", WS_TABSTOP, 48, 4, 45, 15
  CONTROL "Cancel", 4002, "Button", WS_TABSTOP, 96, 4, 45, 15
  CONTROL "", 4003, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 4, 4, 40, 12
}

EDIT:
It is needed with registered class that define lpfnWndProc ?

Modified version for non-modal dialog:
Code: [Select]
/****************************************************************************
 *                                                                          *
 * File    : main.c                                                         *
 *                                                                          *
 * Purpose : Generic dialog based Win32 application.                        *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/

/*
 * Either define WIN32_LEAN_AND_MEAN, or one or more of NOCRYPT,
 * NOSERVICE, NOMCX and NOIME, to decrease compile time (if you
 * don't need these defines -- see windows.h).
 */

#define WIN32_LEAN_AND_MEAN
/* #define NOCRYPT */
/* #define NOSERVICE */
/* #define NOMCX */
/* #define NOIME */

#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include "main.h"

#define NELEMS(a)  (sizeof(a) / sizeof((a)[0]))

/** Prototypes **************************************************************/

static INT_PTR CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);

/** Global variables ********************************************************/

static HANDLE ghInstance;

/****************************************************************************
 *                                                                          *
 * Function: WinMain                                                        *
 *                                                                          *
 * Purpose : Initialize the application.  Register a window class,          *
 *           create and display the main window and enter the               *
 *           message loop.                                                  *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
    INITCOMMONCONTROLSEX icc;
    WNDCLASSEX wcx;
    HWND hWnd;
    MSG msg;

    ghInstance = hInstance;

    /* Initialize common controls. Also needed for MANIFEST's */
    /*
     * TODO: set the ICC_???_CLASSES that you need.
     */
    icc.dwSize = sizeof(icc);
    icc.dwICC = ICC_WIN95_CLASSES /*|ICC_COOL_CLASSES|ICC_DATE_CLASSES|ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES|... */;
    InitCommonControlsEx(&icc);

    /* Load Rich Edit control support */
    /*
     * TODO: uncomment one of the lines below, if you are using a Rich Edit control.
     */
    // LoadLibrary(_T("riched32.dll"));  // Rich Edit v1.0
    // LoadLibrary(_T("riched20.dll"));  // Rich Edit v2.0, v3.0

    /*
     * TODO: uncomment line below, if you are using the Network Address control (Windows Vista+).
     */
    // InitNetworkAddressControl();

    /* Get system dialog information */
    wcx.cbSize = sizeof(wcx);
    if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
        return 0;

    /* Add our own stuff */
    wcx.hInstance = hInstance;
    wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
    wcx.lpszClassName = _T("TestAppClass");
    wcx.lpfnWndProc = (WNDPROC)MainDlgProc;
    wcx.hbrBackground = (HBRUSH)COLOR_3DSHADOW;
    if (!RegisterClassEx(&wcx))
        return 0;

    /* The user interface is a non-modal dialog box */
    hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, 0);
    if (!hWnd)
        return 0;
    while(GetMessage(&msg, NULL, 0, 0))
    {
        if(!IsDialogMessage(hWnd, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
     return (int) msg.wParam;
}

/****************************************************************************
 *                                                                          *
 * Function: MainDlgProc                                                    *
 *                                                                          *
 * Purpose : Process messages for the Main dialog.                          *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/

static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_INITDIALOG:
            /*
             * TODO: Add code to initialize the dialog.
             */
            return TRUE;

        case WM_SIZE:
            /*
             * TODO: Add code to process resizing, when needed.
             */
            return TRUE;

        case WM_COMMAND:
            switch (GET_WM_COMMAND_ID(wParam, lParam))
            {
                /*
                 * TODO: Add more control ID's, when needed.
                 */
                case IDOK:
                    DestroyWindow(hwndDlg);
                    return TRUE;
            }
            break;

        case WM_CLOSE:
            DestroyWindow(hwndDlg);
            return TRUE;

        case WM_DESTROY:
            PostQuitMessage(0);
            return FALSE;
        /*
         * TODO: Add more messages, when needed.
         */
    }
    return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
}
« Last Edit: September 21, 2011, 12:16:29 PM by timovjl »
May the source be with you

CommonTater

  • Guest
Re: ERROR_RESOURCE_NAME_NOT_FOUND, CreateDialogParam
« Reply #6 on: September 21, 2011, 10:35:33 AM »
i followed this guide: http://win32assembly.online.fr/tut10.html

Try this one... Pure C, pure winAPI ... http://www.winprog.org/tutorial/

Timo has the right idea...

Plus, if you want a menu in a dialog... you can simply enter it's name in the dialog box parameters dialog in the resource editor...