Help please :/

Why will my window not show up? There is not a line of output, I thing its either how I did COLOREFF, or my messaging system.

1
2
3
4
5
6
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <stdio.h>
#include <string.h> 


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
int d;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

PAINTSTRUCT paint;

HDC hDC;

char string[] = "Hello World";


switch(msg){
// Window is being created
case WM_CREATE:
    //Return it to make sure it works properly and displays the error messages
    return 0;
    // And then break the switch statement for efficiency factors.
    break;
case WM_CLOSE:
    // see if the window is closes
    PostQuitMessage(1);
    // if so send a message to the window telling it to close
    return 0;
    // check for errors
    break;
    // break it again
DWORD COLORREF;
case WM_PAINT:
    hDC = BeginPaint(hwnd, &paint);
    SetTextColor(hDC, COLORREF = 0x00FF0000);
    TextOut(hDC, 150, 150, string, sizeof(string)-1);
    EndPaint(hwnd, &paint);
    return 0;
    break;

default:
    break;

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



}


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
int APIENTRY WinMain(HINSTANCE DERP,
                    HINSTANCE hp,
                    LPSTR CmdLine,
                   int cmdshow ){
//shortining up and tagging everything.

//first up the class of the window.
WNDCLASSEX              WC;
// The windows handle is next
HWND hwnd;
// Now the messages sent back and forth telling the window what to do and when to do it (etc)
MSG mesg;
// I am not sure what the bool valye is for.

// Now on to making the Window

WC.cbSize = sizeof(WNDCLASSEX);
// Size of the window in pixels
WC.style = CS_BYTEALIGNCLIENT||CS_HREDRAW||CS_VREDRAW;
// The windows style
WC.lpfnWndProc = WndProc;
WC.cbClsExtra = 0;
WC.cbWndExtra = 0;
WC.hInstance = DERP;
WC.hIcon = LoadIcon(NULL, IDI_ASTERISK);
WC.hCursor = LoadCursor(NULL, IDC_CROSS);
WC.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WC.lpszMenuName = "Prototype(In Progress)";
WC.lpszClassName = "Class";
WC.hIconSm = LoadIcon(NULL, IDI_WARNING);
//Register the window class


if(!RegisterClassEx(&WC)){

    return 0;

}

//class registered so now create the window

hwnd = CreateWindowEx(NULL,
                      "Class",
                      "Prototype(In Progress)",
                      WS_OVERLAPPEDWINDOW|
                      WS_VISIBLE|
                      WS_SYSMENU,
                      0,0,
                      950,500,
                      NULL,
                      NULL,
                      DERP,
                     NULL);

                     // We now check if the window creation was succsessful or a failure.

                     if(!hwnd){

                        return 0;
                        d = "false";// loop condition variable needs to be initialized

                     }
while(!d){
    PeekMessage(&mesg, NULL, NULL, NULL, PM_REMOVE);

    if (mesg.message - WM_QUIT){ // Check for the quit message


        d = "true";


    }else{ // otherwise send it to the library of events fired
TranslateMessage(&mesg);
DispatchMessage(&mesg);


    }
}

}



Never really tagged my code, but I tried I hope it is read-able now.
Last edited on
Please edit your post to put the code in code tags. It makes it much easier to read.

[code]Your code goes between these tags[/code]
I'd guess the reason is in WM_CREATE.
you return 0; and hence DefWindowProc isn't called
You're also doing some weirdness here:

1
2
3
4
5
6
7
while(!d){
    PeekMessage(&mesg, NULL, NULL, NULL, PM_REMOVE);

    if (mesg.message - WM_QUIT){ // <-  why using - operator?  Did you mean to use == ?


        d = "true";  // <- why are you assigning a string to an integer value?  This should be giving you a compiler error 




EDIT:

Also you're using the TCHAR form of WinAPI functions but are not using TCHARs. Newbie mistake.

See this if interested:
http://v2.cplusplus.com/forum/windows/105027/#msg566862
Last edited on
@kcoder, hhow would I call it? Also Disch its giving me errors when I use bool values, so I tried integers. I am trying to learn from CPLUSPLUS.com, but they have had many errors that I fixed on my own. :o
Also Disch its giving me errors when I use bool values, so I tried integers.


But you're assigning a string, which is neither a bool nor an integer.

"true" is a string because it's in quotes.

What you want is a bool, and you want to assign it a bool, not a string:

d = true; // <- notice, no quotes
btw disch your method fixrd it, thanks allot!
Oh, the whole window is invisable, or not there, it just shows the hellow world, xD
When I change it to the bool it says undeclared, not in a function.
FillRect(hDC, &paint.rcPaint, (HBRUSH) (COLOR_WINDOW+1));

Try adding this to WM_PAINT:
@TDS, now the window shows up, but Hello Works is gone :o.
Actually sorry TDS, it works fine, its jut you can not see the minus and exit or scroll bar, its a big white square on my screen with blue lettering that says Hello World.
Topic archived. No new replies allowed.