NO

Author Topic: Bizarre  (Read 7672 times)

Grincheux

  • Guest
Bizarre
« on: February 26, 2016, 08:27:23 pm »
MSVC2015


PELLES


Code: [Select]
#define __STDC_WANT_LIB_EXT1__ 1

#include <windows.h>
#include <Commctrl.h>
#include <shlwapi.h>

#include "ImagesViewer.h"

#include "libgfl.h"
#include "libgfle.h"
#include "Images.h"
#include "sqlite3.h"
#include "Resources.h"
#include "Functions.h"
#include "Datas.h"
#include "Utils.h"

#ifdef __POCC__
#pragma warn(disable: 2216)
#endif

LRESULT ImagesToolBar_OnNotify(LPARAM __lParam)
{
LVITEM _Lvi ;
char _szTmp[MAX_PATH] ;
char _szImg[MAX_PATH] ;
LPNMITEMACTIVATE _lpItem ;
LVHITTESTINFO _Hit ;
int _FileSize,_ImageWidth,_ImageHeight,_ImageSize ;
char _szFormatName[256] ;

_lpItem = (LPNMITEMACTIVATE) __lParam ;

if(_lpItem->hdr.code == NM_CLICK)
{
if(_lpItem->hdr.idFrom == IDW_LISTVIEW_IMGTLB)
{
memset(&_Lvi,0,sizeof(LVITEM)) ;
memset(_szTmp,0,MAX_PATH) ;

_Hit.pt.x = _lpItem->ptAction.x ;
_Hit.pt.y = _lpItem->ptAction.y ;
_Hit.flags = LVHT_ONITEMICON ;
_Hit.iItem = 0 ;
_Lvi.iItem = (int) SendMessage(_lpItem->hdr.hwndFrom,LVM_HITTEST,0,(LPARAM) &_Hit) ;
_Lvi.mask = LVIF_PARAM | LVIF_TEXT ;
_Lvi.cchTextMax = MAX_PATH ;
_Lvi.pszText = _szTmp ;

SendMessage(_lpItem->hdr.hwndFrom,LVM_GETITEM,0,(LPARAM) &_Lvi) ;
if(_Lvi.iItem != -1)
{
memset(_szImg,0,sizeof(_szImg)) ;
SQLite_GetFileName((int) _Lvi.lParam,_szImg) ;

if(lstrlen(_szImg))
{
if(PathFileExists(_szImg))
{
lstrcpy(szCurrentFile,_szImg) ;

SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 1,(LPARAM) (LPSTR) PathFindFileName(_szImg)) ;

GetImageFileProperties(szCurrentFile,&_FileSize,&_ImageSize,_szFormatName,&_ImageWidth,&_ImageHeight) ;

sprintf_s(_szTmp,sizeof(_szTmp),"W = %d / H = %d",_ImageWidth,_ImageHeight) ;
SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 2,(LPARAM) (LPSTR) _szTmp) ;

sprintf_s(_szTmp,sizeof(_szTmp),"File size = %d",_FileSize) ;
SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 3,(LPARAM) (LPSTR) _szTmp) ;

sprintf_s(_szTmp,sizeof(_szTmp),"Image size = %d",_ImageSize) ;
SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 4,(LPARAM) (LPSTR) _szTmp) ;

SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 5,(LPARAM) (LPSTR) _szFormatName) ;

InvalidateRect(hEffects,NULL,TRUE) ;
InvalidateRect(hZoom,NULL,TRUE) ;

Memory_CreateImageList(szCurrentFile) ;
RealSizeImage_CreateImageList(szCurrentFile) ;
}
}
}
}
}
else
{
if(_lpItem->hdr.code == NM_DBLCLK)
{
if(_lpItem->hdr.idFrom == IDW_LISTVIEW)
{
memset(&_Lvi,0,sizeof(LVITEM)) ;
memset(_szTmp,0,MAX_PATH) ;

_Hit.pt.x = _lpItem->ptAction.x ;
_Hit.pt.y = _lpItem->ptAction.y ;
_Hit.flags = LVHT_ONITEMICON ;
_Hit.iItem = 0 ;
_Lvi.iItem = (int) SendMessage(_lpItem->hdr.hwndFrom,LVM_HITTEST,0,(LPARAM) &_Hit) ;
_Lvi.mask = LVIF_PARAM | LVIF_TEXT ;
_Lvi.cchTextMax = MAX_PATH ;
_Lvi.pszText = _szTmp ;

SendMessage(_lpItem->hdr.hwndFrom,LVM_GETITEM,0,(LPARAM) &_Lvi) ;
if(_Lvi.iItem != -1)
{
memset(_szImg,0,sizeof(_szImg)) ;
SQLite_GetFileName((int) _Lvi.lParam,_szImg) ;

if(lstrlen(_szImg))
{
if(PathFileExists(_szImg))
{
SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 0,(LPARAM) (LPSTR) PathFindFileName(_szImg)) ;
lstrcpy(szCurrentFile,_szImg) ;

GetImageFileProperties(szCurrentFile,&_FileSize,&_ImageSize,_szFormatName,&_ImageWidth,&_ImageHeight) ;

sprintf_s(_szTmp,sizeof(_szTmp),"W = %d / H = %d",_ImageWidth,_ImageHeight) ;
SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 1,(LPARAM) (LPSTR) _szTmp) ;

sprintf_s(_szTmp,sizeof(_szTmp),"File size = %d",_FileSize) ;
SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 2,(LPARAM) (LPSTR) _szTmp) ;

sprintf_s(_szTmp,sizeof(_szTmp),"Image size = %d",_ImageSize) ;
SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 3,(LPARAM) (LPSTR) _szTmp) ;

SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 4,(LPARAM) (LPSTR) _szFormatName) ;

InvalidateRect(hEffects,NULL,TRUE) ;
InvalidateRect(hZoom,NULL,TRUE) ;

Memory_CreateImageList(szCurrentFile) ;
RealSizeImage_CreateImageList(szCurrentFile) ;
}
}
}
}
}
else
{
if(((NMHDR *) __lParam)->code == NM_SETFOCUS)
{
if(((NMHDR *) __lParam)->idFrom == IDW_LISTVIEW)
{
memset(&_Lvi,0,sizeof(LVITEM)) ;
memset(_szTmp,0,MAX_PATH) ;

_Lvi.mask = LVIF_PARAM|LVIF_STATE|LVIF_TEXT ;
_Lvi.state = LVIS_FOCUSED|LVIS_SELECTED ;
_Lvi.stateMask = LVIS_FOCUSED|LVIS_SELECTED ;
_Lvi.pszText = _szTmp ;
_Lvi.cchTextMax = MAX_PATH ;

if(SendMessage(((NMHDR *) __lParam)->hwndFrom,LVM_GETITEM,0,(LPARAM) &_Lvi))
{
if(lstrlen(_szTmp))
{
memset(_szImg,0,sizeof(_szImg)) ;
SQLite_GetFileName((int) _Lvi.lParam,_szImg) ;

SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 0,(LPARAM) (LPSTR) PathFindFileName(_szImg)) ;
lstrcpy(szCurrentFile,_szImg) ;

SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 0,(LPARAM) (LPSTR) PathFindFileName(_szImg)) ;
lstrcpy(szCurrentFile,_szImg) ;

GetImageFileProperties(szCurrentFile,&_FileSize,&_ImageSize,_szFormatName,&_ImageWidth,&_ImageHeight) ;

sprintf_s(_szTmp,sizeof(_szTmp),"W = %d / H = %d",_ImageWidth,_ImageHeight) ;
SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 1,(LPARAM) (LPSTR) _szTmp) ;

sprintf_s(_szTmp,sizeof(_szTmp),"File size = %d",_FileSize) ;
SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 2,(LPARAM) (LPSTR) _szTmp) ;

sprintf_s(_szTmp,sizeof(_szTmp),"Image size = %d",_ImageSize) ;
SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 3,(LPARAM) (LPSTR) _szTmp) ;

