Win 32 help please

Pages: 12
Only problem I'm aware of with anything I just posted is that its use other than in the Code::Blocks IDE could cause problems because of the UNICODE issue. It assumes the ansi character set. To use it in Visual Studio you would need to set the char set to single byte or ansi.
If you're still following this ch1136 or whatever chapter you are, here is a 35 line version which takes 'some liberties' with some of the defines/typedefs that cause Windows Api programs to look 'strange' ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <windows.h>

long __stdcall WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 if(message==WM_DESTROY)
    PostQuitMessage(0);
 else
    return DefWindowProc(hwnd, message, wParam, lParam);

 return 0;
}

int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpszArgument, int nCmdShow)
{
 char szClassName[ ] = "CodeBlocksWindowsApp";
 MSG messages;
 WNDCLASS wc;
 HWND hwnd;

 wc.hInstance     = hInstance,                       wc.lpszClassName = szClassName;
 wc.lpfnWndProc   = WindowProcedure,                 wc.style        = 0;
 wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION), wc.hCursor = LoadCursor(NULL, IDC_ARROW);
 wc.lpszMenuName  = NULL,                            wc.cbClsExtra = 0;
 wc.cbWndExtra    = 0,                               wc.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
 RegisterClass(&wc);
 hwnd=CreateWindow(szClassName,"Template",WS_OVERLAPPEDWINDOW,50,50,544,375,HWND_DESKTOP,NULL,hInstance,NULL);
 ShowWindow (hwnd, nCmdShow);
 while(GetMessage (&messages, NULL, 0, 0))
 {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
 }

 return messages.wParam;
}


Note that doing the above can cause portability problems. Specifically, the above won't compile as 64 bit code. In the 64 bit headers CALLBACK is, I believe, defined away, as that processor doesn't implement all the calling conventions 32 bit X86s have.
Topic archived. No new replies allowed.
Pages: 12