Thread: help with creating window

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    124

    help with creating window

    Code:
    #include <windows.h>
    
    #define WndClsname[] "Justin's window class"
    
    
    LRESULT CALLBACK WndProcedure( HWND hwnd, UNIT msg, WPARAM wParam, LPARAM lParam);
    
    
    
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine, int nCmdShow )
    {
      HWND hwnd;
      WNDCLASSEX wc;
      MSG msg;
      
      wc.cbSize      = sizeof(WNDCLASSEX);
      wc.style       = CS_VREDRAW|CS_HREDRAW;
      wc.lpfnWndProc = WndProcedure;
      wc.cbClsExtra    = 0;
      wc.cbWndExtra    = 0;
      wc.hInstance     = hInstance;
      wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
      wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
      wc.lpszMenuName  = NULL;
      wc.lpszClassName = WndClsname;
      wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
      
      if(!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
       hwnd = CreateWindowEx
       (WS_EX_CLIENTEDGE,
        WndClsname,
        "The title of the window",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        320,120,
        NULL,NULL,hInstance, NULL
        );
        if(hwnd == NULL)
        {
            MessageBox(NULL, "Window Creation Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    
    
        while(GetMessage(&msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
       return msg.wParam;
    
    }
    
    LRESULT CALLBACK WndProcedure( HWND hwnd, UNIT msg, WPARAM wParam, LPARAM lParam)
    {
            switch(msg)
            {
             case WM_CLOSE:
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
            default:
                     return DefWindowProc(hwnd, msg, wParam, lParam);
                     break;
             }
    return 0;
    }
    i get errors concerning UNIT is undeclared,
    invalid conversion from `LRESULT (*)(HWND__*, int, WPARAM, LPARAM)' to `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)', and
    expected primary-expression before ']' token

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    You mean UINT not UNIT,

    Keep your Window class name simple, and avoid spaces, also you're not allowed special characters in macros

    Code:
    #define WND_CLASS_NAME "JUSTINS_WC"
    
    wc.lpszClassName = WND_CLASS_NAME;
    
    /* ... */
    
      hwnd = CreateWindowEx
       (WS_EX_CLIENTEDGE,
        WND_CLASS_NAME,
    /* ... */

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    124
    Hey, thanks for helping me for my syntax error and i'll stray from using special characters in macros xD

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    124

    hey i have another problem

    im using resource file to make a new cursor...
    i used icon suite program for the visual editor, and script the rc file
    in bloodshed(latest ver)

    Code:
    #include "resource.h"
    
    IDC_REDCUR  CURSOR "Red.cur"
    This is the .rc script and the
    header i just type in #define IDC_REDCUR 104 .

    for the program i just modtify it with
    wc.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_REDCUR));
    and the image is 16x16 256 color ...

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    124
    the problem is that it doesn't show the custom cursor and instead the default one

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by zacs7 View Post
    You mean UINT not UNIT,
    yes, the imfamous UNIT bug, i just made this one myself not 5 minutes ago :|

    try this instead:
    Code:
    wc.hCursor = LoadCursor(hInstance, TEXT ("IDC_REDCUR"));
    Last edited by abachler; 06-12-2007 at 05:48 PM.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    124

    oooh i found the problem

    it's weird but it saids
    [Resource error] cursor file `Red.cur' does not contain cursor data
    xD
    well this is the problem but the file i use i made with an external visual editor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a child window in a parent window
    By vopo in forum Windows Programming
    Replies: 8
    Last Post: 10-06-2007, 04:15 PM
  2. Creating a window causes a trackbar to stop working?
    By kidburla in forum Windows Programming
    Replies: 2
    Last Post: 09-20-2007, 05:44 AM
  3. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  4. Creating a window through menu
    By Homunculus in forum Windows Programming
    Replies: 17
    Last Post: 02-20-2006, 06:56 PM
  5. Problem with creating new window, from another window
    By Garfield in forum Windows Programming
    Replies: 6
    Last Post: 01-11-2004, 02:10 PM