SendMessage(hStatus,(UINT) SB_SETTEXT,(WPARAM)(INT) 4,(LPARAM) (LPSTR) _szFormatName) ;

InvalidateRect(hEffects,NULL,TRUE) ;
InvalidateRect(hZoom,NULL,TRUE) ;

Memory_CreateImageList(szCurrentFile) ;
RealSizeImage_CreateImageList(szCurrentFile) ;
}
}
}
}
}
}

return (0) ;
}

LRESULT ImagesToolBar_OnCreate(HWND __hWnd)
{
RECT _Rc ;
LVCOLUMN _LvCol ;

GetClientRect(__hWnd,&_Rc) ;
hLVImagesToolBar = CreateWindow(WC_LISTVIEW,szNullString,
WS_VISIBLE|WS_CHILD|LVS_ICON|LVS_SHOWSELALWAYS|LVS_SINGLESEL,
0,0,Profile.dwTumbnails_Width,_Rc.bottom,__hWnd,(HMENU) IDW_LISTVIEW_IMGTLB,hInstance,NULL) ;

memset(&_LvCol,0,sizeof(LVCOLUMN)) ;

_LvCol.mask = LVCF_WIDTH ;
_LvCol.cx = Profile.dwTumbnails_Width ;

ListView_InsertColumn(hLVImagesToolBar,0,&_LvCol) ;
_LvCol.mask = LVCF_WIDTH | LVCF_FMT ;
_LvCol.fmt = LVCFMT_IMAGE ;
ListView_InsertColumn(hLVImagesToolBar,1,&_LvCol) ;
ListView_DeleteColumn(hLVImagesToolBar,0) ;

SendMessage(hLVImagesToolBar,LVM_SETBKCOLOR,0,0) ;
SendMessage(hLVImagesToolBar,LVM_SETTEXTCOLOR,0,0x00ffff) ;

ListView_SetIconSpacing(hLVImagesToolBar,Profile.dwTumbnails_Width,Profile.dwTumbnails_Gap_Height) ;
ListView_SetExtendedListViewStyleEx(hLVImagesToolBar,LVS_SHAREIMAGELISTS | LVS_EX_BORDERSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SIMPLESELECT,LVS_SHAREIMAGELISTS | LVS_EX_BORDERSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SIMPLESELECT) ;
SendMessage(hLVImagesToolBar,LVM_SETOUTLINECOLOR,0,0x00ff0000) ;

return (0) ;
}

