I picked up this program from a long time ago, and decided to do something with it, just for fun. I've added quite a lot to the original (see comments at the beginning of the listing). It will load and save quite a lot of formats
There is everything you should need to compile the program. If I have missed anything, let me know. Just move the includes and libs to the correct folders
Three things I can't figure out:
In the BrowseForFolder, I want it to jump and highlight the current folder when loading up. Any ideas?
When viewing an image larger than the actual screen size, I want it to reduce the size of the displayed image so that it fits. Any ideas?
And how do I colour the size grip when the statusbar changes to green, to signal an image has been loaded correctly?
Any comments, ideas, please let me know,
PS: I have updated the DevIL DLLs to the latest version
Nice program! Can't help with any of these questions really.
QuoteIn the BrowseForFolder, I want it to jump and highlight the current folder when loading up. Any ideas?
Check the source code, this must be happening when processing the message BFF_JUMPTOPATH
QuoteWhen viewing an image larger than the actual screen size, I want it to reduce the size of the displayed image so that it fits. Any ideas?
Same as before. Probably inside ilutConvertToHBitmap in conjunction with the code after that (loadfile function).
QuoteAnd how do I colour the size grip when the statusbar changes to green, to signal an image has been loaded correctly?
I think you can't do this unless you draw the statusbar yourself which is really hard to do.
Update: Now populates the file list box faster; added keyboard shortcuts, and various other tweaks
Help! If anyone can help with this problem, I would be very grateful. I am banging my head over this one
When the program starts up, the window is 1024 x 768. If you click on a graphic that is smaller than the client window (the grey area), the image fits perfectly in the centre
I am calculating if the image width or height is greater than the client area, and using iluScale to resize the image to fit, but obviously it is not working like I think it should be
I have more or less fixed the first example you posted because that treeview looks much better. I had to change many things, I will try to explain them briefly.
- The handle of the treeview is the handle of the BFF control. Denying this made me waste a lot of time.
- Once the treeview handle is obtained, adding TVS_SHOWSELALWAYS is simple, but it didn't work. The treeview seem to have some customdraw code that I couldn't remove by subclassing it. The only way to achieve this was to use a .manifest file and enabling visual styles.
' GET THE TREEVIEW HANDLE
INT tv_hwnd = GetDlgItem(win.hWnd, BFF)
' MODIFY THE TREEVIEW
IF tv_hwnd THEN
' SHOW ALWAYS THE SELECTION ON THE TREEVIEW
LONG lStyle = GetWindowLong(tv_hwnd, GWL_STYLE)
lStyle = lStyle | TVS_SHOWSELALWAYS
' lStyle = lStyle & NOT(TVS_HASLINES) ' <-- if you want to remove the treeview lines uncomment this
SetWindowLong(tv_hwnd, GWL_STYLE, lStyle)
' SET WINDOWS EXPLORER STYLE / YOU MUST USE A .MANIFEST FILE
SetWindowTheme(tv_hwnd, L"explorer", NULL) ' the treeview is unicode!!
' SET INITIAL FOCUS ON THE TREEVIEW
- To successfully paint listbox background & elements using visual styles it is necessary to subclass win DIALOG, and process the WM_CTLCOLORLISTBOX message.
CASE WM_CTLCOLORLISTBOX ' PAINT FILELISTBOX
IF lParam = GetDlgItem(win.hWnd, FLB) THEN
HDC hdcStatic = wParam
IF hbrBkgnd = NULL THEN hbrBkgnd = CreateSolidBrush(RGB(240,240,240))
CASE WM_PAINT ' PAINT THE IMAGE
hDC = BeginPaint(hWnd, &Ps)
RETURN DefSubclassProc(hWnd, uMsg, wParam, lParam)
- Finally, I didn't like at all that the application resizes according to the image. I decided to always start the DIALOG maximized and the image is the one that fits the screen size. Unfortunately this was impossible to achieve with SHOWIMAGE, so I had to process the WM_PAINT message and draw the image using double buffer, since for some reason the ILXXX dll functions seem to "modify" the win device context.
SUB OnPaint(INT hDC, WINRECT rc)
' start double buffer
INT hdcMem = CreateCompatibleDC(hDC)
HBITMAP memBM = CreateCompatibleBitmap(hDC, rc.right - rc.left, rc.bottom - rc.top)
HBITMAP OldmemBM = SelectObject(hdcMem, memBM)
' paint background color
HBRUSH hbrBkgnd = CreateSolidBrush(RGB(190,190,190))
FillRect(hdcMem, rc, hbrBkgnd)
' paint image
' finish double buffer
BitBlt(hDC, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hdcMem, 0, 0, SRCCOPY)
SUB PaintImage(INT hDC, WINRECT rc)
INT hdcMem = CreateCompatibleDC(hDC)
INT oldBitmap = SelectObject(hdcMem, bitmap)
GetObject(bitmap, LEN(bit), &bit)
StretchBlt(hDC, splitWidth + paddingX, paddingY, w, h, hdcMem, 0, 0, bit.bmWidth, bit.bmHeight, SRCCOPY)
Complete code and .manifest file below. EDIT: .manifest file not allowed as attachments. But make sure to use a .manifest file or some code will not work.
Thanks for the code. Will have to look later, as I am out most of the day
When I compiled, I noticed straight away that the treeview selection didn't jump to the saved folder. It jumps to the root directory of the folder, but not the saved folder
And using a manifest removes the file icons in the FileListBox. Did you notice this?
Unless the manifest file I am using is the wrong type. I know there are quite a few variations. You could always post it with a .txt extension, instead of .manifest, and point out that it needs renaming
That way, I can be certain that we are the same
Yes, sorry. I give up. I can't solve the issues you posted without modifying the dll source code.
That's OK - miracles take a bit longer!
Anyway, I have been working on it today, and have come up with a version that works in respect of centring an image that is smaller than the window, and resizing an image if it is larger. It also resizes the image if you resize the program window
Only thing that doesn't work correctly (yet) is the crop function, and zoom. Will take a look at those as time goes on. Also, when it redraws after a window, resizing could be quicker, I reckon
Otherwise, quite happy with this version. Thing is, you can go on the internet and type "image viewers" and take your pick. But there is nothing like the satisfaction of creating something of your own
Many thanks for your help in this. Please take a look at my latest offering
QuoteThing is, you can go on the internet and type "image viewers" and take your pick. But there is nothing like the satisfaction of creating something of your own
I can't agree more on that
QuotePlease take a look at my latest offering
this version you posted is fantastic. You really get the hang of those il functions. Well done!