Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

set window placement of current app window

- - - - -

  • Please log in to reply
8 replies to this topic

#1
jjj93421

jjj93421

    Newbie

  • Member
  • 17 posts
  • Joined 24-August 04
Hi. I'm programming in c++ win32 and I need some code that will take the current window app that is on the screen and set placement of it to certain x, y coordinates on the screen. (please no MFC)

Thanks and please be specific.


How to remove advertisement from MSFN

#2
HeartsOfWar

HeartsOfWar

    Newbie

  • Member
  • 49 posts
  • Joined 25-February 04
Use windowPOS

see the documentation here http://msdn.microsof...s/windowpos.asp
Posted Image

#3
jjj93421

jjj93421

    Newbie

  • Member
  • 17 posts
  • Joined 24-August 04
Thanks. Use setwindowpos , you mean?

I am using this now:
It gives me errors saying:

C:\Program Files\Microsoft Visual Studio\MyProjects\get pixel win32\getpixel7.cpp(18) : error C2059: syntax error : 'constant'
C:\Program Files\Microsoft Visual Studio\MyProjects\get pixel win32\getpixel7.cpp(19) : error C2059: syntax error : 'constant'
Error executing cl.exe.


Here is the code:

const char* caption = "Poker";
HWND hwnd = FindWindow(NULL, caption);


BOOL SetWindowPos( HWND hWnd,
    HWND HWND_TOP,
    100,
    100,
    2,
    2,
    UINT SWP_NOSIZE
);

How do you get the handle? Am I doing it right?

#4
HeartsOfWar

HeartsOfWar

    Newbie

  • Member
  • 49 posts
  • Joined 25-February 04
If you didn't keep track of the HWND variable when you created the window, using CreateWindow or CreateWindowEx, then yes you can use FindWindow, but that is a mediocre way of doing it. Better to track the variable like so:

hwnd = CreateWindowEx(NULL, ClsName, WndName, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT,
  CW_USEDEFAULT, WndWid, WndHgt, NULL, NULL, Instance, (void*) this)

This way, you always have the TOP window handle in case you need it... If you did it this way, use the variable you used instead.

BOOL SetWindowPos( HWND hWnd,
HWND HWND_TOP,
100,
100,
2,
2,
UINT SWP_NOSIZE
);


You're not using the function properly...

First, the 'BOOL' word lets you know that the 'SetWindowPos' function will return a true or false when it has actually been called. You don't need to write this when calling it.

Second, When you call a function, you don't include the DATA TYPE declaration... so, you can remove the HWND in front of the first & second parameters, along with removing the 'UINT' from the final parameter.

Your final result should resemble something of this nature:

SetWindowPos(hwnd, HWND_TOP, 100, 100, 2, 2, SWP_NOSIZE);

However, you may want to review those numbers, because your function will create the window offset by 100 vertically & Horizontally, but it would only have a width & height of 2 pixels.... Is that what you wanted?
Posted Image

#5
jjj93421

jjj93421

    Newbie

  • Member
  • 17 posts
  • Joined 24-August 04
Thanks for the reply. The SWP_NOSIZE should make it ignore the height and width numbers (the 2's). This child window that I am trying to move wasn't created by me. It is an application.

Right now, I'm having trouble getting a handle on the child window. The hwnd or whatever. Can you help?

Basically, all I need to do is get a handle on the current child window on the screen just below my console program and move it over to the left and up. Thanks.

#6
jjj93421

jjj93421

    Newbie

  • Member
  • 17 posts
  • Joined 24-August 04
Let me explain further,

I need to get the handle of the window at the bottom of the Z order. Or, the window underneath my console program window.

#7
HeartsOfWar

HeartsOfWar

    Newbie

  • Member
  • 49 posts
  • Joined 25-February 04
It's a child window? And you didn't create the Window... you're just trying to manipulate it?

You need to use 'FindWindow' along with 'FindWindowEx'...

Use 'FindWindow' to retrieve the HWND of the TOP WINDOW or PARENT window. You will need to know the className or WindowName. The preferred method is the className, as it is unique..., but if you didn't make the window, you won't know that. SO use the PARENT Window Name instead.

Once you have the PARENT HWND, use that variable within 'FindWindowEx' to locate the child Window. Once again, you're going to need either the Child's Class name or Window name. Same rules apply as the PARENT.

Then try setting the Window Position using 'SetWindowPos'.

HWND Phwnd, chwnd;
Phwnd = FindWindow(NULL,"CLASSNAME", "WINDOWNAME");

chwnd = FindWindowEx(Phwnd, NULL, "CLASSNAME", "WINDOWNAME");

SetWindowPos(chwnd, HWND_TOP, 100, 100, 2, 2, SWP_NOSIZE);

Posted Image

#8
jjj93421

jjj93421

    Newbie

  • Member
  • 17 posts
  • Joined 24-August 04
Thanks for the help Hearts. I finally got it working. It feels good to see your program work. I did a double take when I saw the window move.

I'm new to programming as you may have guessed so it feels good when something works especially when it is windows programming.

Actually, I'm not sure I would have gotten without your help. thanks. I like setwindowpos better than movewindow.

#9
HeartsOfWar

HeartsOfWar

    Newbie

  • Member
  • 49 posts
  • Joined 25-February 04
Great... Glad to know I could help...

I know how you feel... that's why I'm A CSC major ;-)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users