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 6383243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:37:30+00:00 2026-05-25T02:37:30+00:00

I am developing an Win32 application where user logins when the application starts in

  • 0

I am developing an Win32 application where user logins when the application starts in a login window and then the main window opens

But when I run the program nothing appears.

Here’s the code

HINSTANCE   ghInstance;
HWND hWnd;

HWND hWndPopUp;

LRESULT WINAPI PopUpWndProc( HWND hWnd2, UINT msg, WPARAM wParam, LPARAM lParam );
LRESULT WINAPI  MainWndProc( HWND hWnd , UINT msg , WPARAM wParam , LPARAM lParam );

int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpszCmdLine , int nCmdShow){

WNDCLASS wc;
WNDCLASS wcPopUp;
MSG msg;
//HWND hWnd;
BOOL bRet;

if( !hPrevInstance )
{

    wc.lpszClassName    =   L"MainAppClass" ;

    wc.lpfnWndProc      =   MainWndProc ;

    wc.style            =   CS_OWNDC    |   CS_VREDRAW  |   CS_HREDRAW ;

    wc.hInstance        =   hInstance ;

    wc.hIcon            =   LoadIcon( NULL, IDI_APPLICATION ) ;

    wc.hCursor          =   LoadCursor( NULL, IDC_ARROW ) ;

    wc.hbrBackground    =   (HBRUSH)( COLOR_WINDOW+1 ) ;

    wc.lpszMenuName     =   NULL ;

    wc.cbClsExtra       =   0 ;

    wc.cbWndExtra       =   0 ;

    RegisterClass( &wc ) ;

    wcPopUp.lpszClassName   =   L"PopUpAppClass" ;

    wcPopUp.lpfnWndProc     =   PopUpWndProc ;

    wcPopUp.style           =   CS_OWNDC    |   CS_VREDRAW  |   CS_HREDRAW ;

    wcPopUp.hInstance       =   hInstance ;

    wcPopUp.hIcon           =   LoadIcon( NULL, IDI_APPLICATION ) ;

    wcPopUp.hCursor         =   LoadCursor( NULL, IDC_ARROW ) ;

    wcPopUp.hbrBackground   =   (HBRUSH)( COLOR_WINDOW+1 ) ;

    wcPopUp.lpszMenuName        =   NULL ;

    wcPopUp.cbClsExtra      =   0 ;

    wcPopUp.cbWndExtra      =   0 ;

    RegisterClass( &wcPopUp );

}

ghInstance = hInstance;

hWndPopUp = CreateWindowEx(WS_EX_CONTEXTHELP,                         
                        wcPopUp.lpszClassName,                          
                        L"Stock Ticker Login",                          
                        WS_OVERLAPPEDWINDOW,
                        0,
                        0,
                        CW_USEDEFAULT,                          
                        CW_USEDEFAULT,                          
                        NULL,                           
                        NULL,                           
                        hInstance,                          
                        NULL
                    );


bool show = ShowWindow( hWndPopUp, SW_MAXIMIZE  ) ;

UpdateWindow(hWndPopUp);

hPE = NULL;


/** While there is no WM_QUIT message in the Message Queue
    Fetch Message from the queue and Dispatch it to WindowProc()
**/
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0 )
{
    if (bRet == -1)
    {
        // handle the error and possibly exit

        int nerror = GetLastError();

        MessageBox(hWnd,L"Window Error",L"Window error", MB_ICONERROR);

        exit(1);
    } 

    else {

        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
}

return (int)msg.wParam;

}

LRESULT WINAPI PopUpWndProc( HWND hWnd2, UINT msg, WPARAM wParam, LPARAM lParam ){

HDC hdc;
PAINTSTRUCT ps;

RECT rc;
GetClientRect(hWnd, &rc);

int height  = rc.bottom - rc.top;
int width = rc.right -rc.left;

switch( msg )
{

    case WM_CREATE:

        hWndStaticUsername = CreateWindowEx(    0
                                            , L"static"
                                            , L"Username"
                                            , WS_CHILD | WS_VISIBLE
                                            , rc.left + width/8
                                            , rc.top + height/4
                                            , 100
                                            , 30
                                            , hWnd2
                                            , 0
                                            , ghInstance
                                            , 0
                                    );

        hWndEditUsername = CreateWindowEx(  WS_EX_CLIENTEDGE
                                        , L"edit"
                                        , L""
                                        , WS_CHILD | WS_VISIBLE
                                        , rc.left + width/8 + 150
                                        , rc.top + height/4 
                                        , 150
                                        , 30
                                        , hWnd2
                                        , 0
                                        , ghInstance
                                        , 0
                                );
        hWndBtnLogin = CreateWindowEx(  0
                                    , L"button"
                                    , L"Login"
                                    , WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                    , rc.left + width/8
                                    , rc.top + height/4 + 80 
                                    , 50
                                    , 30
                                    , hWnd2
                                    , 0
                                    , ghInstance
                                    , 0
                            );

        break;

    case WM_COMMAND:

        if(HIWORD(wParam)== BN_CLICKED  && lParam==(LPARAM)hWndBtnLogin )
        {
            TCHAR* uname =new TCHAR;
            Edit_GetText(hWndEditUsername, uname, 20);

            if(wcscmp(uname,L"")==0)

                return 0;

            else 
            {
                StartTicker(uname);
                DestroyWindow(hWnd);
            }

        }

        break;

    case WM_DESTROY:

        hWnd = CreateWindowEx(WS_EX_CONTEXTHELP,                          
                        L"MainAppClass",                            
                        L"Assignment 2",                            
                        WS_OVERLAPPEDWINDOW,
                        0,
                        0,
                        CW_USEDEFAULT,                          
                        CW_USEDEFAULT,                          
                        NULL,                           
                        NULL,                           
                        ghInstance,                         
                        NULL
                    );

        ShowWindow( hWnd, SW_MAXIMIZE ) ;

        UpdateWindow(hWnd);

        break;

    default:

        return DefWindowProc(hWnd, msg, wParam, lParam );
}

return 0;

}

Please help me find the solution.

  • 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-25T02:37:31+00:00Added an answer on May 25, 2026 at 2:37 am
        return DefWindowProc(hWnd, msg, wParam, lParam );
    

    Wrong window handle, it should be hWnd2.

    To uplift this post beyond a ‘debug my code for me’ answer, there are two fundamental things you do wrong, they are going to get you into a lot more trouble:

    • too sloppy on picking good variable names. You should never have a global variable named “hWnd”. That should of course be hWndMain, you’d have never made that mistake.
    • no error check whatsoever. If you had any, you would have quickly discovered that CreateWindowEx() returned NULL and GetLastError() returned 1400. Without error checking, you can only watch it misbehave but never diagnose it.

    Using the raw winapi requires meticulous attention to such small details. Consider using a class library instead.

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

Sidebar

Related Questions

I am developing an application that needs to a host native Win32 window and
I am developing a Win32 application and I would like to use an RSA
I have developend a window application(Win32 API) in visual C++. I have to add
Hi i am developing game level editor.Currently I am using win32 with directX.But with
Developing a .NET WinForms application: how can I check if the window is in
When developing a Win32 Application (non-console application) in Visual Studio 2005, is there any
I'm developing a Win32 mobile application (.NET CF 2.0/3.5) that has to communicate with
I'm currently developing an application which uses the iTunes COM (Win32) to hook into
I'm developing an application on Windows, but I'd also like to support other platforms
I'm developing a win32 C++ application that needs to export data to excel spreadsheets.

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.