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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:44:12+00:00 2026-06-12T23:44:12+00:00

I’m trying to create simple windows app uisng WinAPi. Here is the code: #include

  • 0

I’m trying to create simple windows app uisng WinAPi.
Here is the code:

       #include "stdafx.h"
       #include "APIup.h"

       #define MAX_LOADSTRING 100
       HWND hWnd,cw13;
       // Global Variables:
       HINSTANCE hInst;                             // current                      instance
       TCHAR szTitle[MAX_LOADSTRING];                   // The title bar text
       TCHAR szWindowClass[MAX_LOADSTRING];         // the main window class name

       // Forward declarations of functions included in this code module:
       ATOM             MyRegisterClass(HINSTANCE hInstance);
       ATOM Register(HINSTANCE hInstance);
       BOOL             InitInstance(HINSTANCE, int);
       LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
       LRESULT CALLBACK    WndProc_dla13(HWND, UINT, WPARAM, LPARAM);
       INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

       int APIENTRY _tWinMain(HINSTANCE hInstance,
                            HINSTANCE hPrevInstance,
                            LPTSTR    lpCmdLine,
                            int       nCmdShow)
       {
        UNREFERENCED_PARAMETER(hPrevInstance);
        UNREFERENCED_PARAMETER(lpCmdLine);

            // TODO: Place code here.
        MSG msg;
                HACCEL hAccelTable;

        // Initialize global strings
        LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
        LoadString(hInstance, IDC_APIUP, szWindowClass, MAX_LOADSTRING);
        MyRegisterClass(hInstance);
        Register(hInstance);

        // Perform application initialization:
        if (!InitInstance (hInstance, nCmdShow))
        {
            return FALSE;
        }

        hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_APIUP));

        // Main message loop:
        while (GetMessage(&msg, NULL, 0, 0))
        {
            if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }

        return (int) msg.wParam;
       }





        ATOM MyRegisterClass(HINSTANCE hInstance)
        {
            WNDCLASSEX wcex;

            wcex.cbSize = sizeof(WNDCLASSEX);

            wcex.style          = CS_HREDRAW | CS_VREDRAW;
            wcex.lpfnWndProc    = WndProc;
            wcex.cbClsExtra     = 0;
            wcex.cbWndExtra     = 0;
            wcex.hInstance      = hInstance;
            wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APIUP));
            wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
            wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
            wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_APIUP);
            wcex.lpszClassName  = szWindowClass;
            wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));


            return RegisterClassEx(&wcex);
               }

               ATOM Register(HINSTANCE hInstance)
               {
            WNDCLASSEX cw13class;

            cw13class.cbSize = sizeof(WNDCLASSEX);

            cw13class.style         = CS_HREDRAW | CS_VREDRAW;
            cw13class.lpfnWndProc   = WndProc_dla13;
            cw13class.cbClsExtra        = 0;
            cw13class.cbWndExtra        = 0;
            cw13class.hInstance     = hInstance;
            cw13class.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APIUP));
            cw13class.hCursor       = LoadCursor(NULL, IDC_ARROW);
            cw13class.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
            cw13class.lpszMenuName  = NULL;
            cw13class.lpszClassName = L"13class";
            cw13class.hIconSm       = LoadIcon(cw13class.hInstance,                               MAKEINTRESOURCE(IDI_SMALL));
            return RegisterClassEx(&cw13class);

        }

        BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
        {




           hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
              CW_USEDEFAULT, 0, 100, 100, NULL, NULL, hInstance, NULL);
           cw13=CreateWindow(L"13class",L"Ćwiczenie                         13",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,300,300,NULL,NULL,hInst,NULL);


           if (!hWnd)
           {
              return FALSE;
           }

          ShowWindow(hWnd, nCmdShow);
           UpdateWindow(hWnd);

           return TRUE;
        }


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:

        switch (wmId)
        {
        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        case ID_32771:
            ShowWindow(cw13, 1);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // TODO: Add any drawing code here...
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

LRESULT CALLBACK WndProc_dla13 (HWND hWnd, UINT msg/*message*/, WPARAM  wParam,LPARAM lParam)
        {
 switch(msg)  
  {
    case WM_CREATE:

      CreateWindowW(L"button", L"Beep",
          WS_VISIBLE | WS_CHILD ,
          20, 50, 80, 25,
          cw13, (HMENU) 1, hInst, NULL);

      CreateWindowW(L"button", L"Quit",
          WS_VISIBLE | WS_CHILD ,
          120, 50, 80, 25,
          cw13, (HMENU) 2, NULL, NULL);
      break;

    case WM_COMMAND:

      if (LOWORD(wParam) == 1) {
        Beep(40, 50);
      }

      if (LOWORD(wParam) == 2) {
        PostQuitMessage(0);
      }

      break;

    case WM_DESTROY:

      PostQuitMessage(0);
      break;
      default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
  }
 return 0;
}




// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}

And the problem is that: when i create window ‘cw13’ it is created and displayed, but push buttons are not.I created two separate WndProc functions. Other messages are executed correctly( like WM_QUIT), only CreateWindowW under WM_CREATE,witch should create and show Push buttons aren’t. Where is the problem?

  • 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-06-12T23:44:13+00:00Added an answer on June 12, 2026 at 11:44 pm

    When processing the WM_CREATE message, your call to CreateWindow(L"13class") is still running. Your cw13 variable has not been assigned yet, so you are assigning an invalid HWND as the parent of your buttons. That is why they do not appear. Use the hwnd parameter of WndProc_dla13() instead as the parent. That will be the same HWND that gets assigned to the cw13 variable once CreateWindow(L"13class") exits.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a

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.