Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,561 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,896 people online right now. Registration is fast and FREE... Join Now!




Basic Window

 
Reply to this topicStart new topic

Basic Window

Clearman
16 May, 2008 - 01:48 PM
Post #1

New D.I.C Head
*

Joined: 13 Dec, 2007
Posts: 48


My Contributions
Hello everybody

I have a problem with a basic window and i cant finger what the problem is.

CODE

#include <windows.h>    

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nShowCmd)
{
        MessageBox(NULL,
               L"Hello World!",
               L"Just another Hello World program!",
               MB_ICONEXCLAMATION | MB_OK);

    
    return 0;
}


Errors


C:\Documents and Settings\/*****/\Desktop\testwindow.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':

13 C:\Documents and Settings\/*****/\Desktop\testwindow.cpp cannot convert `const wchar_t*' to `const CHAR*' for argument `2' to `int MessageBoxA(HWND__*, const CHAR*, const CHAR*, UINT)'


I am using bloodshed dev-C++.
The tutorial i am looking at advices to use " Microsoft visual studio 2005" . I am downloading it now but would like to know how to fix this problem in dev.

Also if you can point me out to your c++ code tags for the forums.

Thanks in advance.

Tutorial i am using:
http://www.directxtutorial.com/Tutorial9/A-Win32/dx9A2.aspx

This post has been edited by Clearman: 16 May, 2008 - 03:35 PM
User is offlineProfile CardPM
+Quote Post

KYA
RE: Basic Window
16 May, 2008 - 03:37 PM
Post #2

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 4,924



Thanked: 105 times
Dream Kudos: 1200
My Contributions
Get rid of the "L" in front of the parameters. you don't need to cast them. You'll often see things like that in front. "TEXT" is another popular one. It depends on your compiler and various standards:

cpp

#include <windows.h>

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
MessageBox(NULL,
"Hello World!",
"Just another Hello World program!",
MB_ICONEXCLAMATION | MB_OK);


return 0;
}

User is offlineProfile CardPM
+Quote Post

Clearman
RE: Basic Window
16 May, 2008 - 03:37 PM
Post #3

New D.I.C Head
*

Joined: 13 Dec, 2007
Posts: 48


My Contributions
Wow thanks kya .
i owe you one

This post has been edited by Clearman: 16 May, 2008 - 03:40 PM
User is offlineProfile CardPM
+Quote Post

Clearman
RE: Basic Window
17 May, 2008 - 03:06 AM
Post #4

New D.I.C Head
*

Joined: 13 Dec, 2007
Posts: 48


My Contributions
Sorry to post a new problem in here but i thought it would be useless to make a new topic for such a similar problem .
Dont want to use up all the server space.

I took out the "L" parameters in this one. smile.gif
CODE

#include <windows.h>
#include <windowsx.h>


LRESULT CALLBACK WindowProc(HWND hWnd,
                         UINT message,
                         WPARAM wParam,
                         LPARAM lParam);


int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    
    HWND hWnd;
  
    WNDCLASSEX wc;

  
    ZeroMemory(&wc, sizeof(WNDCLASSEX));

  
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC)WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = "WindowClass1";


    RegisterClassEx(&wc);

  
    hWnd = CreateWindowEx(NULL,
                          "WindowClass1",    
                          "Our First Windowed Program",  
                          WS_OVERLAPPEDWINDOW,    
                          300,    
                          300,    
                          500,    
                          400,    
                          NULL,    
                          NULL,    
                          hInstance,    
                          NULL);    //<--- ERROR HERE

  
    ShowWindow(hWnd, nCmdShow);




    MSG msg;

    while(GetMessage(&msg, NULL, 0, 0))
    {
      
        TranslateMessage(&msg);

        
        DispatchMessage(&msg);
    }

  
    return msg.wParam;
}


LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // sort through and find what code to run for the message given
    switch(message)
    {
        // this message is read when the window is closed
        case WM_DESTROY:
            {
                // close the application entirely
                PostQuitMessage(0);
                return 0;
            } break;
    }

    // Handle any messages the switch statement didn't
    return DefWindowProc (hWnd, message, wParam, lParam);
}


Error:

49 C:\Documents and Settings\Ciachyou\Desktop\Untitled1.cpp [Warning] passing NULL used for non-pointer converting 1 of `HWND__* CreateWindowExA(DWORD, const CHAR*, const CHAR*, DWORD, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)'

This post has been edited by Clearman: 17 May, 2008 - 03:14 AM
User is offlineProfile CardPM
+Quote Post

bizzehdee
RE: Basic Window
17 May, 2008 - 02:10 PM
Post #5

New D.I.C Head
Group Icon

Joined: 6 Apr, 2008
Posts: 45



Thanked: 2 times
Dream Kudos: 200
My Contributions
the best tutorial on all of the web for someone who is new to coding up windows is over at winprog.org. you want "the basics" tutorial first. this shows you through from 0 to window in easy to follow steps
User is offlineProfile CardPM
+Quote Post

Clearman
RE: Basic Window
17 May, 2008 - 03:52 PM
Post #6

New D.I.C Head
*

Joined: 13 Dec, 2007
Posts: 48


My Contributions
Thank you
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:35PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month