Basic chunk...Help please

Heres the output:


D:\Videos\CustomStory(Red X Orginization)\main.cpp|54|error: 'WM_Paint' was not declared in this scope|



c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\wingdi.h|2976|error: initializing argument 2 of 'void* SelectObject(HDC, HGDIOBJ)' [-fpermissive]|


D:\Videos\CustomStory(Red X Orginization)\main.cpp|64|error: invalid conversion from 'HGDIOBJ {aka void*}' to 'HBITMAP' [-fpermissive]|



D:\Videos\CustomStory(Red X Orginization)\main.cpp|66|error: invalid conversion from 'int' to 'HGDIOBJ {aka void*}' [-fpermissive]|


c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\wingdi.h|2874|error: initializing argument 1 of 'int GetObjectA(HGDIOBJ, int, PVOID)' [-fpermissive]|


D:\Videos\CustomStory(Red X Orginization)\main.cpp|68|error: too few arguments to function 'BOOL BitBlt(HDC, int, int, int, int, HDC, int, int, DWORD)'|


c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\wingdi.h|2707|note: declared here|



D:\Videos\CustomStory(Red X Orginization)\main.cpp||In function 'LRESULT WndProc(HWND, UINT, WPARAM, LPARAM)':|
D:\Videos\CustomStory(Red X Orginization)\main.cpp|54|error: 'WM_Paint' was not declared in this scope|
D:\Videos\CustomStory(Red X Orginization)\main.cpp|64|error: invalid conversion from 'int' to 'HGDIOBJ {aka void*}' [-fpermissive]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\wingdi.h|2976|error: initializing argument 2 of 'void* SelectObject(HDC, HGDIOBJ)' [-fpermissive]|
D:\Videos\CustomStory(Red X Orginization)\main.cpp|64|error: invalid conversion from 'HGDIOBJ {aka void*}' to 'HBITMAP' [-fpermissive]|
D:\Videos\CustomStory(Red X Orginization)\main.cpp|66|error: invalid conversion from 'int' to 'HGDIOBJ {aka void*}' [-fpermissive]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\wingdi.h|2874|error: initializing argument 1 of 'int GetObjectA(HGDIOBJ, int, PVOID)' [-fpermissive]|
D:\Videos\CustomStory(Red X Orginization)\main.cpp|68|error: too few arguments to function 'BOOL BitBlt(HDC, int, int, int, int, HDC, int, int, DWORD)'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\wingdi.h|2707|note: declared here|
D:\Videos\CustomStory(Red X Orginization)\main.cpp|58|warning: unused variable 'ps' [-Wunused-variable]|
||=== Build finished: 7 errors, 1 warnings (0 minutes, 2 seconds) ===|




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

     case WM_Paint:
            {

                BITMAP bm;
                PAINTSTRUCT ps;

                HDC hdc;

                HDC hdcMem = CreateCompatibleDC(hdc);

                HBITMAP old = SelectObject(hdcMem, RedXOrginization_Background_Image);

                GetObject(RedXOrginization_Background_Image, sizeof(bm), &bm);

                BitBlt(hdc,0,0,bm.bmWidth, bm.bmHeight, 0, 0, SRCCOPY);

                SelectObject(hdcMem, old);

                DeleteDC(hdcMem);

            }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//     case WM_Paint:
       case WM_PAINT:    // <- it's WM_PAINT, capitalized
            {

                BITMAP bm;
                PAINTSTRUCT ps;

                HDC hdc;
/* !!! */       hdc = BeginPaint( your_window, &ps );  // you have to initialize your HDC

                HDC hdcMem = CreateCompatibleDC(hdc);

//              HBITMAP old = SelectObject(hdcMem, RedXOrginization_Background_Image);
                HBITMAP old = (HBITMAP)SelectObject(hdcMem, RedXOrginization_Background_Image);
                //                ^  This has to be cast.  Normally you should not cast around
                //   compiler errors, but it's OK here since that's what you're supposed to do.

//              GetObject(RedXOrginization_Background_Image, sizeof(bm), &bm);
/* !!! */       // I'm not familiar enough with GetObject to comment on what's wrong with it.
                //   you can read up on it here:
                // http://msdn.microsoft.com/en-us/library/windows/desktop/dd144904%28v=vs.85%29.aspx
                //
                // It might be as simple as casting the first param to (HGDIOBJ) similar to what
                //   I did for SelectObject up there.  so maybe this?
                GetObject((HGDIOBJ)RedXOrginization_Background_Image, sizeof(bm), &bm);
                

//              BitBlt(hdc,0,0,bm.bmWidth, bm.bmHeight, 0, 0, SRCCOPY);
                BitBlt(hdc,0,0,bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
                //                                        ^  You have to tell it which DC
                //  you want to blit from.  In this case, you want to blit from your memory DC
                //  since it holds your bitmap.  For more info:
                //  http://msdn.microsoft.com/en-us/library/windows/desktop/dd183370%28v=vs.85%29.aspx

/* !!! */       EndPaint( your_window, &ps );  // be sure to finish painting with EndPaint
                
                SelectObject(hdcMem, old);

                DeleteDC(hdcMem);
                

            }



Also, you probably should not be Creating/Deleting a DC every time you paint. Instead, try creating the HDC once (when you load the bitmap maybe?) and keep it alive until you no longer need it.

Same goes for the GetObject call. That can be done once and then you can just hang on to that info... rather than re-getting it every paint.

Although BeginPaint/EndPaint must be called every paint.
Last edited on
Do you know of any good tutorials on this, the one I have is the forgers, but its not working.
Nah, sorry. There was a WinAPI tutorial I learned the basics from like 8 years ago, but I doubt it's still around (and even if it is I doubt I'd be able to find it). Apart from that I've just learned what I have by reading reference pages on MSDN.

EDIT: did I really just say 8 years? It's been longer than that. I keep forgetting how old I am.
Last edited on
Topic archived. No new replies allowed.