listbox control didn't redraw after moving main window position or popout a messagebox
Here is the screenshot of my win32 app (dialogbox-based , non-MFC):
After I click add button , data like 11:22 test will be added to the listbox below.
but after I move the main dialogbox , the listbox items will disappear as the image shown beblow which i think the listbox didn't redraw itself.
after i click add button to add new list item to the listbox, list items appears again. and after that,moving dialog didn't cause the blank-listbox anymore. moving main dialog to the edge of the desktop and letting listbox hidden from we can see. or pop out a messagebox will alse erase listbox-item.
the full c code:
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <stdio.h>
#include "resource.h"
//global variable declaration
HWND hWnd,hHour,hMinute,hRemindText,hRemindList;
WNDPROC procHour,procMinute;
char buf[1024],bufHour[1024],bufMinute[1024],bufRemindText[1024];
int i;
//function declaration
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK HourEditProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK MinuteEditProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_ALARM),hWnd, (DLGPROC)DlgProc);
return 0;
}
//function prototype
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
HICON hIcon,hIconSm;
switch (LOWORD(Msg))
{
case WM_INITDIALOG :
//initial
memset(buf,0,sizeof(buf));
//icon setting
//hIcon = (HICON)LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICON1));
//SendMessage(hWndDlg, WM_SETICON, ICON_BIG , (LPARAM)hIcon);
//hIconSm = (HICON)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
//SendMessage(hWndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
//subclass the edit control
hHour = GetDlgItem(hWndDlg, IDC_HOUR);
hMinute = GetDlgItem(hWndDlg,IDC_MINUTE);
hRemindText = GetDlgItem(hWndDlg,IDC_REMIND_TEXT);
hRemindList = GetDlgItem(hWndDlg,IDC_REMIND_LIST);
procHour = (WNDPROC)SetWindowLong(hHour, GWL_WNDPROC, (LONG)HourEditProc);
procMinute = (WNDPROC)SetWindowLong(hMinute, GWL_WNDPROC, (LONG)MinuteEditProc);
return TRUE ;
case WM_CHAR:
return TRUE;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDC_REMIND_LIST:
if(HIWORD(wParam) == LBN_DBLCLK)
{
i=SendMessage(hRemindList,LB_GETCURSEL,0,0);
SendMessage(hRemindList,LB_DELETESTRING,i,0);
}
if(HIWORD(wParam) == LBN_SELCHANGE)
{
SendMessage(hRemindList,LB_GETTEXT,0,(LPARAM)buf);
MessageBox(hWndDlg,buf,buf,MB_OK);
//InvalidateRect (hRemindList, NULL, FALSE);
//UpdateWindow(hRemindList);
//ShowWindow(hRemindList,0);
}
return TRUE;
case IDC_ADD://添加
//MessageBox(hWndDlg,NULL,NULL,MB_OK);
if(GetWindowText(hHour,buf,sizeof(buf)) == 0)
{
MessageBox(hWndDlg,"【时】不能为空!","提示",MB_OK);
break;
}
sprintf(bufHour,"%02s:",buf);
if(GetWindowText(hMinute,buf,sizeof(buf)) == 0)
{
MessageBox(hWndDlg,"【分】不能为空!","提示",MB_OK);
break;
}
sprintf(bufMinute,"%02s",buf);
if(GetWindowText(hRemindText,buf,sizeof(buf)) == 0)
{
MessageBox(hWndDlg,"【提醒内容】不能为空!","提示",MB_OK);
break;
}
sprintf(bufRemindText," %-140s",buf);
memset(buf,0,sizeof(buf));
strcat(buf,bufHour);
strcat(buf,bufMinute);
strcat(buf,bufRemindText);
SendMessage(hRemindList,LB_ADDSTRING,0,(LPARAM)(LPCSTR)buf);
return TRUE;
case IDOK :
EndDialog (hWndDlg, 0) ;
return TRUE ;
case IDCANCEL :
EndDialog (hWndDlg, 0) ;
return TRUE ;
}
break ;
}
return FALSE ;
}
LRESULT CALLBACK HourEditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SETFOCUS:
SendMessage(hwnd,EM_SETLIMITTEXT,2,0);
break;
case WM_KEYUP:
GetWindowText(hHour,buf,sizeof(buf));
sscanf(buf,"%d",&i);
if(i/10>2 || i>=24)
{
buf[1]=0;
SetWindowText(hHour,buf);
SendMessage(hHour,EM_SETSEL,1,0);
return TRUE;
}
break;
}
return CallWindowProc (procHour, hwnd, message, wParam, lParam);
}
LRESULT CALLBACK MinuteEditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SETFOCUS:
SendMessage(hwnd,EM_SETLIMITTEXT,2,0);
break;
case WM_KEYUP:
GetWindowText(hMinute,buf,sizeof(buf));
sscanf(buf,"%d",&i);
if(i/10>5 || i>=60)
{
buf[1]=0;
SetWindowText(hMinute,buf);
SendMessage(hMinute,EM_SETSEL,1,0);
return TRUE;
}
break;
}
return CallWindowProc (procMinute, hwnd, message, wParam, lParam);
}
the full resource script code:
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// 中文(简体,中国) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_ALARM DIALOGEX 0, 0, 300, 201
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU
CAPTION "定时提醒器"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_HOUR,6,7,25,14,ES_CENTER | ES_AUTOHSCROLL | ES_NUMBER,WS_EX_RIGHT
EDITTEXT IDC_MINUTE,45,7,25,14,ES_CENTER | ES_AUTOHSCROLL | ES_NUMBER
EDITTEXT IDC_REMIND_TEXT,121,7,172,14,ES_AUTOHSCROLL
PUSHBUTTON "↓添加",IDC_ADD,6,26,54,14
CONTROL "1",IDC_MON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,38,152,20,10
CONTROL "2",IDC_TUE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,65,152,20,10
CONTROL "3",IDC_WED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,92,152,20,10
CONTROL "4",IDC_THU,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,119,152,20,10
CONTROL "5",IDC_FRI,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,146,152,20,10
CONTROL "6",IDC_SAT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,173,152,20,10
CONTROL "7",IDC_SUN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,200,152,20,10
DEFPUSHBUTTON "保存设置",IDOK,83,180,61,14
PUSHBUTTON "最小化到托盘",IDCANCEL,156,180,61,14
LTEXT "提醒我",IDC_STATIC,227,152,25,8
LTEXT "点",IDC_STATIC,36,10,9,8
LTEXT "分",IDC_STATIC,74,9,9,8
LTEXT "请在周",IDC_STATIC,6,152,25,8
LTEXT "提醒我",IDC_STATIC,88,9,25,8
LISTBOX IDC_REMIND_LIST,7,46,287,99,LBS_SORT | WS_VSCROLL | WS_TABSTOP
LISTBOX 开发者_StackOverflow社区 IDC_LIST2,7,46,287,99,LBS_SORT | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_ALARM, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 293
TOPMARGIN, 7
BOTTOMMARGIN, 194
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "Clock.ico"
#endif // 中文(简体,中国) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
after exam the rc file i found
two windows overlapping each other as HansPassant said.
精彩评论