Fixed the stack trash upon loading a channel, made the GuildView change states before the slow network call which would delay the UI, also fixed a late error check on ChatView

This commit is contained in:
winsped
2026-07-20 19:58:42 +03:00
parent 48f91c0912
commit ffde1ca33d
3 changed files with 10 additions and 47 deletions
+6 -6
View File
@@ -50,6 +50,11 @@ void ChatView_SetUserPfp(char *path, char *user) {
PngBuffer pngbuf = {buf, file_size, 0}; PngBuffer pngbuf = {buf, file_size, 0};
png_set_read_fn(png, &pngbuf, PngReadBufCB); png_set_read_fn(png, &pngbuf, PngReadBufCB);
if (setjmp(png_jmpbuf(png))) {
png_destroy_read_struct(&png, &info, NULL);
// err
MessageBoxA(NULL, "zzzzzzzz", "zzzzzzzzz", 0);
}
png_read_info(png, info); png_read_info(png, info);
BITMAPINFO bmi = {0}; BITMAPINFO bmi = {0};
@@ -59,11 +64,6 @@ void ChatView_SetUserPfp(char *path, char *user) {
bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB; // THIS IS RAW - gordon ramsey bmi.bmiHeader.biCompression = BI_RGB; // THIS IS RAW - gordon ramsey
if (setjmp(png_jmpbuf(png))) {
png_destroy_read_struct(&png, &info, NULL);
// err
MessageBoxA(NULL, "zzzzzzzz", "zzzzzzzzz", 0);
}
png_set_expand(png); png_set_expand(png);
png_set_strip_16(png); png_set_strip_16(png);
png_set_filler(png, 0xFF, png_set_filler(png, 0xFF,
@@ -156,7 +156,7 @@ static int pfp_compare(const void *a, const void *b, void *udata) {
} }
static void pfp_free(void *pfpitem) { static void pfp_free(void *pfpitem) {
IntPfpTableItem *item = pfpitem; IntPfpTableItem *item = pfpitem;
free(item->bmp); DeleteDC(item->bmp);
free(item->key); free(item->key);
} }
#define UsernameFieldHeight 15 #define UsernameFieldHeight 15
+1 -1
View File
@@ -228,8 +228,8 @@ LRESULT CALLBACK GuildWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
nm.pt.x = x; nm.pt.x = x;
nm.pt.y = y; nm.pt.y = y;
SendMessage(GetParent(hwnd), WM_NOTIFY, nm.hdr.idFrom, (LPARAM)&nm);
InvalidateRect(hwnd, NULL, true); InvalidateRect(hwnd, NULL, true);
SendMessage(GetParent(hwnd), WM_NOTIFY, nm.hdr.idFrom, (LPARAM)&nm);
return 0; return 0;
} }
} }
+3 -40
View File
@@ -443,7 +443,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
} }
} }
} else { } else {
DiscordGuild *guild; DiscordGuild *guild;
guild = pnmv->guild.data; guild = pnmv->guild.data;
@@ -457,14 +456,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
channel_compare, NULL, NULL); channel_compare, NULL, NULL);
for (int i = 0; i < ChannelCount; i++) { for (int i = 0; i < ChannelCount; i++) {
char *VisualName; char *VisualName;
if (Channels[i].type == GUILD_TEXT) { VisualName = malloc(strlen(Channels[i].name+1));
VisualName = malloc(strlen(Channels[i].name) + 2);
*VisualName = '#';
strcpy(VisualName + 1, Channels[i].name);
} else {
VisualName = malloc(strlen(Channels[i].name) + 1);
strcpy(VisualName, Channels[i].name); strcpy(VisualName, Channels[i].name);
}
TVINSERTSTRUCT tvInsert = {0}; TVINSERTSTRUCT tvInsert = {0};
HTREEITEM hParent = TVI_ROOT; HTREEITEM hParent = TVI_ROOT;
if (Channels[i].parentID) { if (Channels[i].parentID) {
@@ -494,46 +487,16 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
chnl->id = strdup(Channels[i].id); chnl->id = strdup(Channels[i].id);
hashmap_set(ChannelUITable, chnl); hashmap_set(ChannelUITable, chnl);
} }
free(VisualName);
} }
} }
} else if (pNMHDR.hwndFrom == hChTree) { } else if (pNMHDR.hwndFrom == hChTree) {
LPNMTREEVIEW pnmv = (LPNMTREEVIEW)lParam; LPNMTREEVIEW pnmv = (LPNMTREEVIEW)lParam;
if (pNMHDR.code == NM_CUSTOMDRAW) {
LPNMTVCUSTOMDRAW pcd = (LPNMTVCUSTOMDRAW)lParam;
switch (pcd->nmcd.dwDrawStage) {
case CDDS_PREPAINT:
SetWindowLongPtr(hwnd, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW);
return CDRF_NOTIFYITEMDRAW;
case CDDS_ITEMPREPAINT:
return CDRF_NOTIFYPOSTPAINT;
case CDDS_ITEMPOSTPAINT: {
DiscordChannel *chnl = (DiscordChannel *)pcd->nmcd.lItemlParam;
if (chnl && chnl->type == GUILD_VOICE) {
RECT rc;
TreeView_GetItemRect(hChTree, (HTREEITEM)pcd->nmcd.dwItemSpec, &rc, TRUE);
// draw icon to the left of the label rect
ImageList_Draw(hChannelImgList, 0, pcd->nmcd.hdc,
rc.left - 18, rc.top + (rc.bottom - rc.top - 16) / 2,
ILD_TRANSPARENT);
} else if (chnl && chnl->type == GUILD_ANNOUNCEMENT) {
RECT rc;
TreeView_GetItemRect(hChTree, (HTREEITEM)pcd->nmcd.dwItemSpec, &rc, TRUE);
// draw icon to the left of the label rect
ImageList_Draw(hChannelImgList, 1, pcd->nmcd.hdc,
rc.left - 18, rc.top + (rc.bottom - rc.top - 16) / 2,
ILD_TRANSPARENT);
}
return CDRF_DODEFAULT;
}
}
}
if (pNMHDR.code == TVN_SELCHANGED && if (pNMHDR.code == TVN_SELCHANGED &&
pnmv->itemNew.state & TVIS_SELECTED) { pnmv->itemNew.state & TVIS_SELECTED) {
DiscordChannel *chnl = ((DiscordChannel *)pnmv->itemNew.lParam); DiscordChannel *chnl = ((DiscordChannel *)pnmv->itemNew.lParam);
if (chnl->type != GUILD_CATEGORY) { if (chnl->type != GUILD_CATEGORY) {
char *title = malloc(14 + strlen(pnmv->itemNew.pszText)); char *title = malloc(13 + strlen(chnl->name));
wsprintf(title, "Backcord - %s", pnmv->itemNew.pszText); wsprintf(title, "Backcord - #%s", chnl->name);
SetWindowTextA(hwnd, title); SetWindowTextA(hwnd, title);
DiscordMessage *msgs; DiscordMessage *msgs;
int msgcnt = DiscordGetChannelHistory(chnl->id, 50, &msgs); int msgcnt = DiscordGetChannelHistory(chnl->id, 50, &msgs);