createWindowEx problem

Hey, I'm a newbee to windows-programming in C++, and I just tried to create a window, which doesn't seem to work.

Here is 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
#include <windows.h>
#include <wingdi.h>

LRESULT CALLBACK WndProc( HWND hWnd, UINT messg, 
                                        WPARAM wParam, LPARAM lParam )
{
}

int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPreInst,LPSTR lpszCmdLine,int nCmdShow )
{
    MessageBox(NULL,"Wilt u sluiten?","Aan u de keuze",MB_OKCANCEL | MB_ICONQUESTION);
    //set class-window
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);//size of object
    wc.style=0;//no style
    wc.lpfnWndProc=WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance=hInst;
    wc.hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
    wc.hCursor = LoadCursor(NULL,IDC_ARROW);
    wc.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = TEXT("WINCLASS1");
    wc.hIconSm = LoadIcon(NULL, IDI_EXCLAMATION);
    //register window-class
    RegisterClassEx(&wc);
    //make window
    HWND hWnd;
    hWnd = CreateWindowEx 
    (NULL,
    "WINCLASS1",
    "A Basic Window",
    WS_OVERLAPPEDWINDOW | WS_VISIBLE,10, 
    10,
    200, 
    200,
    NULL,
    NULL,
    hInst,
    NULL); 
    return 0;
}


I get the following errors:
1
2
[Warning] passing NULL used for non-pointer converting 1 of 'HWND__*CreateWindowExA(etc..)
[Linker error] undefined reference to 'GetStockObject@4' 


I've read that you should change something in the project-menu (change from console-application to windows-application or link gdi32.lib) but in my Dev-c all options of the menu "project" are disabled! What should I do? How to link libraries?
Last edited on
sorry no answer for you,
just wondering where you got this code?
Im trying to create a simple window but my code is completely different from yours
In "C++ programming for the absolute beginner". But I solved the problem already. Now I feel sheepy: just go to "file-new-project" and then the project option should be available.
O no, nothing is displayed on the screen! How is that possible. I added the line
"ShowWindow(hWnd, nCmdShow);" without any effect! I have the feeling that it shows for a moment and then disappears again.
Last edited on
yes, your window will show very briefly (after you answer the messagebox),
because you ask the program to quit on Line 42 return 0.

So the last two lines of your code as show above are:

1. Display window
1
2
hWnd = CreateWindowEx 
    (NULL,"WINCLASS1","A Basic Window",WS_OVERLAPPEDWINDOW | WS_VISIBLE,10, 10,200, 200,NULL,NULL,hInst,NULL); 


2. End program return 0;

You are missing the message loop which comes between these two action.
Last edited on
Oh yeah,
the WndProc should pass on unused messages to the
default windows preceddure DefWindowsProc
Topic archived. No new replies allowed.