Which module implements CreateWindowW on Windows? - c++

I just came across issue in my application where i need to get static address of CreateWindowW function. Just like this:
&ShowWindow;
However, when doing the same trick with CreateWindowW, i get compiler error Identifier "CreateWindowW" is undefined (it's a macro). I actually cannot find where this function is defined (which DLL) and even pinvoke.net does not mention this.
On some website there is a mention it is user32.dll, but GetProcAddress for my function inside it returns null pointer. I am lost, which module on Windows is linked for this function?
If i try to connect debugger and trace call to this function, Visual Studio makes "Step over" it so i cannot understand where the call goes to..
My build is UNICODE. WinUser.h text i can see:
#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#ifdef UNICODE
#define CreateWindow CreateWindowW
#else
#define CreateWindow CreateWindowA
#endif // !UNICODE

CreateWindowExW is exported by user32.dll. You can just check the documentation. Or you can check the exports via e.g. Microsoft's dumpbin tool.
> dumpbin /exports c:\windows\system32\user32.dll | find /i "CreateWindow"
1618 6D 0000A230 CreateWindowExA
1619 6E 000107B8 CreateWindowExW
1620 6F 00041530 CreateWindowStationA
1621 70 000014D0 CreateWindowStationW
CreateWindowW is a thin wrapper implemented as a macro, according to its documentation:
” CreateWindow is implemented as a call to the CreateWindowEx function, as shown below.
#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#ifdef UNICODE
#define CreateWindow CreateWindowW
#else
#define CreateWindow CreateWindowA
#endif
You can also check that by e.g. “Go to definition” in Visual Studio.

If you open the CreateWindow documentation on MSDN and scroll down, you will see that it is implemented as a wrapper around CreateWindowEx. And if you open the CreateWindowEx doc and scroll down, you'll see this:
So it's implemented in User32.dll.

Related

How to change the window rect without redrawing it

I want to change the height of an edit control window at 1st and then visualize the change through calling AnimateWindow function. But it doesn't seems to work. What should I do for this?
Use MoveWindow with bRepaint=FALSE
BOOL WINAPI MoveWindow(
_In_ HWND hWnd,
_In_ int X,
_In_ int Y,
_In_ int nWidth,
_In_ int nHeight,
_In_ BOOL bRepaint // <-- FALSE
);

C++ GUI Window position

I have a GUi, written in C++/CLI . I want one specific window of it to open on a specific position (right top corner) of my display.
How can I implement this?
BOOL WINAPI SetWindowPos(
__in HWND hWnd,
__in_opt HWND hWndInsertAfter,
__in int X,
__in int Y,
__in int cx,
__in int cy,
__in UINT uFlags
);
More info on msdn.
http://www.winprog.org/tutorial/ -- That will teach you how to make a GUI for Windows only in window's native GUI implement (API).
To implement your code you need to respond to a user's action, i.e clicks a button then
do i = 1+1;

How to set the window's default position?

I'm using Dev C++. After I created a windows application, it generated some code which creates a window. I understand the code broadly. I've found the code to set the size, title, and background color but how do I set up the default position of the new window? I want to start it at the center of the screen.
You should have CreateWindow function, its definition is as follows:
HWND WINAPI CreateWindow(
__in_opt LPCTSTR lpClassName,
__in_opt LPCTSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam
);
The x and y parameters specify the location of the newly-created window. These are the ones you need to set.

C++ don't display in the taskbar a window created with CreateWindow [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Windows Taskbar API
Win32: How to hide 3rd party windows in taskbar by hWnd
How can I prevent window from showing in the taskbar after I created it with CreateWindow? (Is there any parameter that allows me to do this, or something?)
set 'dwStyle' to WS_POPUP, the third argument:
HWND WINAPI CreateWindow(
__in_opt LPCTSTR lpClassName,
__in_opt LPCTSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam);
If you're doing win32, I suggest, for your own sanity, you give Qt a try.
ITaskbarList::DeleteTab will also remove a window from the taskbar.

Set HWND on CreateWindow appears to fail

I'm coming from C# and very new at this so please bear with me.
I have a MainWindow class which has some private HWND variables. One for the window itself, and one for each of the controls. I assume I need to keep track of them, or that it will make things easier later?
Anyway, I've got:
class GUIMain
{
private:
HINSTANCE hInstance;
HWND hWnd; // The windows itself
HWND cmdGenerate, cmdQuit; // 2 buttons
I've got a private method called initialise(HWND hWnd) which is called on WM_CREATE and it adds all the controls to the window:
void MainWindow::initialise(HWND hWnd)
{
this->hWnd = hWnd;
cmdGenerate = CreateWindow(TEXT("BUTTON"), TEXT("&Generate..."),
WS_VISIBLE | WS_CHILD,
6, 6, 150, 25,
hWnd, (HMENU)1, 0, 0);
cmdQuit = CreateWindow(TEXT("BUTTON"), TEXT("&Quit"),
WS_VISIBLE | WS_CHILD,
6, 37, 150, 25,
hWnd, (HMENU)2, 0, 0);
}
however this does not seem to put the buttons on the window. In fact, when I debug I can see that it's not even getting past the first line. What is strange is that when I change it to this:
void MainWindow::initialise(HWND hWnd)
{
//this->hWnd = hWnd;
/*cmdGenerate = */CreateWindow(TEXT("BUTTON"), TEXT("&Generate..."),
WS_VISIBLE | WS_CHILD,
6, 6, 150, 25,
hWnd, (HMENU)1, 0, 0);
/*cmdQuit = */CreateWindow(TEXT("BUTTON"), TEXT("&Quit"),
WS_VISIBLE | WS_CHILD,
6, 37, 150, 25,
hWnd, (HMENU)2, 0, 0);
}
it seems to work fine.
Logic would seem to suggest that assigning the private HWND variables the value of the CreateWindow function return is causing problems, but I have done this before and not had a problem?
The only difference between my previous code and this code is that I am now using classes whereas before (while I was learning) I just had everything in WinMain and WndProc.
WinMain: http://pastebin.com/j54vW9gc
Header File: http://pastebin.com/cUs4vVJ6
CPP File: http://pastebin.com/B5KUXTvx
Welcome to world of win32 that was not designed for C++. That's a good first try. I redid classes trying to make a generic framework hundreds of times before saying it was not worth any more time.
Your WinMain() would also be helpful, but a big issue i see is your call to CreateWindowEx() . The last parameter you send is 0. Than when you retrieve it later SetWindowLong(hWnd, GWL_USERDATA, (long) ((LPCREATESTRUCT)lParam)->lpCreateParams); you are saying it is a pointer to class. Did you mean to have:
hWnd = CreateWindowEx(0, TEXT("AS2MainWindow"),
TEXT("AS2"),
WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT,
824, 350,
0, 0,
hInstance, this);
Looking for other problems. See if that helps. If not maybe your post your main()
Added:
CreateWindowEx
HWND WINAPI CreateWindowEx(
__in DWORD dwExStyle,
__in_opt LPCTSTR lpClassName,
__in_opt LPCTSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam
);
The last parameter lpParam is optional. So when you had it set to 0 it was not hurting anything. But this is how you "send" something to your WM_NCCREATE or WM_CREATE. It can be any LPVOID. In C you may send a pointer to a struct or anything you want. In this case you want to send it a pointer to the object that is about your window.
To get this parameter in WM_NCCREATE or WM_CREATE you use the below code:
(long) ((LPCREATESTRUCT)lParam)->lpCreateParams);
That is saying cast lParam to a pointer to a CREATESTRUCT. Than get lpCreateParams from it. and cast that to a long. This is slightly different than how i have written this hard to understand piece of code. If you break it into several steps it looks easier. Let me know if you need further explanation here.
Just so you get the full picture below is the definition of CreateStruct. It has more than just lpCreateParams in it. (which you chose to be a pointer to your class).
typedef struct tagCREATESTRUCT {
LPVOID lpCreateParams;
HINSTANCE hInstance;
HMENU hMenu;
HWND hwndParent;
int cy;
int cx;
int y;
int x;
LONG style;
LPCTSTR lpszName;
LPCTSTR lpszClass;
DWORD dwExStyle;
} CREATESTRUCT, *LPCREATESTRUCT;
After understanding all this. Check out ATL thunking. Its the way to go if you want all your code inside classes. I find it better to get away from EVERY piece of code being in a class when it doesn't have to be. Depends on the program I am writing.