Results 1 to 12 of 12

Thread: Please Help Me.

  1. #1

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    Exclamation

    Can Anybody Tell Me How To Center A Win32 Form On Startup. I don't know if your supposed to get the width of the desktop and subtract the width of the appwindow, and divide by 2, and then do the same for the height. i would appreciate any code on centering my appwindow. it doesn't have a titlebar, so i would like for it to be centered as i haven't made an option to move it. thanx for any input on the subject.

    AAG

  2. #2
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    Talking Possible Answer

    Don't quote me on this, but I'm pretty sure you can Pass either WS_CENTERED or WS_CENTER when using CreateWindowEx and the window will be centered. Hope it works.
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  3. #3

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    Exclamation Already tried that.

    i had already tried WS_CENTER and WS_CENTERED. The function is unkown. thanx for the effort though. Can somebody please tell me the correct way to center a window. thanx

  4. #4
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    Talking Maybe this then

    If you use a resource, it has a flag there that you can add, which is Center form?? Tick it, then open the resource in note pad, and see how it works. Just a suggestion.
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  5. #5

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    already tried that.

    thanx for the help though

  6. #6
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Use the GetSystemMetrics function and use the formula you stated above, i.e.....

    PHP Code:
    int wdth;
    int hgt;
    int x;
    int y;

    //other code here

    wdth 420;
    hgt 300;

    = (GetSystemMetrics(SM_CXSCREEN) / 2) - (wdth 2);
    = (GetSystemMetrics(SM_CYSCREEN) / 2) - (hgt 2);

    hwnd CreateWindowEx(
          
    WS_EX_CLIENTEDGE,
          
    g_szClassName,
          
    "The title of my window",
          
    WS_OVERLAPPEDWINDOW,
          
    xywdthhgt,
          
    NULLNULLg_hInstNULL);

    // rest of the code here 
    WOW! I think I answered a C++ question. WOO-HOO!!
    Last edited by YoungBuck; Mar 11th, 2001 at 01:29 AM.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  7. #7

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    Talking Thanx :)

    Thanx alot man it worked great i owe u one.

  8. #8
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    Unhappy KULE

    How bout this one then.
    How do I get what would be equivalent to Me.Left in vb??

    Thanx in advance...
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  9. #9
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    GetWindowRect retrieves the coordinates of a window as it relates to the screen....

    PHP Code:
    RECT me;

    GetWindowRect(hwndme);

    cout << me.left << endl
    2 in 24 hours YEE-HAW!! hehe
    Last edited by YoungBuck; Mar 11th, 2001 at 10:58 AM.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    RECT me;
    
    GetWindowRect(hwnd, &me);
    
    cout << me.left << endl;
    Two minor problems...it must be the address of me, and since you're in a window you don't have a console
    Code:
    char buf[40];
    MessageBox(hwnd, itoa(me.left, buf, 10), "Left!", MB_OK);
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    LOL Thanks for stealing my thunder parksie
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  12. #12

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    thanx for your replies.

    thankx again
    AAG

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