move variable declarations to top

reduce flickering

svn path=/trunk/; revision=32500
This commit is contained in:
Christoph von Wittich 2008-02-27 10:53:59 +00:00
parent 8a104be4fc
commit d49acd34e8

View file

@ -20,6 +20,10 @@ HFONT hMainFont;
HIMAGELIST hImageAppList; // Image list for programs list HIMAGELIST hImageAppList; // Image list for programs list
BOOL bAscending = TRUE; // Sorting programs list BOOL bAscending = TRUE; // Sorting programs list
HDC BackbufferHdc = NULL;
HBITMAP BackbufferBmp = NULL;
VOID VOID
ShowMessage(WCHAR* title, WCHAR* message) ShowMessage(WCHAR* title, WCHAR* message)
{ {
@ -119,6 +123,7 @@ AddTreeViewItems(VOID)
HIMAGELIST hImageList; HIMAGELIST hImageList;
WCHAR szBuf[1024]; WCHAR szBuf[1024];
int Index[2]; int Index[2];
TV_INSERTSTRUCTW Insert;
hImageList = ImageList_Create(16, 16, ILC_COLORDDB, 1, 1); hImageList = ImageList_Create(16, 16, ILC_COLORDDB, 1, 1);
SendMessageW(hActList, TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)(HIMAGELIST)hImageList); SendMessageW(hActList, TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)(HIMAGELIST)hImageList);
@ -127,8 +132,6 @@ AddTreeViewItems(VOID)
Index[1] = ImageList_Add(hImageList, LoadBitmap(hApplet, MAKEINTRESOURCE(IDB_ICON)), NULL); Index[1] = ImageList_Add(hImageList, LoadBitmap(hApplet, MAKEINTRESOURCE(IDB_ICON)), NULL);
// Insert items to Actions List // Insert items to Actions List
TV_INSERTSTRUCTW Insert;
ZeroMemory(&Insert, sizeof(TV_INSERTSTRUCT)); ZeroMemory(&Insert, sizeof(TV_INSERTSTRUCT));
Insert.item.mask = TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE; Insert.item.mask = TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
Insert.hInsertAfter = TVI_LAST; Insert.hInsertAfter = TVI_LAST;
@ -273,6 +276,7 @@ AddItemToList(LPARAM hSubKey, LPWSTR szDisplayName, INT ItemIndex, LPWSTR AppNam
HICON hIcon = NULL; HICON hIcon = NULL;
LV_ITEM listItem; LV_ITEM listItem;
WCHAR IconPath[MAX_PATH], AppSize[256], LastUsed[256]; WCHAR IconPath[MAX_PATH], AppSize[256], LastUsed[256];
int iIndex;
GetARPInfo(AppName, IconPath, AppSize, LastUsed); GetARPInfo(AppName, IconPath, AppSize, LastUsed);
@ -295,7 +299,6 @@ AddItemToList(LPARAM hSubKey, LPWSTR szDisplayName, INT ItemIndex, LPWSTR AppNam
listItem.lParam = (LPARAM)hSubKey; listItem.lParam = (LPARAM)hSubKey;
listItem.iItem = (int)ItemIndex; listItem.iItem = (int)ItemIndex;
listItem.iImage = index; listItem.iImage = index;
int iIndex;
iIndex = ListView_InsertItem(hAppList, &listItem); iIndex = ListView_InsertItem(hAppList, &listItem);
ListView_SetItemText(hAppList, iIndex, 1, LastUsed); ListView_SetItemText(hAppList, iIndex, 1, LastUsed);
ListView_SetItemText(hAppList, iIndex, 2, AppSize); ListView_SetItemText(hAppList, iIndex, 2, AppSize);
@ -322,13 +325,12 @@ FillSoftwareList(INT ShowMode)
BOOL bIsUpdate = FALSE; BOOL bIsUpdate = FALSE;
BOOL bIsSystemComponent = FALSE; BOOL bIsSystemComponent = FALSE;
INT ItemIndex = 0; INT ItemIndex = 0;
(VOID) ImageList_Destroy(hImageAppList);
(VOID) ListView_DeleteAllItems(hAppList);
DEVMODE pDevMode; DEVMODE pDevMode;
int ColorDepth; int ColorDepth;
(VOID) ImageList_Destroy(hImageAppList);
(VOID) ListView_DeleteAllItems(hAppList);
pDevMode.dmSize = sizeof(DEVMODE); pDevMode.dmSize = sizeof(DEVMODE);
pDevMode.dmDriverExtra = 0; pDevMode.dmDriverExtra = 0;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &pDevMode); EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &pDevMode);
@ -421,6 +423,8 @@ GetAppString(LPCWSTR lpKeyName, LPWSTR lpString)
{ {
HKEY hKey; HKEY hKey;
INT nIndex; INT nIndex;
DWORD dwSize;
DWORD dwType = REG_SZ;
nIndex = (INT)SendMessage(hAppList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED); nIndex = (INT)SendMessage(hAppList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
if (nIndex != -1) if (nIndex != -1)
@ -433,7 +437,6 @@ GetAppString(LPCWSTR lpKeyName, LPWSTR lpString)
(VOID) ListView_GetItem(hAppList,&item); (VOID) ListView_GetItem(hAppList,&item);
hKey = (HKEY)item.lParam; hKey = (HKEY)item.lParam;
DWORD dwSize, dwType = REG_SZ;
if (RegQueryValueEx(hKey, lpKeyName, NULL, &dwType, if (RegQueryValueEx(hKey, lpKeyName, NULL, &dwType,
(LPBYTE)lpString, &dwSize) == ERROR_SUCCESS) (LPBYTE)lpString, &dwSize) == ERROR_SUCCESS)
{ {
@ -689,10 +692,7 @@ CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
Size2 = _wtoi(szItem2); Size2 = _wtoi(szItem2);
if (Size1 < Size2) if (Size1 < Size2)
{ {
if(bAscending == TRUE) return (bAscending ? -1 : 1);
return -1;
else
return 1;
} }
else if (Size1 == Size2) else if (Size1 == Size2)
{ {
@ -700,10 +700,7 @@ CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
} }
else if (Size1 > Size2) else if (Size1 > Size2)
{ {
if(bAscending == TRUE) return (bAscending ? 1 : -1);
return 1;
else
return -1;
} }
} }
} }
@ -723,10 +720,7 @@ LoadSettings(VOID)
dwSize = sizeof(APPWIZSETTINGS); dwSize = sizeof(APPWIZSETTINGS);
if (RegQueryValueEx(hKey, L"Settings", NULL, NULL, (LPBYTE)&AppWizSettings, &dwSize) == ERROR_SUCCESS) if (RegQueryValueEx(hKey, L"Settings", NULL, NULL, (LPBYTE)&AppWizSettings, &dwSize) == ERROR_SUCCESS)
{ {
if (AppWizSettings.Size == sizeof(APPWIZSETTINGS)) Ret = (AppWizSettings.Size == sizeof(APPWIZSETTINGS));
Ret = TRUE;
else
Ret = FALSE;
} }
else Ret = FALSE; else Ret = FALSE;
} }
@ -746,10 +740,7 @@ SaveSettings(VOID)
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
{ {
AppWizSettings.Size = sizeof(APPWIZSETTINGS); AppWizSettings.Size = sizeof(APPWIZSETTINGS);
if (RegSetValueEx(hKey, L"Settings", 0, REG_BINARY, (LPBYTE)&AppWizSettings, sizeof(APPWIZSETTINGS)) == ERROR_SUCCESS) Ret = (RegSetValueEx(hKey, L"Settings", 0, REG_BINARY, (LPBYTE)&AppWizSettings, sizeof(APPWIZSETTINGS)) == ERROR_SUCCESS);
Ret = TRUE;
else
Ret = FALSE;
} }
else Ret = FALSE; else Ret = FALSE;
@ -757,10 +748,31 @@ SaveSettings(VOID)
return Ret; return Ret;
} }
static void UpdateBitmap(HWND hWnd, RECT WndRect, RECT DescriptionRect)
{
HDC hdc = GetDC(hWnd);
if (!BackbufferHdc)
BackbufferHdc = CreateCompatibleDC(hdc);
if (BackbufferBmp)
DeleteObject(BackbufferBmp);
BackbufferBmp = CreateCompatibleBitmap(hdc, WndRect.right, WndRect.bottom);
SelectObject(BackbufferHdc, BackbufferBmp);
FillRect(BackbufferHdc, &WndRect, (HBRUSH)COLOR_APPWORKSPACE);
DrawIconEx(BackbufferHdc, 153, 1, hSearchIcon, 24, 24, 0, NULL, DI_NORMAL|DI_COMPAT);
DrawDescription(BackbufferHdc, DescriptionRect);
ReleaseDC(hWnd, hdc);
}
static LRESULT CALLBACK static LRESULT CALLBACK
WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{ {
static RECT DescriptionRect; static RECT DescriptionRect;
static RECT AppRect;
WCHAR szBuf[1024]; WCHAR szBuf[1024];
switch (Message) switch (Message)
@ -824,16 +836,7 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{ {
PAINTSTRUCT ps; PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps); HDC hdc = BeginPaint(hwnd, &ps);
HDC BackbufferHdc = CreateCompatibleDC(hdc);
HBITMAP BackbufferBmp = CreateCompatibleBitmap(hdc, ps.rcPaint.right, ps.rcPaint.bottom);
SelectObject(BackbufferHdc, BackbufferBmp);
FillRect(BackbufferHdc, &ps.rcPaint, (HBRUSH)COLOR_APPWORKSPACE);
DrawIconEx(BackbufferHdc, 153, 1, hSearchIcon, 24, 24, 0, NULL, DI_NORMAL|DI_COMPAT);
DrawDescription(BackbufferHdc, DescriptionRect);
BitBlt(hdc, 0, 0, ps.rcPaint.right, ps.rcPaint.bottom, BackbufferHdc, 0, 0, SRCCOPY); BitBlt(hdc, 0, 0, ps.rcPaint.right, ps.rcPaint.bottom, BackbufferHdc, 0, 0, SRCCOPY);
DeleteObject(BackbufferBmp);
DeleteDC(BackbufferHdc);
EndPaint(hwnd, &ps); EndPaint(hwnd, &ps);
} }
break; break;
@ -865,6 +868,8 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
EnableWindow(hModifyBtn, TRUE); EnableWindow(hModifyBtn, TRUE);
} }
ShowAppInfo(); ShowAppInfo();
UpdateBitmap(hwnd, AppRect, DescriptionRect);
InvalidateRect(hwnd, &DescriptionRect, FALSE);
} }
break; break;
case NM_DBLCLK: case NM_DBLCLK:
@ -879,16 +884,8 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
case LVN_COLUMNCLICK: case LVN_COLUMNCLICK:
{ {
LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam; LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
(VOID) ListView_SortItems(hAppList, CompareFunc, pnmv->iSubItem); (VOID) ListView_SortItems(hAppList, CompareFunc, pnmv->iSubItem);
if (bAscending == TRUE) bAscending = !bAscending;
{
bAscending = FALSE;
}
else
{
bAscending = TRUE;
}
} }
break; break;
} }
@ -906,6 +903,10 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
break; break;
case WM_SIZE: case WM_SIZE:
{ {
RECT Rect = {1, HIWORD(lParam)-178, LOWORD(lParam)-1, HIWORD(lParam)-1};
SetRect(&AppRect, 0, 0, LOWORD(lParam)-1, HIWORD(lParam)-1);
DescriptionRect = Rect;
// Actions list // Actions list
ResizeControl(hActList, 0, 1, 150, HIWORD(lParam)-180); ResizeControl(hActList, 0, 1, 150, HIWORD(lParam)-180);
@ -915,9 +916,6 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
// Search Edit // Search Edit
ResizeControl(hSearch, 180, 1, LOWORD(lParam), 25); ResizeControl(hSearch, 180, 1, LOWORD(lParam), 25);
RECT Rect = {1, HIWORD(lParam)-178, LOWORD(lParam)-1, HIWORD(lParam)-1};
DescriptionRect = Rect;
// Buttons // Buttons
MoveWindow(hRemoveBtn, LOWORD(lParam)-105, HIWORD(lParam)-30, 100, 25, TRUE); // Remove button MoveWindow(hRemoveBtn, LOWORD(lParam)-105, HIWORD(lParam)-30, 100, 25, TRUE); // Remove button
MoveWindow(hModifyBtn, LOWORD(lParam)-208, HIWORD(lParam)-30, 100, 25, TRUE); // Modify button MoveWindow(hModifyBtn, LOWORD(lParam)-208, HIWORD(lParam)-30, 100, 25, TRUE); // Modify button
@ -926,6 +924,8 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
// Update title and info // Update title and info
ShowAppInfo(); ShowAppInfo();
UpdateBitmap(hwnd, AppRect, DescriptionRect);
InvalidateRect(hwnd, &DescriptionRect, FALSE);
} }
break; break;
case WM_ACTIVATEAPP: case WM_ACTIVATEAPP:
@ -949,12 +949,13 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
AppWizSettings.Top = wp.rcNormalPosition.top; AppWizSettings.Top = wp.rcNormalPosition.top;
AppWizSettings.Right = wp.rcNormalPosition.right; AppWizSettings.Right = wp.rcNormalPosition.right;
AppWizSettings.Bottom = wp.rcNormalPosition.bottom; AppWizSettings.Bottom = wp.rcNormalPosition.bottom;
if (IsZoomed(hMainWnd) || (wp.flags & WPF_RESTORETOMAXIMIZED)) AppWizSettings.Maximized = (IsZoomed(hMainWnd) || (wp.flags & WPF_RESTORETOMAXIMIZED));
AppWizSettings.Maximized = TRUE;
else
AppWizSettings.Maximized = FALSE;
SaveSettings(); SaveSettings();
// Destroy all and quit // Destroy all and quit
if (BackbufferHdc)
DeleteDC(BackbufferHdc);
if (BackbufferBmp)
DeleteObject(BackbufferBmp);
DeleteObject(hMainFont); DeleteObject(hMainFont);
DeleteObject(hSearchIcon); DeleteObject(hSearchIcon);
PostQuitMessage(0); PostQuitMessage(0);