HWND problem

This is a discussion on HWND problem within the Windows Programming forums, part of the Platform Specific Boards category; I want to be able in my applications to tell if the app's window is resized, moved around, or just ...

  1. #1
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114

    HWND problem

    I want to be able in my applications to tell if the app's window is resized, moved around, or just minimized and stuff, and I googled to figure out that most of the functions that could achieve his used a variable of type "HWND". But the problem is that I found nothing about how to set this variable to my application's console window process Id or whatever. I know that it can be complicated since an app can have multiple windows, but in my case I only have one.

    But what is the function to set that kind of variable to the window? I know that we can also set it to another window that has no real connection to our app, but I'd like to find something that just get the Id from where the function was called, so in my application.

    I have found something, but that's not helpful as I need to find the position of the window first! "WindowFromPoint()"... But BTW I use Windows XP, and my complier is MSVC++6...

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I'm not sure what it is you're trying to do. The app with the window is your app? If so, you just handle the message WM_SIZE to find out when its sized. Many actions have an associated WM_ message.

    but if you are doing a windows app, you would probably know about WM_SIZE already. I'm not sure where you're going with this
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I think I would need you to just be more specific as to what your app is, and is trying to do
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Well, I just want to know how I can manage to work around with window handles, but it's currently to try on a console window (just learning...) and then later I will try to use these in a game, but that will be in some time. First I need to know how to catch the window's events and get/set them. I just need to know what to do after this:

    Code:
    HWND hwnd;
    hwnd = some_function_that_return_what_is_the_application_id();
    //then try stuff here with the handle!
    But that's a function that I'm not aware about now... I know I will(maybe) be able to deal with my window because I found some functions, just I'm not able to set a value or address to an HWND...
    Code:
    SetWindowPos(/*hwnd params...*/);
    SetConsoleTitle(/*hwnd params...*/);
    GetWindowPlacement(/*hwnd params...*/);
    I would really like to know, because I couldn't find any thing related to this, even on MSDN...

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    ok I think there's a misunderstanding somewhere in here. the HWND is a handle to a window. You get it from CreateWindow. Which means your app created the window. If you're trying to manipulate another application that you did not right, its a whole different ball game.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Well, the console window is created by itself when I run my application... I just can't do a thing to it since it's the "main()" that does it (I think...)

  7. #7
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I think I understand what you're trying. Well first off, the console window is not your app. Your app is running inside the console window. If you're trying to learn how to do windows stuff, this is not the right approach. If you really want to screw with the console window itself though, I don't think I can help you without researching it.

    maybe someone else?
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    I have researched the topic, and I'll just say that it's very hard and very unreliable. The console window seems to change its window class in every Windows version, never has a predictable title, and is thus impossible to find directly.
    Because the console doesn't fully belong to your program (that is, it might have been created by your program, but that's unlikely - more likely it was created by explorer.exe, cmd.exe, or vstudio.exe) you can't even enumerate all windows of your app and just grab the most likely one.

    If you want to play around with windows, do yourself a favour and use regular windows.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    I see. I'll have to try with "real" windows app then... But it looks really complicated, though...

  10. #10
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    yes, it is fairly complicated. But have you tried .NET? Much less complicated
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  11. #11
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Well, I don't really know what's .NET... I mean I'm all mixed up with all the compilers versions and frameworks, I just can't seem to tell what is what... But I know that I might be working with it, because of the "about MSVC" tab in the comp...

  12. #12
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    figure out which version of MSVC you have. But I have to say, you don't sound like you're ready for windows programming yet.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  13. #13
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Well, I know I'm maybe not ready for this, but I'm making efforts to try myself at it. Since yesterday I gathered pieces of snippets about creating windows and I found out a kind of library that handles windows and I want to be able to do that to be able to handle also the pixels in a window, because I'm able to do it all by myself, using SDL... So I checked in a 20000 lines of code header file and found out some things that might help me build a window.

    I will look later to how to change the screen's pixels, but right now I'm only trying to "keep" a window. Though I fail... This is what I came up with, it sure is messed up, but when I run it I get a window that opens and closes in a flash, even if my program enters an infinite loop...

    Code:
    #include "windows.h"
    
    
    static DWORD WINAPI _events_thread(void* arg) {
    	CLIENTCREATESTRUCT lpParam;
    	RECT rect;
    	rect.left = rect.top = 0;
    	rect.right = 480;
    	rect.bottom = 432;
    	AdjustWindowRect(&rect, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, false);
    	CreateWindowA("MDICLIENT", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
    	480, 432, 0, 0, 0, &lpParam);
    	return 0;
    }
    
    void main() {
    	HANDLE	thread;
    	HANDLE	created;
    	HANDLE	mutex;
    	void	*arg = 0;
    	
    	unsigned long		ThreadID;
    	mutex = CreateMutex(0, 0, 0);
    	created = CreateEvent(0, 0, 0, 0);
    	thread = CreateThread(0, 0, _events_thread, arg, 0, &ThreadID);
    	WaitForSingleObject(thread, INFINITE);
    	
    	for (;;) {}
    }
    So I came up with this, but I got to mention, my project type is still in console, so I think I'd have to use WinMain() and change to a Window project, right?

    Edit: I tried also "__stdcall WinMain(void) {" to change from "void main()", but I get an error telling me that I can't just overload that function... As if I was trying to redefine a previously defined function... What??
    Last edited by mikahell; 08-12-2006 at 09:10 AM.

  14. #14
    Registered User
    Join Date
    May 2006
    Posts
    903
    There are *so* many things wrong in that code. Either start learning how to properly program with the Win32 API (www.winprog.org) or learn how to use C++ itself correctly but don't try to mix that many things you don't fully understand.

  15. #15
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Yeah I know BTW how to use C++ correctly but its just that I never tried on with this kind of programming (meaning building a window...) but it's just that I like to rush myself and get all along the rough paths...

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  2. 3 windows, cpu 100%
    By phil in forum Windows Programming
    Replies: 3
    Last Post: 08-01-2005, 08:45 AM
  3. edit box affecting displaying of text?
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2005, 03:28 PM
  4. Really Need Help With My Opengl Camera!!!!
    By psychopath in forum Game Programming
    Replies: 13
    Last Post: 05-28-2004, 03:05 PM
  5. button 'message'
    By psychopath in forum Windows Programming
    Replies: 12
    Last Post: 04-18-2004, 09:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21