Solved C++ win32 API

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat
Status
Not open for further replies.

guru

Coder
Full Member
Nobleman
Jun 8, 2012
115
673
1
Hi guys,
This is a s**t i tried now. Eventhough i did exactly what was given in the tutorial, it shows error. Even copy and paste didn't work! I can even handle very big process but this fu*king c++ and win32 is fu*king me always. Any tutorial or any book what ever fu*k i use it results in error even i follow all the steps. Moreover, even after copy paste work it shows error. This is pathetic!

#include <Windows.h>
const char sz_WindowName[]="TEST application";
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg, WPARAM wparam,LPARAM lparam){
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
default:
return DefWindowProc(hwnd,msg,wparam,lparam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
wc.cbSize=sizeof(WNDCLASSEX);
wc.style=0;
wc.hInstance=hInstance;
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName=NULL;
wc.lpszClassName=sz_WindowName;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.cbClsExtra=0;
wc.lpfnWndProc=WndProc;
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,"NOte!","class registration failed",MB_OK);
return 0;
}
hwnd=CreateWindowEx(0,(LPCWSTR)sz_WindowName,(LPCWSTR)sz_WindowName,WS_OVERLAPPEDWINDOW,10,10, 640,480,NULL,NULL,hInstance,NULL);
if(hwnd==NULL)
{
MessageBox(NULL,(LPCWSTR)"Sorry",(LPCWSTR)"Window creation failed",MB_OK);
return 0;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

}
 

P4R4D0GS

Newbie
Full Member
Aug 17, 2012
13
262
1
Watch and learn. Iam not good in English so I can not explain what you have wrong. But there u have working code.
Try to compare with your code certainly u find what is wrong. Next time u can tell us compile errors.

C++:
#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
          PSTR szCmdLine, int iCmdShow)
{
  TCHAR szAppName[] = TEXT("WindowName");
  HWND hWnd;
  MSG msg;
  WNDCLASSEX wc;
  
  wc.cbSize = sizeof(wc);
  wc.style = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc = WndProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = hInstance;
  wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  wc.hIconSm = NULL;
  wc.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = szAppName;
  
  RegisterClassEx(&wc);
  
  hWnd = CreateWindowEx(0,szAppName,
            szAppName,
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            NULL,
            NULL,
            hInstance,NULL);
  ShowWindow(hWnd, iCmdShow);
  UpdateWindow(hWnd);
  
  while(GetMessage(&msg, NULL, 0, 0))
  {
     TranslateMessage(&msg);
     DispatchMessage(&msg);
  }
  return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
     case WM_DESTROY:
     PostQuitMessage(0);
     return 0;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}
 

Fleep

Founder
Meme Tier VIP
May 20, 2012
572
11,023
6
First calm down guru your not gonna make much progress this way, its probably just a small mistake.
On a first look that code works fine, tell us as much as you can. Can you compile it?, if not then where and what are your errors?

Fleep
 

guru

Coder
Full Member
Nobleman
Jun 8, 2012
115
673
1
Sorry Fleep! I wrote it when i was very angry that it didn't work. Actually, I can make hacks with c++. I use base code from other creators(It's copy and paste the base code to get win32 to windows and function. I just program the logic of core concept like aimbot, esp code and fix simple errors to make it work).

Regarding this program, I get "cannot convert from 'const char[17]' to 'LPCWSTR' " and the same error occur when it comes to message box. Actually I got this program from this tutorial- www.winprog.org/tutorial/simple_window.html . Some variable names might have changed by me. But followed those steps. Why the hell is it that difficult even to create a simple window in win32 api?

@P4R4DOGS: Thanks for your help! I will check with that code and try to find the error!
 

P4R4D0GS

Newbie
Full Member
Aug 17, 2012
13
262
1
Try to remove (LPCWSTR) from this:

C++:
hwnd=CreateWindowEx(0,(LPCWSTR)sz_WindowName,(LPCWSTR)sz_WindowName,WS_OVERLAPPEDWINDOW,10,10, 640,480,NULL,NULL,hInstance,NULL);
and this:

C++:
  if(hwnd==NULL)
  {
   MessageBox(NULL,(LPCWSTR)"Sorry",(LPCWSTR)"Window creation failed",MB_OK);
   return 0;
  }
and check the part when u registering class.

C++:
  wc.cbSize    = sizeof(WNDCLASSEX);
  wc.style     = 0;
  wc.lpfnWndProc  = WndProc;
  wc.cbClsExtra  = 0;
  wc.cbWndExtra  = 0;
  wc.hInstance   = hInstance;
  wc.hIcon     = LoadIcon(NULL, IDI_APPLICATION);
  wc.hCursor    = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = sz_WindowName;
  wc.hIconSm    = LoadIcon(NULL, IDI_APPLICATION);
 

guru

Coder
Full Member
Nobleman
Jun 8, 2012
115
673
1
P4R4D0GS said:
Try to remove (LPCWSTR) from this:

C++:
hwnd=CreateWindowEx(0,(LPCWSTR)sz_WindowName,(LPCWSTR)sz_WindowName,WS_OVERLAPPEDWINDOW,10,10, 640,480,NULL,NULL,hInstance,NULL);
When i remove that (LPCWSTR) it shows a type cast error! That why i added it to type the char* to LPCWSTR. It removed the error but created a letters which i can't understand! In that tutorial which i have mentioned, the author didn't use LPCWSTR.
 

guru

Coder
Full Member
Nobleman
Jun 8, 2012
115
673
1
Ya! Got that fixed! 1st success! Thanks.

But still i get only the failure message! Not able to create window!!!!!???

RegisterClassEx() not able to register the window! Any fix for it! The debug console didn't say any thing about it.
 

P4R4D0GS

Newbie
Full Member
Aug 17, 2012
13
262
1
Check the part when u registering class

C++:
  wc.cbSize    = sizeof(WNDCLASSEX);
  wc.style     = 0;
  wc.lpfnWndProc  = WndProc;
  wc.cbClsExtra  = 0;
  wc.cbWndExtra  = 0;
  wc.hInstance   = hInstance;
  wc.hIcon     = LoadIcon(NULL, IDI_APPLICATION);
  wc.hCursor    = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = sz_WindowName;
  wc.hIconSm    = LoadIcon(NULL, IDI_APPLICATION);
 

guru

Coder
Full Member
Nobleman
Jun 8, 2012
115
673
1
It works! wc.hIconsm fixed it. A blank window is now open! Thanks for the help man!
Could you list which are the optional and compulsory attribute in the class structure when creating a window?

Is it a myth?
 

P4R4D0GS

Newbie
Full Member
Aug 17, 2012
13
262
1
Sorry my english is weak and i dont know what you mean. But if you mean what you can skip from registration class process from this:

C++:
  wc.cbSize    = sizeof(WNDCLASSEX);
  wc.style     = 0;
  wc.lpfnWndProc  = WndProc;
  wc.cbClsExtra  = 0;
  wc.cbWndExtra  = 0;
  wc.hInstance   = hInstance;
  wc.hIcon     = LoadIcon(NULL, IDI_APPLICATION);
  wc.hCursor    = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = sz_WindowName;
  wc.hIconSm    = LoadIcon(NULL, IDI_APPLICATION);
I guess all must be there, or registration class will fail. I tried to remove one by one and every time creation class failed.
 

guru

Coder
Full Member
Nobleman
Jun 8, 2012
115
673
1
Ok. Thanks! This is what i asked. Even removing one attributes, registration fails.

And I never mind about error in language once you are able to successfully communicate and express your thoughts :).

/solved
 
Status
Not open for further replies.
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods