Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 323587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:02:41+00:00 2026-05-12T09:02:41+00:00

I am trying to add menus to a window created in win32 API through

  • 0

I am trying to add menus to a window created in win32 API through VC++. This program generates two errors which I am not able to fix.

The code as following.

GENERIC.H

#define IDM_EXIT 100
#define IDM_TEST 200
#define IDM_ABOUT 300
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);

GENERIC.RC

#include "windows.h"
#include "generic.h"
#include "winver.h"
MYAPP ICON DISCARDABLE "GENERIC.ICO"
MYAPP MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", IDM_EXIT
END
MENUITEM "&Test!", IDM_TEST
POPUP "&Help"
BEGIN
MENUITEM "&About MyApp…", IDM_ABOUT
END
END
1 VERSIONINFO
FILEVERSION 3,3,0,0
PRODUCTVERSION 3,3,0,0
FILEFLAGSMASK 0x3fl
#ifdef _DEBUG
FILEFLAGS 0xbl
#else
FILEFLAGS 0xal
#endif
FILEOS 0X4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "Your Company\0"
VALUE "FileDescription", "My Application\0"
VALUE "FileVersion", "1.0\0"
VALUE "InternalName", "MyApp\0"
VALUE "LegalCopyright", "Copyright \251 Your Company.
1995\0"
VALUE "LegalTrademarks", "Microsoft\256 is a registered
trademark of Microsoft
Corporation. Windows (TM) is
a trademark of Microsoft
Corporation\0"
VALUE "OriginalFilename", "\0"
VALUE "ProductName", "MyApp\0"
VALUE "ProductVersion", "1.0\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END

Generic.C

#include <windows.h>
#include "generic.h"
HINSTANCE hInst; // current instance
LPCTSTR lpszAppName = "MyApp";
LPCTSTR lpszTitle = "My Application";
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                     LPTSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    HWND hWnd;
    WNDCLASSEX wc;
    // In Windows 95 or Windows NT the hPrevInstance will always be NULL.
    //...................................................................
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC)WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (hInstance, lpszAppName);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName = lpszAppName;
    wc.lpszClassName = lpszAppName;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.hIconSm = LoadImage(hInstance, lpszAppName,
        IMAGE_ICON, 16, 16,
        LR_DEFAULTCOLOR );
    if ( !RegisterClassEx( &wc ) )
        return( FALSE );
    hInst = hInstance;
    hWnd = CreateWindow( lpszAppName,
        lpszTitle,
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0,
        CW_USEDEFAULT, 0,
        NULL,
        NULL,
        hInstance,
        NULL
        );
    if ( !hWnd )
        return( FALSE );
    ShowWindow( hWnd, nCmdShow );
    UpdateWindow( hWnd );
    while( GetMessage( &msg, NULL, 0, 0) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
    return( msg.wParam );
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
                         lParam )
{
    switch( uMsg )
    {
    case WM_COMMAND :
        switch( LOWORD( wParam ) )
        {
        case IDM_TEST :
            break;
        case IDM_ABOUT :
            DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About
                );
            break;
        case IDM_EXIT :
            DestroyWindow( hWnd );
            break;
        }
        break;
    case WM_DESTROY :
        PostQuitMessage(0);
        break;
    default :
        return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
    }
    return( 0L );
}
LRESULT CALLBACK About( HWND hDlg,
                       UINT message,
                       WPARAM wParam,
                       LPARAM lParam)
{
    switch (message)
    {
    case WM_INITDIALOG:
        return (TRUE);
    case WM_COMMAND:
        if ( LOWORD(wParam) == IDOK
            || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, TRUE);
            return (TRUE);
        }
        break;
    }
    return (FALSE);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:02:41+00:00Added an answer on May 12, 2026 at 9:02 am

    I don’t know which errors you’ve got but I when I tried to compile your code I had only one error about type conversion

    wc.hIconSm = LoadImage(hInstance, lpszAppName,
        IMAGE_ICON, 16, 16,
        LR_DEFAULTCOLOR );
    

    Also, I’ve noticed that you pass wrong second argument to DialogBox function. It expects a resource identifier of your dialog box converted to a LPCTSTR via MAKEINTRESOURCE. So you should add something like this

    IDD_ABOUTBOX DIALOG DISCARDABLE  34, 22, 217, 55
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "About ..."
    FONT 8, "MS Sans Serif"
    BEGIN
        LTEXT           "About me",1000,40,10,76,8
        DEFPUSHBUTTON   "OK",IDOK,176,6,32,14,WS_GROUP
    END
    

    into your generic.rc file.

    Hope this helps. Although it would be much better if you were more clear about your problem. And I suggest you study a bit MSDN windows programming section if you’re about to do some GUI programming or at least let Visual Studio Wizard generate a simple win32 project for you and than study it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 159k
  • Answers 159k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I tend to use properties if the following are true:… May 12, 2026 at 11:31 am
  • Editorial Team
    Editorial Team added an answer Based on your code-example, it seems you're only detouring your… May 12, 2026 at 11:31 am
  • Editorial Team
    Editorial Team added an answer You're looking at code generated by the compiler. The compiler… May 12, 2026 at 11:31 am

Related Questions

I already started this in javascript so I don't want to use jquery but
I'm trying to make a context menu for a control that is linked to
I am running SQL Server Reporting Services on SQL Server 2008 Standard and trying
I'm trying to setup some caching on my site and am having troubles with
I am trying to add a new menu item to Eclipse's popupmenus. It really

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.