For Programmers: Free Programming Magazines  


Home > Archive > VC Language > June 2005 > Scrollbar controls in Win32 -- Please help









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Scrollbar controls in Win32 -- Please help
Brennan Vincent

2005-06-01, 8:59 pm

Bear with me, I'm a complete newbie to Win32 programming. I want a scrollbar
in the upper corner of my app, but it's not showing up. Here is my code:


#include "stdafx.h"

#include <commctrl.h>

#include "resource.h"

LRESULT __stdcall wcexProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
lParam)

{

switch(msg)

{

case WM_CREATE:

{

HWND hScroll;

if(!(hScroll =
CreateWindowEx(0L,"SCROLLBAR" ,NULL,WS_VISIBLE|WS_CHILD,0,0,200,CW_USE
DEFAULT,hwnd,NULL,GetModuleHandle(NULL),
NULL)))

MessageBox(NULL,"Scrollbar could not be created","error",0);

}

break;

default:

return DefWindowProc(hwnd,msg,wParam,lParam);


}

return 0;

}

int __stdcall _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)

{

InitCommonControls();

HWND hwnd;

WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = 0;

wcex.lpfnWndProc = wcexProc;

wcex.cbClsExtra = 0;

wcex.cbWndExtra = 0;

wcex.hInstance = hInstance;

wcex.hIcon = LoadIcon(NULL,(LPCSTR)IDI_RACER);

wcex.hCursor = LoadCursor(NULL,IDC_ARROW);

wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);

wcex.lpszMenuName = NULL;

wcex.lpszClassName = "wcex";

wcex.hIconSm = LoadIcon(NULL,(LPCSTR)IDI_SMALL);

if(!RegisterClassEx(&wcex))

{

MessageBox(NULL,"Couldn't register wcex","error",0);

}

if(!(hwnd = CreateWindowEx(0,"wcex","Main
Window" ,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_US
EDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NUL
L,NULL,hInstance,NULL)))

{

MessageBox(NULL,"Could not create main window","error",0);

}

ShowWindow(hwnd,nCmdShow);

UpdateWindow(hwnd);

MSG msg;

while(GetMessage(&msg,NULL,0,0) > 0)

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;


}


Jeff Partch [MVP]

2005-06-02, 4:02 am

"Brennan Vincent" <brennan.vincent@gmail.com> wrote in message
news:f%pne.49$4A3.5495@news.uswest.net...
> Bear with me, I'm a complete newbie to Win32 programming. I want a

scrollbar
> in the upper corner of my app, but it's not showing up. Here is my code:
>
>
> #include "stdafx.h"
>
> #include <commctrl.h>
>
> #include "resource.h"
>
> LRESULT __stdcall wcexProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
> lParam)
>
> {
>
> switch(msg)
>
> {
>
> case WM_CREATE:
>
> {
>
> HWND hScroll;
>
> if(!(hScroll =
>

CreateWindowEx(0L,"SCROLLBAR" ,NULL,WS_VISIBLE|WS_CHILD,0,0,200,CW_USE
DEFAULT
,hwnd,NULL,GetModuleHandle(NULL),NULL)))

>
> MessageBox(NULL,"Scrollbar could not be created","error",0);
>
> }


Just a guess, but I'd rethink your use of CW_USEDEFAULT.
--
Jeff Partch [VC++ MVP]


Brennan Vincent

2005-06-02, 4:02 am


"Jeff Partch [MVP]" <jeffp@mvps.org> wrote in message
news:OeiUPLxZFHA.228@TK2MSFTNGP12.phx.gbl...
> "Brennan Vincent" <brennan.vincent@gmail.com> wrote in message
> news:f%pne.49$4A3.5495@news.uswest.net...
> scrollbar
> CreateWindowEx(0L,"SCROLLBAR" ,NULL,WS_VISIBLE|WS_CHILD,0,0,200,CW_USE
DEFAULT
> ,hwnd,NULL,GetModuleHandle(NULL),NULL)))

>
> Just a guess, but I'd rethink your use of CW_USEDEFAULT.
> --
> Jeff Partch [VC++ MVP]
>
>


Your quess proved correct! Thanks a million!


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com