我正在Windows中使用Windows5.0MobileSDK创建一个对话框,使用Visual 2008用C创建WIN32。我使用SW_SHOW和SW_HIDE常量和ShowWindow函数在对话框中隐藏和显示控件,该对话框由静态文本(标签)和编辑文本(文本框)控件组成。我使用“资源编辑器和工具箱”将控件拖放到对话框中。我将可视属性设置为false的一些控件。单击按钮时,不可见控件将可见,可见控件将不可见。
然而,只有我的编辑文本(文本框)控件似乎正在显示和隐藏,但ShowWindow函数似乎对我的静态文本(标签)没有任何影响-它们不会隐藏和显示。下面是我的密码。为什么会这样呢?
#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);
}下面请查找MyResource.h头文件的内容:
//{{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发布于 2020-03-18 02:51:39
使用下面的示例代码,隐藏静态文本在Windows 10上对我有效。你可以试试。
对话框过程中的C++代码:
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.h中的资源in:
#define IDC_STATIC1 995
#define IDC_STATIC2 996
#define IDC_STATIC3 997
#define IDC_BUTTON_HIDE 1001
#define IDC_BUTTON_SHOW 1002project_name.rc文件中的资源脚本:
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显示

隐

https://stackoverflow.com/questions/60664784
复制相似问题