LRESULT ImagesToolBar_OnSize(DWORD __dwNewWith,DWORD __dwNewHeight)
{
MoveWindow(hLVImagesToolBar,0,0,__dwNewWith,__dwNewHeight,TRUE) ;

return (0) ;
}

LRESULT CALLBACK ImagesToolBarWndProc(HWND __hWnd,UINT __Msg,WPARAM __wParam,LPARAM __lParam)
{
switch(__Msg)
{
case WM_NOTIFY : return(ImagesToolBar_OnNotify(__lParam)) ;

case WM_SIZE : return(ImagesToolBar_OnSize(LOWORD(__lParam),HIWORD(__lParam))) ;

case WM_CREATE : return(ImagesToolBar_OnCreate(__hWnd)) ;
}

return(DefWindowProc(__hWnd,__Msg,__wParam,__lParam)) ;
}

JohnF

  • Guest
Re: Bizarre
« Reply #1 on: February 27, 2016, 09:52:07 am »
Turn optimizations off and debug it, find out where the problem occurs.

John

Grincheux

  • Guest
Re: Bizarre
« Reply #2 on: February 29, 2016, 10:58:43 am »
Yes but it is strange with one compiler it is OK and with an other one it is KO.
It is usefull to have two compilers because they don't detect the same errors.
Once MSVC does not see an error but Pelle's sees it or the inverse.
I insterted one column and used ListView_InsertItem but KO too.
I don't understand why it has not one column.
Should I use a listbox? For the same result.
I suspect a problem within the library.

I have advanced on the program but they are many problems with Pelle's that I have not resolved. That makes the program ugly.
The bug A = B - (C + D) is not yet resolved. So it's difficult to have code well compiled on the two compilers. With one I write A = B (C + D= and with the other I write E = C + D ; A = B - E ; !!!!!!!!!!!!

