Ezani
Ezani

Reputation: 557

WIN32 - Hiding Controls Work Except For Static Text (Labels)

I am creating a dialog in Windows CE using Windows 5.0 Mobile SDK and WIN32 using C with Visual Studio 2008. I am using the SW_SHOW and SW_HIDE constants with the ShowWindow function to hide and show controls on my dialog which consists of static text (labels) and edit text (textboxes) controls. I use the Resource Editor and Toolbox to drag and drop my controls on to the dialog form. Some of the controls I set the Visible property to false. When I click a button, the invisible controls shall be visible and the visible controls will be invisible.

However only my edit text (textboxes) controls seems to be showing and hiding but the ShowWindow function does not seem to have any effect on my static text (labels) - they don't hide and show. Below is my code. Why is this?

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <windowsx.h>
#include <winuser.h>
#include "ScanCAPI.h"
#include "resource.h"

#pragma comment(lib, "Kernel32.lib")

LRESULT CALLBACK BasicScanProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    DWORD           dwResult;
    TCHAR           szLabelType[256];
    TCHAR           szLen[MAX_PATH];
    TCHAR           szMsgBuf[256];
    LPSCAN_BUFFER   lpScanBuf;
    HWND            hctl_data, hctl_length, hctl_type, hctl1, hctl2, hWndComboBox,  hnd_static5, hnd_static6, hnd_static7, hnd_pic1, hnd_pic2, hnd_static1, hnd_static2, hnd_static4, hwd_button1, hwd_static5, hwd_static6, hwd_static7, hwd_edit1, hwd_edit2;

    switch(uMsg)
    {

        case WM_COMMAND:

        hctl_length = GetDlgItem(hwnd,IDC_EDIT_LEN);
        hctl_type = GetDlgItem(hwnd,IDC_EDIT_TYPE);
        hWndComboBox = GetDlgItem(hwnd,IDC_COMBO1);

        hnd_static1 = GetDlgItem(hwnd,IDC_STATIC1);
        hnd_static2 = GetDlgItem(hwnd,IDC_STATIC2);
        hnd_static4 = GetDlgItem(hwnd,IDC_STATIC4);
        hctl_data = GetDlgItem(hwnd,IDC_EDIT_DATA);
        hctl_length = GetDlgItem(hwnd,IDC_EDIT_LEN);
        hwd_button1 = GetDlgItem(hwnd,IDC_BUTTON1);
        hwd_static5 = GetDlgItem(hwnd,IDC_STATIC5);
        hwd_static6 = GetDlgItem(hwnd,IDC_STATIC6);
        hwd_static7 = GetDlgItem(hwnd,IDC_STATIC7);
        hwd_edit1 = GetDlgItem(hwnd,IDC_EDIT1);
        hwd_edit2 = GetDlgItem(hwnd,IDC_EDIT2);


            switch (LOWORD(wParam))
            {

            case IDC_BUTTON1:

                    ShowWindow(hnd_static1, SW_SHOW);
                    ShowWindow(hnd_static2, SW_SHOW);
                    ShowWindow(hnd_static4, SW_SHOW);
                    ShowWindow(hctl_data, SW_SHOW);
                    ShowWindow(hctl_length, SW_SHOW);
                    ShowWindow(hWndComboBox, SW_SHOW);
                    ShowWindow(hwd_button1, SW_HIDE);
                    ShowWindow(hwd_static5, SW_HIDE);
                    ShowWindow(hwd_static6, SW_HIDE);
                    ShowWindow(hwd_static7, SW_HIDE);
                    ShowWindow(hwd_edit1, SW_HIDE);
                    ShowWindow(hwd_edit2, SW_HIDE);



     }


And below please find the contents of my Resource.h header file:

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by BasicScan.rc
//
#define IDD_DIALOG_SSCAN                101
#define IDI_ICON1                       102
#define IDC_STATIC1                     995
#define IDC_STATIC2                     996
#define IDC_STATIC3                     997
#define IDC_STATIC4                     998
#define IDC_STATIC5                     999
#define IDC_EDIT_DATA                   1000
#define IDC_EDIT_LEN                    1001
#define IDC_EDIT_TYPE                   1002
#define IDC_BUTTON_SOFTTRIGGER          1003
#define IDC_CONTINUOUS                  1004
#define IDC_COMBO1                      1005
#define IDC_STATIC6                     1006
#define IDC_STATIC7                     1007
#define IDC_STATIC8                     1008
#define IDC_STATIC9                     1009
#define IDC_EDIT1                       1010
#define IDC_EDIT2                       1011
#define IDC_BUTTON1                     1012
#define IDS_FAILURE                     57345
#define IDS_ERR_BUF                     57346
#define IDS_DEVICE_FAILURE              57347
#define IDS_READ_PENDING                57348
#define IDS_READ_CANCELLED              57349
#define IDS_READY                       57350
#define IDS_INACTIVE                    57351

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        105
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1014
#define _APS_NEXT_SYMED_VALUE           106
#endif
#endif

Upvotes: 0

Views: 1353

Answers (1)

Rita Han
Rita Han

Reputation: 9700

Hiding static text works for me on Windows 10 using the following sample code. You can have a try.

C++ code in dialog procedure:

case WM_COMMAND:
{
    hwd_static1 = GetDlgItem(hDlg, IDC_STATIC1);
    hwd_static2 = GetDlgItem(hDlg, IDC_STATIC2);
    hwd_static3 = GetDlgItem(hDlg, IDC_STATIC3);

    if (LOWORD(wParam) == IDC_BUTTON_HIDE)
    {
        ShowWindow(hwd_static1, SW_HIDE);
        ShowWindow(hwd_static2, SW_HIDE);
        ShowWindow(hwd_static3, SW_HIDE);

        return (INT_PTR)TRUE;
    }

    if (LOWORD(wParam) == IDC_BUTTON_SHOW)
    {
        ShowWindow(hwd_static1, SW_SHOW);
        ShowWindow(hwd_static2, SW_SHOW);
        ShowWindow(hwd_static3, SW_SHOW);

        return (INT_PTR)TRUE;
    }
}
break;

Resource IDs in Resource.h:

#define IDC_STATIC1                     995
#define IDC_STATIC2                     996
#define IDC_STATIC3                     997
#define IDC_BUTTON_HIDE                 1001
#define IDC_BUTTON_SHOW                 1002

Resource script in project_name.rc file:

LTEXT           "static text 1",IDC_STATIC1,42,14,114,8,SS_NOPREFIX
LTEXT           "static text 2",IDC_STATIC2,42,26,114,8,SS_NOPREFIX
LTEXT           "static text 3",IDC_STATIC3,40,94,147,31,SS_NOPREFIX

PUSHBUTTON      "Hide",IDC_BUTTON_HIDE,142,43,43,14
PUSHBUTTON      "Show",IDC_BUTTON_SHOW,141,78,44,14

Showed

enter image description here

Hidden

enter image description here

Upvotes: 1

Related Questions