-2

How do I get LoadImage(); to work with a variable file path? I have the desired file path in the variable bg, and I'm calling the function like so:
bmp = LoadImage(hInst,bg,IMAGE_BITMAP,640,480,LR_LOADFROMFILE);

Yet bmp does not render any image when used with: BitBlt(hDC,0,0,640,480,memDC,0,0,SRCCOPY);


If I can't use LoadImage();, what equivalent is there that can handle non-constant file names?


[EDIT]

Apparently, the error was caused by another bit of code, and not the LoadImage() function. Disragerd.

  • 1
    What is `bg[]` when `LoadImage(hInst,bg,IMAGE_BITMAP...` called? There is no call to `md0()` to populate it. – chux - Reinstate Monica Oct 23 '17 at 20:16
  • Does the application crash, or does your image simply not show up? Are you sure that your timer is firing properly? – Milack27 Oct 23 '17 at 20:20
  • 1
    If you want to find out what is wrong with your program you should debug it. Why do programmers if today no longer debug their programs? – David Heffernan Oct 23 '17 at 20:43
  • 1
    Your `WM_PAINT` is leaking memory (you are not restoring the `HBITMAP` that `SelectObject()` replaced. You have to call `SelectObject()` again before calling `DeleteDC()`), and using `PostMessage()` to trigger a paint handler is wrong. Use `InvalidateRect()` instead, and let the OS trigger `WM_PAINT` when it is ready to do so. – Remy Lebeau Oct 23 '17 at 22:27
  • Please provide a [mcve]. Code that is deliberately hard to read (like the indirect function calls through function pointers) is not very helpful. – IInspectable Oct 24 '17 at 00:59
  • You made your question to short! The suggestion was to make minimal + **complete** + **verifiable** example. That does NOT mean make the question "as short as possible". Nobody would have guessed your problem from those 2 lines. By the way, you don't have to specify width and height, you can just use `LoadImage(hInst,bg,IMAGE_BITMAP,0,0,LR_LOADFROMFILE)`. – Barmak Shemirani Oct 24 '17 at 05:41

1 Answers1

0

It seems to be the timer. The documentation about the SetTimer function says that the second parameter (nIDEvent) must be a nonzero value. So, I imagine your timer is never firing, the execmain() function is never called, and so your bg string is never set.

When you replace bg by a string literal, it works, because the WM_PAINT message does not depend on the timer, it is always called at least once when the window is created.

Milack27
  • 1,619
  • 2
  • 20
  • 31