The other form A = B - C - D does not work too.
« Last Edit: February 29, 2016, 11:05:07 am by Grincheux »

Grincheux

  • Guest
Re: Bizarre
« Reply #3 on: March 12, 2016, 10:36:40 am »
I have found, witf Pelle's C Compiler you can't use macros ListView_xxxx instead use SendMessage. Now with MSVC2015 and Pelle's the are same results. :P :P

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1888
Re: Bizarre
« Reply #4 on: March 12, 2016, 02:37:50 pm »
Please create a small compilable sample.
I'll try to fix header commctrl.h

Grincheux

  • Guest
Re: Bizarre
« Reply #5 on: March 12, 2016, 05:33:29 pm »
I think that is in ListView_SetIconSpacing.

You can download the 7up program here

And the web page here

The file ImageViewer.exe is the MSVC2015 version and PImageViewer.exe is Pelle's version
« Last Edit: March 12, 2016, 05:37:16 pm by Grincheux »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1888
Re: Bizarre
« Reply #6 on: March 12, 2016, 06:07:53 pm »
I need a minimal sample as few line of source code as you can put together to show the problem.

Grincheux

  • Guest
Re: Bizarre
« Reply #7 on: March 12, 2016, 10:46:30 pm »
I did it but the only answser was John's one. Now trying to reproduce the bug is difficult. I want to tell that when I ask something ther is no answer generally, also why did I gave the answers for members that do not answers.

Take a look at macros SetIconSpacing, SetOutLineColor

SetIconSpacing is very hard to understand, when using it take care of the WM_SIZE message if you use it.

But I'll try to make what you answer. From my first post below.

There are problems with WM_CTLCOLOR_xxxxx messages
« Last Edit: March 12, 2016, 11:14:14 pm by Grincheux »

JohnF

  • Guest
Re: Bizarre
« Reply #8 on: March 13, 2016, 08:48:33 am »
Frankie,

Here's a maco with a problem in that header, I'm sure there are more.

Code: [Select]
#define ListView_GetItemRect(hwnd,i,prc,code)\
(BOOL)SNDMSG((hwnd),LVM_GETITEMRECT,(WPARAM)(int)(i),((prc)?(((RECT*)(prc))->left = (code),(LPARAM)(RECT*)(prc)):(LPARAM)(RECT*)NULL))

Had to roll my own.

Code: [Select]
#define MyListView_GetItemRect(hWnd, idx, prc, code)\
  ((RECT*)(prc))->left = code;\
  SendMessage(hWnd, (UINT)LVM_GETITEMRECT, (WPARAM)idx,(LPARAM)(RECT*)&rc)

John

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1965
Re: Bizarre
« Reply #9 on: March 13, 2016, 09:51:18 am »
ListView_SetIconSpacing and ListView_GetItemRect macros are same as in WDDK 7
ListView_SetOutlineColor macro is missing
Code: [Select]
#define ListView_SetOutlineColor(hwnd, color) \
    (COLORREF)SNDMSG((hwnd), LVM_SETOUTLINECOLOR, (WPARAM)0, (LPARAM)(COLORREF)(color))
May the source be with you

Grincheux

  • Guest
Re: Bizarre
« Reply #10 on: March 13, 2016, 12:32:32 pm »
There is something strange in SetOutLineColor The source files are here and the binaries are here

Launch PImageViewer and take a look at the border
Launch ImageViewer, there is no border

Go to tab "Layer" and compare the two combos.

I have compared with MS and Mingw I have found no differences too.

There is a mistery

Grincheux

  • Guest
Re: Bizarre
« Reply #11 on: March 13, 2016, 12:42:48 pm »
I have reinstalled Pelle's, nothing change.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1965
Re: Bizarre
« Reply #12 on: March 13, 2016, 02:55:25 pm »
This test code works same way in both compilers.
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>

#ifndef ListView_SetOutlineColor
#define ListView_SetOutlineColor(hwnd, color) (COLORREF)SNDMSG((hwnd), LVM_SETOUTLINECOLOR, (WPARAM)0, (LPARAM)(COLORREF)(color))
#endif

