"Paint" error.

closed account (oN3AqMoL)
Hello! Im a noob at C++ windows programming and I keep coming up with this error:
every time it reaches the point to paint, it suddenly stops. Heres the code:

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//initial windows classes for windows C++
#include"StdAfx.h"
#ifndef UNICODE
#define UNICODE
#endif 

#include <windows.h>

#include"Targetver.h"
#include"Resource.h"


LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
    //Windows Class
    const wchar_t CLASS_NAME[]  = L"YAHBOYS";
    
    WNDCLASS wc = { 0 };

    wc.lpfnWndProc   = WindowProc;
    wc.hInstance     = hInstance;
    wc.lpszClassName = CLASS_NAME;

    RegisterClass(&wc);

    // Creating the window

    HWND hwnd = CreateWindowEx(
        0,                              // Style
        CLASS_NAME,                     // ClassName
        L"YAHBOYS",    // Bar Text
        WS_OVERLAPPEDWINDOW,            // Window style

        // Position
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

        NULL,       // Parent window    
        NULL,       // Menu
        hInstance,  // Instance handle
        NULL        // Additional application data
        //Not really sure what this is yet, but ill figure out later
		);

    if (hwnd == NULL)
    {
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
	
    // Message loop.

    MSG msg = {0};
    while (GetMessage(&msg, NULL, 0, 0)>0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_CREATE:
		{
			return 0;
		}
	case WM_DESTROY:
		//In case They try to destroy my window, I give them a very angry message with an OK slot and a CANCEL slot
        if( MessageBox(hwnd,L"YOU TRYING TO CLOSE MY WINDOW!!!!!!!AHHHHHH!!!!!!!!!!!", L"I CANT BELIEVE YOU!", MB_OKCANCEL) == IDOK)
		{
			
			DestroyWindow(hwnd);
		}
		else
		{
			MessageBox(hwnd,L"BETTER not close my dang window.",L"MMMM HMMM",NULL);
		//better pick cancel, sonny
		}
			return 0;

    case WM_PAINT:
        {
            //This is where Im getting stuck:
			PAINTSTRUCT ps = { 0 };
			/*The program initializes until it gets here then suddenly STOPS.  .
            I know because right now even my compiler is saying the next line will be executed.*/
			HDC hdc = BeginPaint(hwnd, &ps);

            FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));

            EndPaint(hwnd, &ps);
        }
        return 0;

    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}




Hope you guys can help!
__________________________________________________________

Just a little comic for you guys who considered helping me.
Programmer 1: "So I'm working on using this java mod."
Programmer 2: "Wait..... You use JAVA??"
Programmer 1: "Well yes but Java is actually-"
Programmer 2: "HAHAHAHAHAH!!!!"
Programmer 1: "Hey well now, java's not that-"
Programmer 2: "BUT-BUT YOU USE JAVA!!HAHAHAHAH!!!!!!"
Last edited on
Try to return 0 on a WM_CREATE message. Maybe it has something to do with that. Or Initialize ps as 0 ( PAINTSTRUCT ps = {0}; ).
closed account (oN3AqMoL)
Whoops! Sorry if I misled you, but ti worked one time and now itsa stuck the the return 0. I posted the new code just now.
Last edited on
closed account (oN3AqMoL)
Just an update: Im getting a new error: Cannot find or open the PDB file.
Still didn't test it, but i noticed this line may be inappropriate:
WNDCLASS wc = { };
and should be
WNDCLASS wc = { 0 };
Unless you want to use WNDCLASSEX with RegisterClassEx.
EDIT:
MSG msg = { }; also.
RE-EDIT:
And while (GetMessage(&msg, NULL, 0, 0)) should be while (GetMessage(&msg, NULL, 0, 0) > 0). Now giving an eye to the WM_PAINT section.

It doesn't look to get stuck.

About the PDB file, a PDB file contains debugging informations about a header. Microsoft didn't provide PDB files for most of the WINAPI, else if they did provide such PDB files, their Windows OS would have been Open Souce-ish. That's probably not a fatal error. Or is it? If it is, try Cleaning/Recompiling the Project, and Compiling again.
Last edited on
closed account (oN3AqMoL)
Still doesnt work.... Now when I say OK to close the window the message just pops back up again
Last edited on
You should handle WM_CLOSE, not WM_DESTROY. And you should call PostQuitMessage(0), not DestroyWindow. See if something changes, then ^.
Topic archived. No new replies allowed.