Results 1 to 5 of 5

Thread: Window

  1. #1

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Window

    i dont understand! i spent more than 2 hours trying to fix this program...for now it should just create a window...i wrote the code myself from what i remembered...and when i compare it to other similar examples....could anyone please tell me what i forgot?
    thanks in advance!
    Attached Files Attached Files
    Amon Ra
    The Power of Learning.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Let's see:
    1) You shouldn't call your global HWND variable hwnd, as it is the same name you used in WndProc (no error, just not good)

    2) I don't think WS_BORDER is an extended window style as they all begin with WS_EX_

    3) I think you have to handle the WM_CREATE message, but I#m not absolutely sure.

    4) You didn't assign a value to wc.hIconSm. This can cause RegisterWindowEx to fail. If you don't want to use it, use WNDCLASS and RegisterClass instead (Petzold does this, btw)

    5) GetMessage(&msg, hwnd, NULL, NULL)
    This can cause one of the nastiest errors I know. Since this will only receive messages targeted at hwnd, it will not get the WM_QUIT message (that is targeted on no window) and therefor never leave the message loop, even after the widow was destroyed. The program will run on forever, so you can't (for example) recompile it. Use GetMessage(&msg, NULL, 0, 0) > 0 to receive every message in your app and even be save from the GetMessage error return (-1).

    6) I think the main problem is that you forgot the calls to ShowWindow and UpdateWindow
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Try this:)

    PHP Code:
    //[email protected]
    //Tom Zhang
    //13


    #include <windows.h>
    const char tzID[]="myWindowClass";
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
    switch(
    msg){
    case 
    WM_SHOWWINDOW:
    MessageBox(hwnd,"Hi, welcome asswhole!",MB_ICONINFORMATION|0);
    break;
    case 
    WM_CLOSE:
    DestroyWindow(hwnd);
    break;
    case 
    WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return 
    DefWindowProc(hwnd,msg,wParam,lParam);
    }
    return 
    0;
    }
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
    WNDCLASSEX tz;
    HWND hwnd;
    MSG Msg;
    tz.cbSize=sizeof(WNDCLASSEX);
    tz.style=0;
    tz.lpfnWndProc=WndProc;
    tz.cbClsExtra=0;
    tz.cbWndExtra=0;
    tz.hInstance=hInstance;
    tz.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    tz.hCursor=LoadCursor(NULL,IDC_ARROW);
    tz.hbrBackground=(HBRUSH)(COLOR_WINDOW+8);
    tz.lpszMenuName=NULL;
    tz.lpszClassName=tzID;
    tz.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
    if(!
    RegisterClassEx(&tz)){
    return 
    0;
    }
    hwnd=CreateWindowEx(WS_EX_CLIENTEDGE,tzID,"HI",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,300,200,NULL,NULL,hwnd,NULL);
    if(
    hwnd==NULL){
    return 
    0;
    }
    ShowWindow(hwnd,nCmdShow);
    UpdateWindow(hwnd);
    while(
    GetMessage(&Msg,NULL,0,0)){
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
    }
    return 
    Msg.wParam;


    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  4. #4
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    or check out the faq

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  5. #5

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    i found the bug...but thanks though
    Amon Ra
    The Power of Learning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width