#pragma comment(linker, \
 "\"/MANIFESTDEPENDENCY:type='Win32' "\
 "name='Microsoft.Windows.Common-Controls' "\
 "version='6.0.0.0' "\
 "processorArchitecture='*' "\
 "publicKeyToken='6595b64144ccf1df' "\
 "language='*'\"")

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND MakeListView(HWND hWnd);
void Test1(HWND hWndLV);

TCHAR *szAppName = TEXT("WLV_List");
TCHAR *szFrameClass = TEXT("cWLV_List");
HWND hFrame, hWndLV;
HANDLE hInst;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wcx;
MSG msg;

wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = (WNDPROC) WndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
wcx.hbrBackground= (HBRUSH)COLOR_3DSHADOW;
wcx.lpszMenuName = NULL;
wcx.lpszClassName= szFrameClass;
wcx.hIconSm = 0;

if (!RegisterClassEx(&wcx))
return 0;
hInst = hInstance;

hFrame = CreateWindowEx(0, szFrameClass, szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
200, 400,
NULL, NULL, hInst, NULL);
if(!hFrame) return 0;
ShowWindow(hFrame, nCmdShow);
//UpdateWindow(hFrame);

while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_SIZE:
//MoveWindow(hWndLV, 0, 0, LOWORD(lParam), HIWORD(lParam), 0);
MoveWindow(hWndLV, 0, 0, 150, HIWORD(lParam), 0);
return 0;
case WM_CREATE:
hWndLV = MakeListView(hWnd);
Test1(hWndLV);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

HWND MakeListView(HWND hWnd) {
HWND hWndLV;
hWndLV = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
WS_CHILD | WS_VISIBLE | WS_TABSTOP // | LVS_REPORT
,0, 0, 1, 1,
hWnd, 0, hInst, NULL);
ListView_SetExtendedListViewStyle(hWndLV, LVS_EX_BORDERSELECT);
//SendMessage(hWndLV,LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_GRIDLINES, LVS_EX_GRIDLINES);
return hWndLV;
}

void Test1(HWND hWndLV)
{
TCHAR szTmp[] = TEXT("rowx");
LVITEM lvi;
HIMAGELIST hImgLst = ImageList_Create(100, 100, ILC_MASK, 4, 4);
ListView_SetImageList(hWndLV, hImgLst, LVSIL_NORMAL);
ListView_SetIconSpacing(hWndLV, 100, 4);
COLORREF color = 0;
ListView_SetOutlineColor(hWndLV, color);
lvi.mask = LVIF_TEXT;
for (int i = 0; i < 9; i++) {
lvi.pszText = szTmp;
lvi.iItem = i;
lvi.iSubItem = 0;
szTmp[3] = i + '1';
ListView_InsertItem(hWndLV, &lvi);
}
SetFocus(hWndLV);
}
In PImagesViewer.exe listview borders are blue indeed.
List in Zoom window is better in PellesC version than MS, as MS version have unnecessary dividing area between pics.
Window resizing don't work in both programs.
« Last Edit: March 13, 2016, 02:58:16 pm by TimoVJL »
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1888
Re: Bizarre
« Reply #13 on: March 13, 2016, 04:44:59 pm »
I have recompiled sources with pocc 8.00.60 and found no errors.
John, as Timo said, ListView_GetItemRect is the same as MSVC, and is correct. The unroll you made manually is equivalent to the comma operator in:
Code: [Select]
((prc)?(((RECT*)(prc))->left = (code),(LPARAM)(RECT*)(prc)):(LPARAM)(RECT*)NULL).
If prc is a valid pointer assigns to its left field the value of code then uses comma operator to pass prc to the send message function. If prc is invalid passes a null pointer.
Maybe the problem is in the user code due to slightly different interpretation of something, maybe user macros not parenthesized, or the like by the 2 compilers.
« Last Edit: March 13, 2016, 04:47:50 pm by frankie »

JohnF

  • Guest
Re: Bizarre
« Reply #14 on: March 13, 2016, 06:02:50 pm »
So you are saying that all functions that get a pointer should have this provision?

Yes I know what the macro does, PellesC doesn't like it though.

John