• Advertisement
Sign in to follow this  

Making a Window ...... HELP

This topic is 4761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I would post the code but its from a book. Does anyone know a simple tutoral on creating a window using CreateWindow and making everything needed to get it to work. Im having alot of issue with this. I can make good program using the books code but i want to write my own for once and i cant even get over this hurdle.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Here, I'll write you up one real quick ...



#include <windows.h>

BOOL CALLBACK wnd_proc(HWND wnd, int msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_CREATE:
SetWindowPos(wnd, 0, 0, 0, 500, 500, SWP_SHOWWINDOW | SWP_NOZORDER);
return FALSE;

case WM_CLOSE: DestroyWindow(wnd); return FALSE;
case WM_DESTROY: PostQuitMessage(0); return FALSE;
}

return DefWindowProc(wnd, msg, wparam, lparam);
}


int WINAPI WinMain(HINSTANCE inst, HINSTANCE previnst, LPSTR cmdline, int show)
{
WNDCLASS wc;
MSG msg;


ZeroMemory(&wc, sizeof(WNDCLASS));
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wc.hCursor = LoadCursor(0, MAKEINTRESOURCE(IDC_ARROW));
wc.hInstance = inst;
wc.lpfnWndProc = (WNDPROC) wnd_proc;
wc.lpszClassName = "class_name";
RegisterClass(&wc);


CreateWindow(wc.lpszClassName, NULL, WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, 0, 0, 0, 0, 0, 0, inst, NULL);

while(GetMessage(&msg,0,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return 0;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by LittleFreak
I would post the code but its from a book. Does anyone know a simple tutoral on creating a window using CreateWindow and making everything needed to get it to work. Im having alot of issue with this. I can make good program using the books code but i want to write my own for once and i cant even get over this hurdle.


Another thing is if you are using Dev-CPP or MSVC, they come with templates for all of this. In Dev-CPP choose a Windows Application. In MSVC choose a Win32 Applicaation and make it a 'hello world' model. Just a heads up for the future.

- Drew

Share this post


Link to post
Share on other sites
I did exactly that code you gave me and this is my debug.

------ Build started: Project: kaigan, Configuration: Debug Win32 ------
Compiling...
winmain.cpp
Linking...
winmain.obj : error LNK2019: unresolved external symbol __imp__DefWindowProcA@16 referenced in function "int __stdcall wnd_proc(struct HWND__ *,int,unsigned int,long)" (?wnd_proc@@YGHPAUHWND__@@HIJ@Z)
winmain.obj : error LNK2019: unresolved external symbol __imp__PostQuitMessage@4 referenced in function "int __stdcall wnd_proc(struct HWND__ *,int,unsigned int,long)" (?wnd_proc@@YGHPAUHWND__@@HIJ@Z)
winmain.obj : error LNK2019: unresolved external symbol __imp__DestroyWindow@4 referenced in function "int __stdcall wnd_proc(struct HWND__ *,int,unsigned int,long)" (?wnd_proc@@YGHPAUHWND__@@HIJ@Z)
winmain.obj : error LNK2019: unresolved external symbol __imp__SetWindowPos@28 referenced in function "int __stdcall wnd_proc(struct HWND__ *,int,unsigned int,long)" (?wnd_proc@@YGHPAUHWND__@@HIJ@Z)
winmain.obj : error LNK2019: unresolved external symbol __imp__DispatchMessageA@4 referenced in function _WinMain@16
winmain.obj : error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function _WinMain@16
winmain.obj : error LNK2019: unresolved external symbol __imp__GetMessageA@16 referenced in function _WinMain@16
winmain.obj : error LNK2019: unresolved external symbol __imp__CreateWindowExA@48 referenced in function _WinMain@16
winmain.obj : error LNK2019: unresolved external symbol __imp__RegisterClassA@4 referenced in function _WinMain@16
winmain.obj : error LNK2019: unresolved external symbol __imp__LoadCursorA@8 referenced in function _WinMain@16
Debug/kaigan.exe : fatal error LNK1120: 10 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Ryan\Desktop\Programing\kaigan\Debug\BuildLog.htm"
kaigan - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
Quote:
Original post by unknownProdigy
How do I make an unresizable window?


Do not use the 'WS_THICKFRAME' in the create window. Here is a snippet:

int flags = ( WS_OVERLAPPED |
WS_CAPTION |
WS_SYSMENU |
WS_MINIMIZEBOX |
WS_MAXIMIZEBOX );

hWnd = CreateWindow(szWindowClass, szTitle, flags,CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);




- Drew

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement