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

  • Home
  • SEARCH
  • 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 3438268
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:10:00+00:00 2026-05-18T08:10:00+00:00

I’m stuck with a strange problem. I’m making a Win32 application in VC++ 2008,

  • 0

I’m stuck with a strange problem. I’m making a Win32 application in VC++ 2008, making a class to encapsulate most of the work for easy repetition when calling a MessageBox. The message box` is created (I think) but doesn’t show up unless I press the Alt key!

What happen exactly is :

  1. I run the program

  2. press Enter

  3. the main window lose focus

  4. give beep sound when i click on the main window as if a modal MessageBox is present

  5. either press Escape… focus is gained OR press Alt then the MessageBox appear with alt key pressed (i.e. menu will drop )!!!!!!

P.S. It was working fine but suddenly this happened. I didn’t find any difference – I even made a new project!

This is supposed the Main program:

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR    lpCmdLine, int       nCmdShow)
{
    MSG msg;
    CWnd    cMainWindow(TEXT("DentoMan"), TEXT("Bejkoman")); // pass The class name and window name to the constructor

    cMainWindow.CreateDef(); //Create the Window
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return (int)msg.wParam;
}

While This is the Class file

CWnd::CWnd() {
};

CWnd::CWnd(LPTSTR lpszClassName, LPTSTR lpszWindowName) {
    CWnd::lpszClassName     = lpszClassName;
    CWnd::lpszWindowName    = lpszWindowName;
};

CWnd::~CWnd() {
};

// Create the window with default parameters
HWND CWnd::CreateDef(void) {
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = StaticWndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = (HINSTANCE)GetModuleHandle(NULL);
    wcex.hIcon          = 0;
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 4);
    wcex.lpszMenuName   = 0;
    wcex.lpszClassName  = lpszClassName;
    wcex.hIconSm        = 0;

    RegisterClassEx(&wcex);
    g_hWnd = CreateWindowEx(0,lpszClassName, lpszWindowName, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, wcex.hInstance, this);
    hInst   =   wcex.hInstance;  //Store hInstance in the class hInst variable

    if (!g_hWnd) return false;
    ShowWindow(g_hWnd, SW_SHOW);
    UpdateWindow(g_hWnd);

    return g_hWnd;
}

LRESULT CALLBACK CWnd::StaticWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) {
    /* The Only Message we take here so we store the 'this' pointer within the window to identify messages 
    comming from it by the 'this' pointer*/
    if ( Message == WM_CREATE ) {
        SetWindowLong( hWnd, GWL_USERDATA, (LONG)((CREATESTRUCT FAR *)lParam)->lpCreateParams);
    }

    /* Store the window pointer in the class pointer we just created in order to run the right public WndPRoc */
    CWnd *Destination = (CWnd*)GetWindowLong( hWnd, GWL_USERDATA );

    // If the hWnd has a related class, pass it through
    if (Destination) {
        return Destination->WndProc( hWnd, Message, wParam, lParam );
    }

    // No destination found, defer to system...
    return DefWindowProc( hWnd, Message, wParam, lParam );
};

LRESULT CWnd::WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) {
    // Determine message type
    switch (Message) {
        case WM_LBUTTONDOWN:
            {
                /* this is a common trick for easy dragging of the window.this message fools windows telling that the user is
                 actually dragging the application caption bar.*/
                 SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION,NULL);
                break;
            }

        /*case WM_CREATE:
            break;
    */

        case WM_CLOSE:
            PostQuitMessage(0);
            break;

        case WM_DESTROY:
            UnregisterClass(lpszClassName, hInst);
            PostQuitMessage(0);
            break;

        case WM_KEYDOWN:    //KeyBoard keys
            // Which key was pressed?
            switch (wParam) {
                case VK_ESCAPE: //close through escape key
                    PostQuitMessage(0);
                    return 0;
                case VK_RETURN:
                    MessageBox(hWnd, TEXT("DFGDGD"), TEXT("DFGDFG"), NULL);
                    return 0;
            } // End Switch

            break;

        case WM_COMMAND:
            /*switch(LOWORD(wParam))
        {
        }*/
        break;

        case WM_PAINT:
            break;

        default:
            return DefWindowProc(hWnd, Message, wParam, lParam);

    } // End Message Switch

return 0;
};

The Class Header:

class CWnd {
    public:
        CWnd();
        CWnd(LPTSTR lpszClassName, LPTSTR lpszWindowName);
        virtual ~CWnd();
        virtual HWND CreateDef(void);           // Create the window with default parameters
        virtual LRESULT     WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam );

    private:
        static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
        HWND        g_hWnd;     //Global window handle for this window
        HINSTANCE   hInst;      //Global instance for this window

        LPTSTR          lpszClassName;
        LPTSTR          lpszWindowName;
};

P.S. I included all needed header files, everything goes fine except MessageBox

This is also a link to the code on here

  • 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-18T08:10:00+00:00Added an answer on May 18, 2026 at 8:10 am

    Ohhhhhhh finally i found the solution of this problem … and for everyone to benefit the problem was in WndProc(…….) at the WM_PAINT Message i wrote some code in it and removed all the code along with BeginPaint and EndPaint functions so the program enter a freeze period once anything is being painted over it including that MessageBox but it only show when i press Alt i think coz the control is transfered to the system in that step to show the system Menu (i think)

    the solution either remove the WM_PAINT message handler or add the normal BeginPaint and EndPaint functions

    Thanks for everyone who passed on my question

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
I used javascript for loading a picture on my website depending on which small
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.